--- a/taskapp/forms/task.py Tue Mar 02 16:20:28 2010 +0530
+++ b/taskapp/forms/task.py Tue Mar 02 16:55:33 2010 +0530
@@ -22,37 +22,28 @@
return data
-def EditTaskForm(task, instance=None):
- class myForm(forms.ModelForm):
- class Meta:
- model = Task
- fields = ['title', 'desc', 'tags_field', 'credits']
+class EditTaskForm(forms.ModelForm):
+ class Meta:
+ model = Task
+ fields = ['title', 'desc', 'tags_field', 'credits']
- def clean_desc(self):
- data = self.cleaned_data['desc'].strip()
- if not data:
- raise forms.ValidationError("Enter some description for the task")
-
- return data
+ def clean_desc(self):
+ data = self.cleaned_data['desc'].strip()
+ if not data:
+ raise forms.ValidationError("Enter some description for the task")
- 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
+
+ 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.id != self.instance.id:
+ raise forms.ValidationError("Another task with same title exists")
+ else:
return data
-
- data = {
- 'title': task.title,
- 'desc': task.desc,
- 'tags_field': task.tags_field,
- 'credits': task.credits,
- }
- return myForm(instance) if instance else myForm(data)
+ except Task.DoesNotExist:
+ return data
def AddMentorForm(choices,instance=None):
""" return a form object with appropriate choices """