summaryrefslogtreecommitdiff
path: root/taskapp/forms
diff options
context:
space:
mode:
authornishanth2010-03-02 16:04:41 +0530
committernishanth2010-03-02 16:04:41 +0530
commit84ce5a608dbac2797d86de88c8331b173ade26c0 (patch)
tree04361f17ea4930f1715ad164507744a9a0996729 /taskapp/forms
parent0039fc6e942ed11284c4dee82807955f2f43e75d (diff)
downloadpytask-84ce5a608dbac2797d86de88c8331b173ade26c0.tar.gz
pytask-84ce5a608dbac2797d86de88c8331b173ade26c0.tar.bz2
pytask-84ce5a608dbac2797d86de88c8331b173ade26c0.zip
now validation for task title is done in the forms.
Diffstat (limited to 'taskapp/forms')
-rw-r--r--taskapp/forms/task.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/taskapp/forms/task.py b/taskapp/forms/task.py
index 2aa4169..e0cc050 100644
--- a/taskapp/forms/task.py
+++ b/taskapp/forms/task.py
@@ -7,6 +7,14 @@ class TaskCreateForm(forms.ModelForm):
fields = ['title', 'desc', 'tags_field', 'credits']
#publish = forms.BooleanField(required=False)
+ def clean_title(self):
+ data = self.cleaned_data['title'].strip()
+ try:
+ Task.objects.exclude(status="DL").get(title__iexact=data)
+ raise forms.ValidationError("Another task with same title exists")
+ except Task.DoesNotExist:
+ return data
+
def clean_desc(self):
data = self.cleaned_data['desc'].strip()
if not data:
@@ -27,6 +35,17 @@ def EditTaskForm(task, instance=None):
return data
+ def clean_title(self):
+ data = self.cleaned_data['title'].strip()
+ try:
+ prev_task = Task.objects.exclude(status="DL").get(title__iexact=data)
+ if prev_task != task:
+ raise forms.ValidationError("Another task with same title exists")
+ else:
+ return data
+ except:
+ return data
+
data = {
'title': task.title,
'desc': task.desc,