diff options
author | nishanth | 2010-03-02 16:04:41 +0530 |
---|---|---|
committer | nishanth | 2010-03-02 16:04:41 +0530 |
commit | 84ce5a608dbac2797d86de88c8331b173ade26c0 (patch) | |
tree | 04361f17ea4930f1715ad164507744a9a0996729 | |
parent | 0039fc6e942ed11284c4dee82807955f2f43e75d (diff) | |
download | pytask-84ce5a608dbac2797d86de88c8331b173ade26c0.tar.gz pytask-84ce5a608dbac2797d86de88c8331b173ade26c0.tar.bz2 pytask-84ce5a608dbac2797d86de88c8331b173ade26c0.zip |
now validation for task title is done in the forms.
-rw-r--r-- | taskapp/forms/task.py | 19 | ||||
-rw-r--r-- | taskapp/views/task.py | 6 |
2 files changed, 20 insertions, 5 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, diff --git a/taskapp/views/task.py b/taskapp/views/task.py index 637fc62..0b0984b 100644 --- a/taskapp/views/task.py +++ b/taskapp/views/task.py @@ -139,10 +139,6 @@ def create_task(request): #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 @@ def edit_task(request, tid): 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}) |