add reviewer works now
authorNishanth Amuluru <nishanth@fossee.in>
Tue, 11 Jan 2011 14:57:16 +0530
changeset 381 da4c6b1cec7d
parent 380 e848bd3ad41f
child 382 daca865314e7
add reviewer works now
pytask/taskapp/forms.py
pytask/taskapp/urls.py
pytask/taskapp/views.py
pytask/templates/task/addreviewer.html
pytask/templates/task/view.html
--- a/pytask/taskapp/forms.py	Tue Jan 11 14:30:25 2011 +0530
+++ b/pytask/taskapp/forms.py	Tue Jan 11 14:57:16 2011 +0530
@@ -78,11 +78,11 @@
             raise forms.ValidationError('Enter something as a proposal')
         return data
 
-def ChoiceForm(choices, data=None):
+def ChoiceForm(choices, data=None, label="choice"):
     """ return a form object with appropriate choices """
     
     class myform(forms.Form):
-        choice = forms.ChoiceField(choices=choices, required=True)
+        choice = forms.ChoiceField(choices=choices, required=True, label=label)
     form = myform(data) if data else myform()
     return form
 
@@ -98,14 +98,6 @@
         model = TextBook
         fields = ['name', 'chapters', 'tags_field']
 
-def AddReviewerForm(choices,instance=None):
-    """ return a form object with appropriate choices """
-    
-    class myform(forms.Form):
-        reviewer = forms.ChoiceField(choices=choices, required=True)
-    form = myform(instance) if instance else myform()
-    return form
-
 def AddTaskForm(task_choices, is_plain=False):
     """ if is_plain is true, it means the task has no subs/deps.
     so we also give a radio button to choose between subs and dependencies.
--- a/pytask/taskapp/urls.py	Tue Jan 11 14:30:25 2011 +0530
+++ b/pytask/taskapp/urls.py	Tue Jan 11 14:57:16 2011 +0530
@@ -3,7 +3,7 @@
 from pytask.taskapp.views import create_task, view_task, claim_task, \
         select_user, edit_task, create_textbook, view_textbook, \
         browse_tasks, edit_textbook, approve_task, approved_task,\
-        browse_textbooks, approve_textbook, approved_textbook
+        browse_textbooks, approve_textbook, approved_textbook, addreviewer
 
 from pytask.views import under_construction
 
@@ -16,6 +16,7 @@
             (r'^select/tid=(\w+)$', select_user),
             (r'^approve/tid=(\w+)$', approve_task),
             (r'^approved/tid=(\w+)$', approved_task),
+            (r'^addreviewer/tid=(\w+)$', addreviewer),
             (r'^browse/$', browse_tasks),
 
             (r'^textbook/create/$', create_textbook),
--- a/pytask/taskapp/views.py	Tue Jan 11 14:30:25 2011 +0530
+++ b/pytask/taskapp/views.py	Tue Jan 11 14:57:16 2011 +0530
@@ -148,6 +148,9 @@
     context['can_comment'] = True if task.status != "UP" or\
                                      profile.rights!="CT" else False
 
+    context['can_mod_reviewers'] = True if profile.rights in ["MG", "DC"] else\
+                                   False
+
 #    if task.status == "CD":
 #        context['closing_notification'] =  Notification.objects.filter(task=task,role="CD")[0]
 #    elif task.status == "CM":
@@ -253,6 +256,53 @@
     return render_to_response("task/approved_task.html", context)
 
 @login_required
+def addreviewer(request, tid):
+
+    user = request.user
+    profile = user.get_profile()
+
+    task_url = "/task/view/tid=%s"%tid
+    task = getTask(tid)
+
+    can_mod_reviewers = True if profile.rights in ["MG", "DC"] else False
+    if not can_mod_reviewers:
+        raise Http404
+
+    context = {"user": user,
+               "profile": profile,
+               "task": task,
+              }
+
+    context.update(csrf(request))
+
+
+    # This part has to be made better
+    reviewer_choices = User.objects.filter(is_active=True).\
+                                           exclude(reviewing_tasks__uniq_key=tid).\
+                                           exclude(claimed_tasks__uniq_key=tid).\
+                                           exclude(approved_tasks__uniq_key=tid).\
+                                           exclude(created_tasks__uniq_key=tid)
+    choices = ((a_user.id,a_user.username) for a_user in reviewer_choices)
+    label = "Reviewer"
+
+    if request.method == "POST":
+        form = ChoiceForm(choices, data=request.POST, label=label)
+        if form.is_valid():
+            data = form.cleaned_data.copy()
+            uid = data['choice']
+            reviewer = User.objects.get(id=uid)
+
+            task.reviewers.add(reviewer)
+            return redirect(task_url)
+        else:
+            context.update({"form": form})
+            return render_to_response("task/addreviewer.html", context)
+    else:
+        form = ChoiceForm(choices, label=label)
+        context.update({"form": form})
+        return render_to_response("task/addreviewer.html", context)
+
+@login_required
 def create_textbook(request):
 
     user = request.user
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pytask/templates/task/addreviewer.html	Tue Jan 11 14:57:16 2011 +0530
@@ -0,0 +1,9 @@
+{% extends 'base.html' %}
+{% block content %}
+    Select a user as a reviewer for this task.<br />
+    <form action="" method="POST">
+	    {% csrf_token %}
+    {{form.as_table}}
+    <input type="submit" value="Select">
+    </form>
+{% endblock %}
--- a/pytask/templates/task/view.html	Tue Jan 11 14:30:25 2011 +0530
+++ b/pytask/templates/task/view.html	Tue Jan 11 14:57:16 2011 +0530
@@ -27,12 +27,7 @@
     on {{task.creation_datetime|date:"D d M Y"}} at {{task.creation_datetime|time:"H:i"}}<br />
     
     {% if reviewers %}
-	    {% ifequal task.status "UP" %}
-		Task can be viewed by:
-	    {% else %}
 		Reviewers:
-	    {% endifequal %}
-	    
 	    {% for reviewer in reviewers %}
 		<a href="/profile/user/view/uid={{reviewer.id}}">{{reviewer.username}}</a>
 	    {% endfor %}
@@ -41,11 +36,7 @@
     
     {% if can_mod_reviewers %}
         <a href="/task/addreviewer/tid={{task.uniq_key}}">
-        {% ifequal task.status "UP" %}
-            Request others to view/edit the task
-        {% else %}
-            Add another Reviewer to this task
-        {% endifequal %}</a>
+		Add a Reviewer to this task</a>
     {% endif %}
     <br />