2010-09-27 08:48:00 +00:00
|
|
|
from django import forms
|
2016-11-28 21:15:46 +00:00
|
|
|
from django.contrib.auth.models import Group
|
2018-04-05 07:27:53 +00:00
|
|
|
from django.forms import ModelForm
|
2018-03-29 05:51:10 +00:00
|
|
|
from todo.models import Task, TaskList
|
2016-11-30 21:32:22 +00:00
|
|
|
|
2010-09-27 08:48:00 +00:00
|
|
|
|
2018-02-10 08:25:28 +00:00
|
|
|
class AddTaskListForm(ModelForm):
|
2018-03-13 07:34:00 +00:00
|
|
|
"""The picklist showing allowable groups to which a new list can be added
|
|
|
|
determines which groups the user belongs to. This queries the form object
|
|
|
|
to derive that list."""
|
|
|
|
|
2010-09-27 08:48:00 +00:00
|
|
|
def __init__(self, user, *args, **kwargs):
|
2018-02-10 08:25:28 +00:00
|
|
|
super(AddTaskListForm, self).__init__(*args, **kwargs)
|
2018-12-21 08:38:44 +00:00
|
|
|
self.fields["group"].queryset = Group.objects.filter(user=user)
|
|
|
|
self.fields["group"].widget.attrs = {
|
|
|
|
"id": "id_group",
|
|
|
|
"class": "custom-select mb-3",
|
|
|
|
"name": "group",
|
|
|
|
}
|
2010-09-27 08:48:00 +00:00
|
|
|
|
|
|
|
class Meta:
|
2018-02-10 08:25:28 +00:00
|
|
|
model = TaskList
|
2018-12-21 08:38:44 +00:00
|
|
|
exclude = ["created_date", "slug"]
|
2014-05-31 16:09:27 +00:00
|
|
|
|
|
|
|
|
2018-03-29 05:51:10 +00:00
|
|
|
class AddEditTaskForm(ModelForm):
|
2018-03-13 07:34:00 +00:00
|
|
|
"""The picklist showing the users to which a new task can be assigned
|
2018-04-05 07:27:53 +00:00
|
|
|
must find other members of the group this TaskList is attached to."""
|
2018-03-13 07:34:00 +00:00
|
|
|
|
2018-03-24 19:24:49 +00:00
|
|
|
def __init__(self, user, *args, **kwargs):
|
2018-03-19 07:41:52 +00:00
|
|
|
super().__init__(*args, **kwargs)
|
2018-12-21 08:38:44 +00:00
|
|
|
task_list = kwargs.get("initial").get("task_list")
|
2018-04-05 07:27:53 +00:00
|
|
|
members = task_list.group.user_set.all()
|
2018-12-21 08:38:44 +00:00
|
|
|
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 = {
|
|
|
|
"id": "id_assigned_to",
|
|
|
|
"class": "custom-select mb-3",
|
|
|
|
"name": "assigned_to",
|
|
|
|
}
|
|
|
|
self.fields["task_list"].value = kwargs["initial"]["task_list"].id
|
2014-05-31 16:09:27 +00:00
|
|
|
|
2018-12-21 08:38:44 +00:00
|
|
|
due_date = forms.DateField(widget=forms.DateInput(attrs={"type": "date"}), required=False)
|
2014-05-31 16:09:27 +00:00
|
|
|
|
2018-12-21 08:38:44 +00:00
|
|
|
title = forms.CharField(widget=forms.widgets.TextInput())
|
2010-09-27 08:48:00 +00:00
|
|
|
|
2018-12-21 08:38:44 +00:00
|
|
|
note = forms.CharField(widget=forms.Textarea(), required=False)
|
2014-11-07 18:42:53 +00:00
|
|
|
|
2019-07-30 05:53:33 +00:00
|
|
|
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
|
|
|
|
|
2010-09-27 08:48:00 +00:00
|
|
|
class Meta:
|
2018-03-29 05:51:10 +00:00
|
|
|
model = Task
|
2014-11-08 07:43:27 +00:00
|
|
|
exclude = []
|
2010-09-27 08:48:00 +00:00
|
|
|
|
|
|
|
|
2018-03-29 05:51:10 +00:00
|
|
|
class AddExternalTaskForm(ModelForm):
|
2010-09-27 08:48:00 +00:00
|
|
|
"""Form to allow users who are not part of the GTD system to file a ticket."""
|
|
|
|
|
2018-12-21 08:38:44 +00:00
|
|
|
title = forms.CharField(widget=forms.widgets.TextInput(attrs={"size": 35}), label="Summary")
|
|
|
|
note = forms.CharField(widget=forms.widgets.Textarea(), label="Problem Description")
|
|
|
|
priority = forms.IntegerField(widget=forms.HiddenInput())
|
2014-05-31 16:09:27 +00:00
|
|
|
|
2010-09-27 08:48:00 +00:00
|
|
|
class Meta:
|
2018-03-29 05:51:10 +00:00
|
|
|
model = Task
|
2018-02-13 07:38:48 +00:00
|
|
|
exclude = (
|
2018-12-21 08:38:44 +00:00
|
|
|
"task_list",
|
|
|
|
"created_date",
|
|
|
|
"due_date",
|
|
|
|
"created_by",
|
|
|
|
"assigned_to",
|
|
|
|
"completed",
|
|
|
|
"completed_date",
|
|
|
|
)
|
2010-09-27 08:48:00 +00:00
|
|
|
|
|
|
|
|
2014-11-17 22:42:17 +00:00
|
|
|
class SearchForm(forms.Form):
|
2010-09-27 08:48:00 +00:00
|
|
|
"""Search."""
|
|
|
|
|
2018-12-21 08:38:44 +00:00
|
|
|
q = forms.CharField(widget=forms.widgets.TextInput(attrs={"size": 35}))
|