merged.
authoranoop
Wed, 24 Feb 2010 16:52:03 +0530
changeset 79 fd6b28204fb1
parent 78 c5bcafccc135 (current diff)
parent 77 8f2906d1200a (diff)
child 80 8917b190c4c4
merged.
--- a/taskapp/events/task.py	Wed Feb 24 16:49:30 2010 +0530
+++ b/taskapp/events/task.py	Wed Feb 24 16:52:03 2010 +0530
@@ -120,7 +120,7 @@
         try:
             task.title = title
             task.save()
-        except IntegrityError:
+        except Task.IntegrityError:
             return None
     if desc:task.desc = desc
     if credits:task.credits = credits
--- a/taskapp/views/task.py	Wed Feb 24 16:49:30 2010 +0530
+++ b/taskapp/views/task.py	Wed Feb 24 16:52:03 2010 +0530
@@ -128,12 +128,15 @@
     if (not is_guest) and user in task.mentors.all():
         
         ## now iam going for a brute force method
-        user_list = list(User.objects.all())
+        user_list = list(User.objects.filter(is_active=True))
         for mentor in task.mentors.all():
             user_list.remove(mentor)
             
         for a_user in task.claimed_users.all():
             user_list.remove(a_user)
+
+        for a_user in task.assigned_users.all():
+            user_list.remove(a_user)
             
         non_mentors = ((_.id,_.username) for _ in user_list)
         ## code till must be made elegant and not brute force like above
@@ -193,18 +196,20 @@
     user = request.user
     task = getTask(tid)
     claims = Claim.objects.filter(task=task)
+
+    mentors = task.mentors.all()
+    claimed_users = task.claimed_users.all()
+    assigned_users = task.assigned_users.all()
     
     is_guest = True if not user.is_authenticated() else False
-    if user in task.mentors.all():
-        is_mentor = True 
-    else:
-         is_mentor = False
+    is_mentor = True if user in mentors else False
 
-    task_claimable = True if task.status in ["OP", "RE", "CL"] else False
-    user_can_claim = True if  task_claimable and not ( is_guest or is_mentor ) and ( user not in task.claimed_users.all() )  else False
-    task_claimed = True if task.status == "CL" else False
+    task_claimable = True if task.status in ["OP", "WR"] else False
+    user_can_claim = True if  task_claimable and not ( is_guest or is_mentor ) and ( user not in claimed_users ) and ( user not in assigned_users )  else False
+    task_claimed = True if claimed_users else False
     
-    context = {'is_mentor':is_mentor,
+    context = {'user':user,
+               'is_mentor':is_mentor,
                'task':task,
                'claims':claims,
                'user_can_claim':user_can_claim,
@@ -240,11 +245,14 @@
     is_guest = True if not user.is_authenticated() else False
     is_mentor = True if user in task.mentors.all() else False
 
-    task_claimed = True if task.status == "CL" else False
+    claimed_users = task.claimed_users.all()
+    assigned_users = task.assigned_users.all()
+
+    task_claimed = True if claimed_users else False
     
     if (not is_guest) and is_mentor:
         if task_claimed:
-            user_list = ((user.id,user.username) for user in task.claimed_users.all())
+            user_list = ((user.id,user.username) for user in claimed_users)
             form = AssignTaskForm(user_list)
     
             if request.method == "POST":
@@ -254,12 +262,10 @@
                 return redirect(task_url)
             else:
                 return render_to_response('task/assign.html',{'form':form})
-        elif task.status == "AS":
-            return show_msg('The task is already assigned', task_url, 'view the task')
-        elif task.status == "OP":
-            return show_msg('No one has still claimed the task', task_url, 'view the task')
+        elif assigned_users:
+            return show_msg('When the no of users you need for the task is more than the no of users willing to do the task, I\'d say please re consider the task :P',task_url, 'view the task')
         else:
-            return show_msg('The task status is %s. how can you assign it now'%task.status, task_url, 'view the task')
+            return show_msg('Wait for ppl to claim dude... slow and steady wins the race :)', task_url, 'view the task')
     else:
         return show_msg('You are not authorised to perform this action', task_url, 'view the task')
         
@@ -268,4 +274,4 @@
     and then give the user fields accordingly.
     """
     
-    return None
+    task = Task.objects.get(id=tid) 
--- a/templates/task/claim.html	Wed Feb 24 16:49:30 2010 +0530
+++ b/templates/task/claim.html	Wed Feb 24 16:52:03 2010 +0530
@@ -8,11 +8,15 @@
             {{claim.message}}<br />
         {% endfor %}
     {% else %}
-        There are no claims for this task yet.<br />
+        {% if task_claimable%}
+            There are no claims for this task yet.<br />
+        {% else %}
+            This task cannot be claimed right now.
+        {% endif %}
         <a href="/task/view/tid={{task.id}}">Click here</a> to return to the task.
     {% endif %}
     {% if task_claimed and is_mentor %}
-        <a href="/task/assign/tid={{task.id}}">Assign task</a>
+        <a href="/task/assign/tid={{task.id}}">Select a user to assign the work.</a>
     {% endif %}
     {% if user_can_claim %}
     <hr />
--- a/templates/task/view.html	Wed Feb 24 16:49:30 2010 +0530
+++ b/templates/task/view.html	Wed Feb 24 16:52:03 2010 +0530
@@ -13,11 +13,12 @@
             <a href="/user/view/uid={{mentor.id}}">{{mentor.username}}|</a>
         {% endfor %}
         {% if can_mod_mentors %}
-            <a href="/task/addmentor/tid={{task.id}}">Add another Mentor to this task</a><br />
+            <a href="/task/addmentor/tid={{task.id}}">Add another Mentor to this task</a>
+            <br />
             edit task goes here and it should contain all those add subs and add deps depending on availability<br />
         {% endif %}
 
-        {%  if deps %}
+        {% if deps %}
             <br />The task has following dependencies
             {% for dep in deps %}
                 <a href="/task/view/tid={{dep.id}}">{{dep.title}}</a><br />
@@ -27,9 +28,9 @@
                 <a href="/task/remtask/tid={{task.id}}">remove an existing dependency</a>
             {% endif %}
         {% else %}
-            {%if can_mod_tasks %}
+            {% if can_mod_tasks %}
                 <a href="/task/addtask/tid={{task.id}}">add a subtask/dependency </a>
-            {%endif%}
+            {% endif %}
         {% endif %}
         
         <hr>
@@ -43,12 +44,15 @@
             {% for user in assigned_users %}
                 <a href="/user/view/uid={{user.id}}">{{user.username}}</a>|
             {% endfor %}
+            {% if is_mentor %}
+                <a href="/task/user/remove/">Remove an existing user</a>
             <br />
+            {% endif %}
         {% endif %}
-        {%if can_assign_credits%}
+        {% if can_assign_credits %}
             <a href="/task/assigncredits/tid={{task.id}}">Assign credits</a>
-        {%endif%}
-        {% if not is_guest %}
+        {% endif %}
+        {% if not is_guest and task_claimable %}
             <a href="/task/claim/tid={{task.id}}">View claims</a><br />
         {% endif %}