2010-09-27 08:48:00 +00:00
|
|
|
from django import forms
|
|
|
|
from django.forms import ModelForm
|
2014-05-31 16:09:27 +00:00
|
|
|
from django.contrib.auth.models import User, Group
|
2010-09-27 08:48:00 +00:00
|
|
|
from todo.models import Item, List
|
|
|
|
|
2014-05-31 16:09:27 +00:00
|
|
|
|
|
|
|
class AddListForm(ModelForm):
|
2010-09-27 08:48: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.
|
|
|
|
def __init__(self, user, *args, **kwargs):
|
|
|
|
super(AddListForm, self).__init__(*args, **kwargs)
|
|
|
|
self.fields['group'].queryset = Group.objects.filter(user=user)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = List
|
2014-11-08 07:43:27 +00:00
|
|
|
exclude = []
|
2014-05-31 16:09:27 +00:00
|
|
|
|
|
|
|
|
2010-09-27 08:48:00 +00:00
|
|
|
class AddItemForm(ModelForm):
|
|
|
|
# The picklist showing the users to which a new task can be assigned
|
|
|
|
# must find other members of the groups the current list belongs to.
|
|
|
|
def __init__(self, task_list, *args, **kwargs):
|
|
|
|
super(AddItemForm, self).__init__(*args, **kwargs)
|
|
|
|
# print dir(self.fields['list'])
|
|
|
|
# print self.fields['list'].initial
|
|
|
|
self.fields['assigned_to'].queryset = User.objects.filter(groups__in=[task_list.group])
|
2015-09-02 21:30:04 +00:00
|
|
|
self.fields['assigned_to'].label_from_instance = \
|
|
|
|
lambda obj: "%s (%s)" % (obj.get_full_name(), obj.username)
|
2014-05-31 16:09:27 +00:00
|
|
|
|
2010-09-27 08:48:00 +00:00
|
|
|
due_date = forms.DateField(
|
2014-05-31 16:09:27 +00:00
|
|
|
required=False,
|
|
|
|
widget=forms.DateTimeInput(attrs={'class': 'due_date_picker'})
|
|
|
|
)
|
|
|
|
|
2010-09-27 08:48:00 +00:00
|
|
|
title = forms.CharField(
|
2014-05-31 16:09:27 +00:00
|
|
|
widget=forms.widgets.TextInput(attrs={'size': 35})
|
|
|
|
)
|
2010-09-27 08:48:00 +00:00
|
|
|
|
2014-11-07 18:42:53 +00:00
|
|
|
# note = forms.CharField(
|
|
|
|
# widget=forms.TextArea(attrs={'size': 35})
|
|
|
|
# )
|
|
|
|
note = forms.CharField(widget=forms.Textarea())
|
|
|
|
|
2010-09-27 08:48:00 +00:00
|
|
|
class Meta:
|
|
|
|
model = Item
|
2014-11-08 07:43:27 +00:00
|
|
|
exclude = []
|
2010-09-27 08:48:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EditItemForm(ModelForm):
|
|
|
|
# The picklist showing the users to which a new task can be assigned
|
|
|
|
# must find other members of the groups the current list belongs to.
|
2014-05-31 16:09:27 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2010-09-27 08:48:00 +00:00
|
|
|
super(EditItemForm, self).__init__(*args, **kwargs)
|
|
|
|
self.fields['assigned_to'].queryset = User.objects.filter(groups__in=[self.instance.list.group])
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Item
|
2014-05-31 16:09:27 +00:00
|
|
|
exclude = ('created_date', 'created_by',)
|
|
|
|
|
2010-09-27 08:48:00 +00:00
|
|
|
|
|
|
|
class AddExternalItemForm(ModelForm):
|
|
|
|
"""Form to allow users who are not part of the GTD system to file a ticket."""
|
|
|
|
|
|
|
|
title = forms.CharField(
|
2014-05-31 16:09:27 +00:00
|
|
|
widget=forms.widgets.TextInput(attrs={'size': 35})
|
|
|
|
)
|
|
|
|
note = forms.CharField(
|
2010-09-27 08:48:00 +00:00
|
|
|
widget=forms.widgets.Textarea(),
|
|
|
|
help_text='Foo',
|
2014-05-31 16:09:27 +00:00
|
|
|
)
|
|
|
|
|
2010-09-27 08:48:00 +00:00
|
|
|
class Meta:
|
|
|
|
model = Item
|
2014-05-31 16:09:27 +00:00
|
|
|
exclude = ('list', 'created_date', 'due_date', 'created_by', 'assigned_to',)
|
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."""
|
|
|
|
|
|
|
|
q = forms.CharField(
|
2014-05-31 16:09:27 +00:00
|
|
|
widget=forms.widgets.TextInput(attrs={'size': 35})
|
|
|
|
)
|