# HG changeset patch # User Nishanth Amuluru # Date 1294514631 -19800 # Node ID 1cc8d0b2eefb1d18bcfccf46c0a2a8b964e3c4ac # Parent 1eb24b1662cfc7d0af604ca35fed9744eacc80d5 commenting on a task works as of now and there is a lot to do with view task diff -r 1eb24b1662cf -r 1cc8d0b2eefb pytask/taskapp/views.py --- a/pytask/taskapp/views.py Sun Jan 09 00:53:11 2011 +0530 +++ b/pytask/taskapp/views.py Sun Jan 09 00:53:51 2011 +0530 @@ -10,8 +10,9 @@ from pytask.utils import make_key from pytask.views import show_msg -from pytask.taskapp.models import Task -from pytask.taskapp.forms import CreateTaskForm, EditTaskForm +from pytask.taskapp.models import Task, TaskComment +from pytask.taskapp.forms import CreateTaskForm, EditTaskForm, TaskCommentForm +from pytask.taskapp.utils import getTask from pytask.profile.utils import get_notification @@ -52,3 +53,85 @@ return render_to_response('task/create.html', context) else: return show_msg(user, 'You are not authorised to create a task.') + +def view_task(request, tid): + """ get the task depending on its tid and display accordingly if it is a get. + check for authentication and add a comment if it is a post request. + """ + + task_url = "/task/view/tid=%s"%tid + task = getTask(tid) + + user = request.user + profile = user.get_profile() + + context = {"user": user, + "profile": profile, + "task": task, + } + + context.update(csrf(request)) + + 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() + + is_guest = True if not user.is_authenticated() else False + is_reviewer = True if user in task.reviewers.all() else False + + context.update({'is_guest':is_guest, + 'is_reviewer':is_reviewer, + 'comments':comments, + 'reviewers':reviewers, + }) + + claimed_users = task.claimed_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") + +# 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['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_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 + +# if task.status == "CD": +# context['closing_notification'] = Notification.objects.filter(task=task,role="CD")[0] +# elif task.status == "CM": +# context['completed_notification'] = Notifications.objects.filter(task=task,role="CM")[0] +# elif task.status == "WR": +# 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) + else: + return redirect(task_url) + else: + form = TaskCommentForm() + context['form'] = form + return render_to_response('task/view.html', context) + diff -r 1eb24b1662cf -r 1cc8d0b2eefb pytask/templates/task/view.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pytask/templates/task/view.html Sun Jan 09 00:53:51 2011 +0530 @@ -0,0 +1,138 @@ +{% extends 'base.html' %} +{% block title %} + {{task.title}} +{% endblock %} +{% block content %} +

{{ task.title }}

+ + {% if can_edit %} + Edit task + {% endif %} + + {% if can_publish %} + Approve task + {% endif %} + + {% if can_close %} + Close task + {% endif %} + + {% if can_delete %} + Delete task + {% endif %} + +
created by {{ task.created_by.username }} + on {{task.creation_datetime|date:"D d M Y"}} at {{task.creation_datetime|time:"H:i"}}
+ + {% ifequal task.status "UP" %} + Task can be viewed by: + {% else %} + Reviewers: + {% endifequal %} + + {% for reviewer in reviewers %} + {{reviewer.username}} + {% endfor %} + + {% if can_mod_reviewers %} + + {% ifequal task.status "UP" %} + Request others to view/edit the task + {% else %} + Add another Reviewer to this task + {% endifequal %} + {% endif %} +
+ +
+ Description:
+ {{ task.desc|linebreaksbr }} +


+ {% if task.tags.count %} + Tags: + {% for tag in task.tags %} + {{tag}} + {% endfor %} +
+ {% endif %} + + + {% ifequal task.status "CD" %} + Task has been closed by {{closing_notification.sent_from.username}} + on {{closing_notification.sent_date|date:"D d M Y"}} at {{closing_notification.sent_date|time:"H:i"}}
+ Reason: {{closing_notification.remarks}}
+ {% endifequal %} + + {% ifequal task.status "CM" %} + Task has been marked complete by + {{completed_notification.sent_from.username}} + on {{completed_notification.sent_date|date:"D d M Y"}} at {{completed_notification.sent_date|time:"H:i"}}
+ {% endifequal %} + + {% ifequal task.status "OP" %} +
There are no users working on this task.
+ {% endifequal %} + + {% if subs %} +
This task cannot be claimed.. It exists only to show all of its sub tasks in one place.
+ {% endif %} + + {% if assigned_users %} + Users working on this task: + {% for user in assigned_users %} + {{user.username}} + {% endfor %} + {% if is_reviewer %} + Remove an existing user + {% endif %} +
+ {% endif %} + + {% if can_assign_pynts %} + View/Assign pynts + {% endif %} + + {% if task_claimable %} + + {% if is_reviewer %} + View claims + {% else %} + Submit Work + Claim the task + {% endif %} + {% endif %} + + {% if comments %} +
+ comments:

+ {% for comment in comments %} + {{ comment.created_by.username }} + on {{ comment.comment_datetime|date:"D d M Y"}} at {{comment.comment_datetime|time:"H:i"}} wrote:
+ {{ comment.data|linebreaksbr }}

+ {% endfor %} + {% endif %} + + {% if not is_guest %} +
+ {% if error_msg %} + {{error_msg}}
+ {% endif %} + {% ifnotequal task.status "UP" %} + Add comment:
+
+ {% csrf_token %} + {{form.as_p}} + +
+ {% else %} + {% if is_reviewer %} + Add comment:
+
+ {% csrf_token %} + {{form.as_p}} + +
+ {% endif %} + {% endifnotequal %} + {% endif %} +{% endblock %}