now validation for task title is done in the forms.
--- a/taskapp/forms/task.py Tue Mar 02 15:34:51 2010 +0530
+++ b/taskapp/forms/task.py Tue Mar 02 16:04:41 2010 +0530
@@ -7,6 +7,14 @@
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 @@
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,
--- a/taskapp/views/task.py Tue Mar 02 15:34:51 2010 +0530
+++ b/taskapp/views/task.py Tue Mar 02 16:04:41 2010 +0530
@@ -139,10 +139,6 @@
#publish = data['publish'] # just in case if we have to show the option
task = createTask(title,desc,user,credits)
- if not task:
- error_msg = "Another task with the same title exists"
- return render_to_response('task/create.html',{'user':user, 'form':form, 'error_msg':error_msg})
-
addMentor(task, user)
updateTask(task,tags_field=data['tags_field'])
# if publish: publishTask(task)
@@ -541,7 +537,7 @@
data = form.cleaned_data
title = data['title']
try:
- prev_task = Task.objects.exclude(status="DL").get(title=title)
+ prev_task = Task.objects.exclude(status="DL").get(title__iexact=title)
if prev_task != task:
error_msg = "Another task exists with the same title"
return render_to_response('task/edittask.html',{'user':user, 'form':form, 'error_msg':error_msg})