12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- from django import forms
- from django.contrib.auth.models import Group
- from django.forms import ModelForm
- from tickets.models import Task, TaskList, TicketType
- from django.conf import settings
- from SharixAdmin.models import SharixUser
- class ListCreateForm(ModelForm):
- def __init__(self, user, *args, **kwargs):
- super(ListCreateForm, self).__init__(*args, **kwargs)
- self.fields["group"].queryset = Group.objects.filter(user=user)
- self.fields["group"].widget.attrs = {
- "id": "id_group",
- "class": "custom-select mb-3",
- "name": "group",
- }
- self.fields["name"].widget.attrs = {
- "id": "id_name",
- "class": "form-control",
- "name": "group",
- }
- class Meta:
- model = TaskList
- exclude = ["slug"]
- class TicketForm(ModelForm):
- def __init__(self, user, *args, **kwargs):
- super().__init__(*args, **kwargs)
- task_list = kwargs.get("initial").get("task_list")
- members = task_list.group.user_set.all()
- #print(user)
- #print(task_list.group)
- #members = SharixUser.objects.filter(groups__name=task_list.group)
- #print(members)
- self.fields["assigned_to"].queryset = members
- self.fields["assigned_to"].label_from_instance = lambda obj: "%s (%s)" % (
- obj.get_full_name(),
- obj.username,
- )
- self.fields["assigned_to"].widget.attrs = {"class": "custom-select"}
- self.fields["type"].widget.attrs = {"class": "custom-select"}
- self.fields["title"].widget.attrs = {"class": "form-control"}
- self.fields["note"].widget.attrs = {"class": "form-control"}
-
- if kwargs.get("initial").get("type_disabled") == True:
- self.fields["type"].disabled = True
- due_date = forms.DateField(widget=forms.DateInput(attrs={"type": "date", "class": "form-control"}))
- def clean_created_by(self):
- """Keep the existing created_by regardless of anything coming from the submitted form.
- If creating a new task, then created_by will be None, but we set it before saving."""
- return self.instance.created_by
- class Meta:
- model = Task
- fields = ["type", "title", "note", "due_date", "assigned_to", "created_by"]
- class SearchForm(forms.Form):
- q = forms.CharField(widget=forms.widgets.TextInput(attrs={"size": 35}))
|