Select user works completely fine
authorNishanth Amuluru <nishanth@fossee.in>
Sun, 09 Jan 2011 12:01:57 +0530
changeset 124 070f01dd7d8e
parent 123 41a7d8d49e35
child 125 9b0812962133
Select user works completely fine
pytask/taskapp/urls.py
pytask/taskapp/views.py
pytask/templates/task/claim.html
pytask/templates/task/select_user.html
--- a/pytask/taskapp/urls.py	Sun Jan 09 11:52:30 2011 +0530
+++ b/pytask/taskapp/urls.py	Sun Jan 09 12:01:57 2011 +0530
@@ -1,6 +1,6 @@
 from django.conf.urls.defaults import *
 
-from pytask.taskapp.views import create_task, view_task, claim_task \
+from pytask.taskapp.views import create_task, view_task, claim_task, \
         select_user
 
 urlpatterns = patterns('',
@@ -8,5 +8,6 @@
             (r'^create/$', create_task),
             (r'^view/tid=(\w+)', view_task),
             (r'^claim/tid=(\w+)', claim_task),
+            (r'^select/tid=(\w+)', select_user),
 )
 
--- a/pytask/taskapp/views.py	Sun Jan 09 11:52:30 2011 +0530
+++ b/pytask/taskapp/views.py	Sun Jan 09 12:01:57 2011 +0530
@@ -1,5 +1,7 @@
 from datetime import datetime
 
+from django.contrib.auth.models import User
+
 from django.shortcuts import render_to_response, redirect
 from django.http import Http404
 
@@ -11,7 +13,9 @@
 from pytask.views import show_msg
 
 from pytask.taskapp.models import Task, TaskComment, TaskClaim
-from pytask.taskapp.forms import CreateTaskForm, EditTaskForm, TaskCommentForm, ClaimTaskForm
+from pytask.taskapp.forms import CreateTaskForm, EditTaskForm, \
+                                 TaskCommentForm, ClaimTaskForm, \
+                                 ChoiceForm
 from pytask.taskapp.utils import getTask
 from pytask.profile.utils import get_notification
 
@@ -220,16 +224,16 @@
 
     context.update(csrf(request))
 
-    task_claimed = True if claimed_users else False
     claimed_users = task.claimed_users.all()
     selected_users = task.selected_users.all()
+    task_claimed = True if claimed_users else False
     
     is_creator = True if user == task.created_by else False
 
     if ( is_creator or profile.rights in ["CR", "DC"] ) and \
-       task.status in ["OP", "WR"] and task_claimed:
+       task.status in ["OP", "WR"]:
 
-       if claimed_users:
+        if task_claimed:
 
             user_list = ((user.id,user.username) for user in claimed_users)
 
@@ -239,8 +243,8 @@
                     uid = form.cleaned_data['choice']
                     selected_user = User.objects.get(id=uid)
 
-                    task.selected_users.add(user)
-                    task.claimed_users.remove(user)
+                    task.selected_users.add(selected_user)
+                    task.claimed_users.remove(selected_user)
                     task.save()
 
                     return redirect(task_url)
--- a/pytask/templates/task/claim.html	Sun Jan 09 11:52:30 2011 +0530
+++ b/pytask/templates/task/claim.html	Sun Jan 09 12:01:57 2011 +0530
@@ -23,7 +23,7 @@
     {% endif %}
     {% if old_claims and is_creator %}
     <hr />
-        <a href="/task/select/tid={{task.id}}">Select a user to assign the work</a>
+        <a href="/task/select/tid={{task.uniq_key}}">Select a user to assign the work</a>
     {% endif %}
 
     {% if can_claim %}
--- a/pytask/templates/task/select_user.html	Sun Jan 09 11:52:30 2011 +0530
+++ b/pytask/templates/task/select_user.html	Sun Jan 09 12:01:57 2011 +0530
@@ -3,6 +3,7 @@
     <a href="/task/claim/tid={{task.id}}">click here</a> to return to the claims page.<br /><br />
     Select a user to assign this task.<br />
     <form action="" method="POST">
+	    {% csrf_token %}
     {{form.as_table}}
     <input type="submit" value="Assign Task">
     </form>