author | Nishanth Amuluru <nishanth@fossee.in> |
Thu, 06 Jan 2011 12:08:36 +0530 | |
changeset 226 | b4a3ec34c061 |
parent 224 | c41e38f36299 |
permissions | -rw-r--r-- |
18
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
12
diff
changeset
|
1 |
from django import forms |
220
807e4b701a20
added a submit_report link for each task
Nishanth Amuluru <nishanth@fossee.in>
parents:
219
diff
changeset
|
2 |
from pytask.taskapp.models import Task, WorkReport |
18
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
12
diff
changeset
|
3 |
|
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
12
diff
changeset
|
4 |
class TaskCreateForm(forms.ModelForm): |
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
12
diff
changeset
|
5 |
class Meta: |
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
12
diff
changeset
|
6 |
model = Task |
219
f04a1ec7a07f
Replaced the word credit with pynt
Nishanth Amuluru <nishanth@fossee.in>
parents:
218
diff
changeset
|
7 |
fields = ['title', 'desc', 'tags_field', 'pynts'] |
165 | 8 |
#publish = forms.BooleanField(required=False) |
9 |
||
179
8d1fdb148c27
now validation for task title is done in the forms.
nishanth
parents:
178
diff
changeset
|
10 |
def clean_title(self): |
8d1fdb148c27
now validation for task title is done in the forms.
nishanth
parents:
178
diff
changeset
|
11 |
data = self.cleaned_data['title'].strip() |
8d1fdb148c27
now validation for task title is done in the forms.
nishanth
parents:
178
diff
changeset
|
12 |
try: |
8d1fdb148c27
now validation for task title is done in the forms.
nishanth
parents:
178
diff
changeset
|
13 |
Task.objects.exclude(status="DL").get(title__iexact=data) |
8d1fdb148c27
now validation for task title is done in the forms.
nishanth
parents:
178
diff
changeset
|
14 |
raise forms.ValidationError("Another task with same title exists") |
8d1fdb148c27
now validation for task title is done in the forms.
nishanth
parents:
178
diff
changeset
|
15 |
except Task.DoesNotExist: |
8d1fdb148c27
now validation for task title is done in the forms.
nishanth
parents:
178
diff
changeset
|
16 |
return data |
8d1fdb148c27
now validation for task title is done in the forms.
nishanth
parents:
178
diff
changeset
|
17 |
|
178
106909df0c17
empty description for a task not allowed. white space around description trimmed.
nishanth
parents:
165
diff
changeset
|
18 |
def clean_desc(self): |
106909df0c17
empty description for a task not allowed. white space around description trimmed.
nishanth
parents:
165
diff
changeset
|
19 |
data = self.cleaned_data['desc'].strip() |
106909df0c17
empty description for a task not allowed. white space around description trimmed.
nishanth
parents:
165
diff
changeset
|
20 |
if not data: |
106909df0c17
empty description for a task not allowed. white space around description trimmed.
nishanth
parents:
165
diff
changeset
|
21 |
raise forms.ValidationError("Enter some description for the task") |
106909df0c17
empty description for a task not allowed. white space around description trimmed.
nishanth
parents:
165
diff
changeset
|
22 |
|
106909df0c17
empty description for a task not allowed. white space around description trimmed.
nishanth
parents:
165
diff
changeset
|
23 |
return data |
106909df0c17
empty description for a task not allowed. white space around description trimmed.
nishanth
parents:
165
diff
changeset
|
24 |
|
181 | 25 |
class EditTaskForm(forms.ModelForm): |
26 |
class Meta: |
|
27 |
model = Task |
|
219
f04a1ec7a07f
Replaced the word credit with pynt
Nishanth Amuluru <nishanth@fossee.in>
parents:
218
diff
changeset
|
28 |
fields = ['title', 'desc', 'tags_field', 'pynts'] |
178
106909df0c17
empty description for a task not allowed. white space around description trimmed.
nishanth
parents:
165
diff
changeset
|
29 |
|
181 | 30 |
def clean_desc(self): |
31 |
data = self.cleaned_data['desc'].strip() |
|
32 |
if not data: |
|
33 |
raise forms.ValidationError("Enter some description for the task") |
|
178
106909df0c17
empty description for a task not allowed. white space around description trimmed.
nishanth
parents:
165
diff
changeset
|
34 |
|
181 | 35 |
return data |
36 |
||
37 |
def clean_title(self): |
|
38 |
data = self.cleaned_data['title'].strip() |
|
39 |
try: |
|
40 |
prev_task = Task.objects.exclude(status="DL").get(title__iexact=data) |
|
41 |
if prev_task.id != self.instance.id: |
|
42 |
raise forms.ValidationError("Another task with same title exists") |
|
43 |
else: |
|
179
8d1fdb148c27
now validation for task title is done in the forms.
nishanth
parents:
178
diff
changeset
|
44 |
return data |
181 | 45 |
except Task.DoesNotExist: |
46 |
return data |
|
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
47 |
|
218
59107ce0a618
Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents:
205
diff
changeset
|
48 |
def AddReviewerForm(choices,instance=None): |
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
49 |
""" return a form object with appropriate choices """ |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
50 |
|
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
51 |
class myform(forms.Form): |
218
59107ce0a618
Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents:
205
diff
changeset
|
52 |
reviewer = forms.ChoiceField(choices=choices, required=True) |
151
d0cb85ba462a
no bogus post request can be made now in addmentor page.
nishanth
parents:
136
diff
changeset
|
53 |
form = myform(instance) if instance else myform() |
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
54 |
return form |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
55 |
|
205 | 56 |
class ClaimTaskForm(forms.Form): |
57 |
message = forms.CharField(label="Proposal") |
|
58 |
||
59 |
def clean_message(self): |
|
60 |
data = self.cleaned_data['message'].strip() |
|
61 |
if not data: |
|
62 |
raise forms.ValidationError('Enter something as a proposal') |
|
63 |
return data |
|
64 |
||
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
65 |
|
151
d0cb85ba462a
no bogus post request can be made now in addmentor page.
nishanth
parents:
136
diff
changeset
|
66 |
def ChoiceForm(choices, instance=None): |
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
67 |
""" return a form object with appropriate choices """ |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
68 |
|
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
69 |
class myform(forms.Form): |
92
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
70 |
choice = forms.ChoiceField(choices=choices, required=True) |
151
d0cb85ba462a
no bogus post request can be made now in addmentor page.
nishanth
parents:
136
diff
changeset
|
71 |
form = myform(instance) if instance else myform() |
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
72 |
return form |
89
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
50
diff
changeset
|
73 |
|
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
50
diff
changeset
|
74 |
def AddTaskForm(task_choices, is_plain=False): |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
50
diff
changeset
|
75 |
""" if is_plain is true, it means the task has no subs/deps. |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
50
diff
changeset
|
76 |
so we also give a radio button to choose between subs and dependencies. |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
50
diff
changeset
|
77 |
else we only give choices. |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
50
diff
changeset
|
78 |
""" |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
50
diff
changeset
|
79 |
|
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
50
diff
changeset
|
80 |
class myForm(forms.Form): |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
50
diff
changeset
|
81 |
if is_plain: |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
50
diff
changeset
|
82 |
type_choices = [('S','Subtasks'),('D','Dependencies')] |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
50
diff
changeset
|
83 |
type = forms.ChoiceField(type_choices, widget=forms.RadioSelect) |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
50
diff
changeset
|
84 |
|
90
b2426897ff18
our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents:
89
diff
changeset
|
85 |
task = forms.ChoiceField(choices=task_choices) |
89
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
50
diff
changeset
|
86 |
return myForm() |
93
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
87 |
|
219
f04a1ec7a07f
Replaced the word credit with pynt
Nishanth Amuluru <nishanth@fossee.in>
parents:
218
diff
changeset
|
88 |
def AssignPyntForm(choices, instance=None): |
93
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
89 |
|
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
90 |
class myForm(forms.Form): |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
91 |
user = forms.ChoiceField(choices=choices, required=True) |
136
8632a44b743d
deducing previous credits for a task using the request model. with a few changes, we can ditchax the credits model.
nishanth
parents:
94
diff
changeset
|
92 |
pynts = forms.IntegerField(min_value=0, required=True, help_text="Choose wisely since it cannot be undone.") |
93
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
93 |
return myForm(instance) if instance else myForm() |
94 | 94 |
|
95 |
def RemoveUserForm(choices, instance=None): |
|
96 |
||
97 |
class myForm(forms.Form): |
|
98 |
user = forms.ChoiceField(choices=choices, required=True) |
|
99 |
reason = forms.CharField(min_length=1, required=True) |
|
100 |
return myForm(instance) if instance else myForm() |
|
101 |
||
220
807e4b701a20
added a submit_report link for each task
Nishanth Amuluru <nishanth@fossee.in>
parents:
219
diff
changeset
|
102 |
class WorkReportForm(forms.ModelForm): |
807e4b701a20
added a submit_report link for each task
Nishanth Amuluru <nishanth@fossee.in>
parents:
219
diff
changeset
|
103 |
|
807e4b701a20
added a submit_report link for each task
Nishanth Amuluru <nishanth@fossee.in>
parents:
219
diff
changeset
|
104 |
class Meta: |
807e4b701a20
added a submit_report link for each task
Nishanth Amuluru <nishanth@fossee.in>
parents:
219
diff
changeset
|
105 |
model = WorkReport |
807e4b701a20
added a submit_report link for each task
Nishanth Amuluru <nishanth@fossee.in>
parents:
219
diff
changeset
|
106 |
fields = ['remarks', 'attachment'] |
224
c41e38f36299
added saving of attachments
Nishanth Amuluru <nishanth@fossee.in>
parents:
220
diff
changeset
|
107 |