view task is now in some shape atleast
authorNishanth Amuluru <nishanth@fossee.in>
Sun, 09 Jan 2011 08:37:28 +0530
changeset 112 4cc40503bf3c
parent 111 1cc8d0b2eefb
child 113 ac75d3cfa96f
view task is now in some shape atleast
pytask/taskapp/views.py
pytask/templates/task/view.html
--- a/pytask/taskapp/views.py	Sun Jan 09 00:53:51 2011 +0530
+++ b/pytask/taskapp/views.py	Sun Jan 09 08:37:28 2011 +0530
@@ -63,6 +63,10 @@
     task = getTask(tid)
 
     user = request.user
+
+    if not user.is_authenticated():
+        return render_to_response("/task/view.html", {"task": task})
+
     profile = user.get_profile()
 
     context = {"user": user,
@@ -75,38 +79,39 @@
     if task.status == "DL":
         return show_msg(user, 'This task no longer exists', '/task/browse/','browse the tasks')
 
-    comments = task.comments.filter(is_deleted=False).order_by('comment_datetime')
-    reviewers = task.reviewers.all()
+    task_viewable = True if ( task.status != "UP" ) or profile.rights != "CT"\
+                         else False
+    if not task_viewable:
+        return show_msg(user, "You are not authorised to view this task", "/task/browse/", "browse the tasks")
 
-    is_guest = True if not user.is_authenticated() else False
+    reviewers = task.reviewers.all()
     is_reviewer = True if user in task.reviewers.all() else False
+    comments = task.comments.filter(is_deleted=False).order_by('comment_datetime')
 
-    context.update({'is_guest':is_guest,
-                    'is_reviewer':is_reviewer,
+    context.update({'is_reviewer':is_reviewer,
                     'comments':comments,
                     'reviewers':reviewers,
                    })
 
     claimed_users = task.claimed_users.all()
-
+    selected_users = task.selected_users.all()
 
-#    is_requested_reviewer = True if user.is_authenticated() and user.request_sent_to.filter(is_valid=True,is_replied=False,role="MT",task=task) else False
-#    task_viewable = True if ( task.status != "UP" ) or is_reviewer or is_requested_reviewer else False
-#    if not task_viewable:
-#        return show_msg(user, "You are not authorised to view this task", "/task/browse/", "browse the tasks")
+    is_creator = True if user == task.created_by else False
+    has_claimed = True if user in claimed_users else False
 
-#    context['is_requested_reviewer'] = is_requested_reviewer
-
-    context['can_publish'] = True if task.status == "UP" and user == task.created_by else False
-    context['can_edit'] = True if task.status == "UP" and is_reviewer else False
+    context['is_selected'] = True if user in selected_users else False
+    context['can_approve'] = True if task.status == "UP" and\
+                                     profile.rights in ["MG", "DC"]\
+                                     else False
+    context['can_edit'] = True if is_creator else False
     context['can_close'] = True if task.status not in ["UP", "CD", "CM"] and is_reviewer else False
-    context['can_delete'] = True if task.status == "UP" and user == task.created_by else False
-
-    context['can_mod_reviewers'] = True if task.status in ["UP", "OP", "LO", "WR"] and is_reviewer else False
-    context['can_mod_tasks'] = True if task.status in ["UP", "OP", "LO"] and is_reviewer else False
+    context['can_delete'] = True if task.status == "UP" and is_creator else False
 
     context['can_assign_pynts'] = True if task.status in ["OP", "WR"] and is_reviewer else False
-    context['task_claimable'] = True if task.status in ["OP", "WR"] and not is_guest else False
+    context['task_claimable'] = True if task.status in ["OP", "WR"] else False
+
+    context['can_comment'] = True if task.status != "UP" or\
+                                     profile.rights!="CT" else False
 
 #    if task.status == "CD":
 #        context['closing_notification'] =  Notification.objects.filter(task=task,role="CD")[0]
@@ -116,20 +121,17 @@
 #        context['assigned_users'] = task.assigned_users.all()
    
     if request.method == 'POST':
-        if not is_guest:
-            form = TaskCommentForm(request.POST)
-            if form.is_valid():
-                data = form.cleaned_data['data']
-                new_comment = TaskComment(task=task, data=data,
-                                          uniq_key=make_key(TaskComment),
-                                          commented_by=user, comment_datetime=datetime.now())
-                new_comment.save()
-                return redirect(task_url)
-            else:
-                context['form'] = form
-                return render_to_response('task/view.html', context)
+        form = TaskCommentForm(request.POST)
+        if form.is_valid():
+            data = form.cleaned_data['data']
+            new_comment = TaskComment(task=task, data=data,
+                                      uniq_key=make_key(TaskComment),
+                                      commented_by=user, comment_datetime=datetime.now())
+            new_comment.save()
+            return redirect(task_url)
         else:
-            return redirect(task_url)
+            context['form'] = form
+            return render_to_response('task/view.html', context)
     else:
         form = TaskCommentForm()
         context['form'] = form
--- a/pytask/templates/task/view.html	Sun Jan 09 00:53:51 2011 +0530
+++ b/pytask/templates/task/view.html	Sun Jan 09 08:37:28 2011 +0530
@@ -9,7 +9,7 @@
         <a href="/task/edit/tid={{task.uniq_key}}">Edit task</a>
     {% endif %}
     
-    {% if can_publish %}
+    {% if can_approve %}
         <a href="/task/approve/tid={{task.uniq_key}}">Approve task</a>
     {% endif %}
     
@@ -24,15 +24,18 @@
     <hr />created by <a href="/user/view/uid={{ task.created_by.uniq_key }}">{{ task.created_by.username }}</a>
     on {{task.creation_datetime|date:"D d M Y"}} at {{task.creation_datetime|time:"H:i"}}<br />
     
-    {% ifequal task.status "UP" %}
-        Task can be viewed by:
-    {% else %}
-        Reviewers:
-    {% endifequal %}
-    
-    {% for reviewer in reviewers %}
-        <a href="/user/view/uid={{reviewer.id}}">{{reviewer.username}}</a>
-    {% endfor %}
+    {% if reviewers %}
+	    {% ifequal task.status "UP" %}
+		Task can be viewed by:
+	    {% else %}
+		Reviewers:
+	    {% endifequal %}
+	    
+	    {% for reviewer in reviewers %}
+		<a href="/user/view/uid={{reviewer.id}}">{{reviewer.username}}</a>
+	    {% endfor %}
+    {% endif %}
+
     
     {% if can_mod_reviewers %}
         <a href="/task/addreviewer/tid={{task.uniq_key}}">
@@ -57,6 +60,7 @@
     {% endif %}
 
     
+    <!--
     {% ifequal task.status "CD" %}
         Task has been closed by <a href="/user/view={{closing_notification.sent_from.id}}">{{closing_notification.sent_from.username}}</a>
         on {{closing_notification.sent_date|date:"D d M Y"}} at {{closing_notification.sent_date|time:"H:i"}}<br />
@@ -76,8 +80,9 @@
     {% if subs %}
         <br />This task cannot be claimed.. It exists only to show all of its sub tasks in one place.<br />
     {% endif %}
+    -->
         
-    {% if assigned_users %}
+    {% if selected_users %}
         Users working on this task:
         {% for user in assigned_users %}
             <a href="/user/view/uid={{user.id}}">{{user.username}}</a>
@@ -88,51 +93,36 @@
         <br />
     {% endif %}
     
+    {% if task_claimable %}
+	<a href="/task/claim/tid={{task.uniq_key}}">View claims</a>
+    {% endif %}
+
     {% if can_assign_pynts %}
-        <a href="/task/assignpynts/tid={{task.uniq_key}}">View/Assign pynts</a>
+        <a href="/task/assignpynts/tid={{task.uniq_key}}">Request assign pynts and mark the task as complete</a>
     {% endif %}
     
-    {% if task_claimable %}
-        <a href="/task/claim/tid={{task.uniq_key}}">
-        {% if is_reviewer %}
-            View claims
-        {% else %}
+
+    {% if is_selected %}
         <a href="/task/report/tid={{task.uniq_key}}">Submit Work</a>
-            Claim the task
-        {% endif %}</a>
     {% endif %}
     
     {% if comments %}
         <hr />
         comments:<br /><br />
         {% for comment in comments %}
-            <a href="/user/view/uid={{comment.created_by.uniq_key}}">{{ comment.created_by.username }}</a> 
+            <a href="/user/view/uid={{comment.commented_by.uniq_key}}">{{ comment.commented_by.username }}</a> 
             on {{ comment.comment_datetime|date:"D d M Y"}} at {{comment.comment_datetime|time:"H:i"}} wrote:<br />
         {{ comment.data|linebreaksbr }}<br /><br />
         {% endfor %}
     {% endif %}
 
-    {% if not is_guest %}
-        <hr />
-        {% if error_msg %}
-            {{error_msg}}<br />
-        {% endif %}
-        {% ifnotequal task.status "UP" %}
-            Add comment:<br />
-            <form action="" method="post">
-		    {% csrf_token %}
-		    {{form.as_p}}
-            <input type="submit" value="Submit">
-            </form>
-        {% else %}
-            {% if is_reviewer %}
-            Add comment:<br />
-                <form action="" method="post">
-		    {% csrf_token %}
-		    {{form.as_p}}
-                <input type="submit" value="Submit">
-                </form>                
-            {% endif %}
-        {% endifnotequal %}
+    {% if can_comment %}
+    Add comment:<br />
+	<form action="" method="post">
+	    {% csrf_token %}
+	    {{form.as_p}}
+	<input type="submit" value="Submit">
+	</form>                
     {% endif %}
+
 {% endblock %}