# HG changeset patch # User Nishanth Amuluru # Date 1294581931 -19800 # Node ID 4c349f310dfc2d2532d626ccd4a1739ab0950fa7 # Parent 32457bce3437b399c853dc5b94c975b076cc10e5 edit task works now diff -r 32457bce3437 -r 4c349f310dfc pytask/taskapp/urls.py --- a/pytask/taskapp/urls.py Sun Jan 09 15:30:06 2011 +0530 +++ b/pytask/taskapp/urls.py Sun Jan 09 19:35:31 2011 +0530 @@ -1,13 +1,14 @@ from django.conf.urls.defaults import * from pytask.taskapp.views import create_task, view_task, claim_task, \ - select_user + select_user, edit_task urlpatterns = patterns('', (r'^create/$', create_task), - (r'^view/tid=(\w+)', view_task), - (r'^claim/tid=(\w+)', claim_task), - (r'^select/tid=(\w+)', select_user), + (r'^edit/tid=(\w+)$', edit_task), + (r'^view/tid=(\w+)$', view_task), + (r'^claim/tid=(\w+)$', claim_task), + (r'^select/tid=(\w+)$', select_user), ) diff -r 32457bce3437 -r 4c349f310dfc pytask/taskapp/views.py --- a/pytask/taskapp/views.py Sun Jan 09 15:30:06 2011 +0530 +++ b/pytask/taskapp/views.py Sun Jan 09 19:35:31 2011 +0530 @@ -15,7 +15,7 @@ from pytask.taskapp.models import Task, TaskComment, TaskClaim from pytask.taskapp.forms import CreateTaskForm, EditTaskForm, \ TaskCommentForm, ClaimTaskForm, \ - ChoiceForm + ChoiceForm, EditTaskForm from pytask.taskapp.utils import getTask from pytask.profile.utils import get_notification @@ -108,7 +108,7 @@ 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_edit'] = True if is_creator and task.status == "UP" 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 is_creator else False @@ -143,6 +143,46 @@ return render_to_response('task/view.html', context) @login_required +def edit_task(request, tid): + """ only creator gets to edit the task and that too only before it gets + approved. + """ + + user = request.user + profile = user.get_profile() + + task_url = "/task/view/tid=%s"%tid + task = getTask(tid) + + is_creator = True if user == task.created_by else False + can_edit = True if task.status == "UP" and is_creator else False + if not can_edit: + raise Http404 + + context = {"user": user, + "profile": profile, + "task": task, + } + + context.update(csrf(request)) + + if request.method == "POST": + form = EditTaskForm(request.POST, instance=task) + if form.is_valid(): + form.save() + return redirect(task_url) + else: + context.update({"form": form}) + return render_to_response("task/edit.html", context) + else: + form = EditTaskForm(instance=task) + context.update({"form": form}) + return render_to_response("task/edit.html", context) + + + + +@login_required def claim_task(request, tid): task_url = "/task/view/tid=%s"%tid diff -r 32457bce3437 -r 4c349f310dfc pytask/templates/task/edit.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pytask/templates/task/edit.html Sun Jan 09 19:35:31 2011 +0530 @@ -0,0 +1,8 @@ +{% extends 'base.html' %} +{% block content %} +
+ {% csrf_token %} + {{form.as_p}} + +
+{% endblock %} diff -r 32457bce3437 -r 4c349f310dfc pytask/templates/task/view.html --- a/pytask/templates/task/view.html Sun Jan 09 15:30:06 2011 +0530 +++ b/pytask/templates/task/view.html Sun Jan 09 19:35:31 2011 +0530 @@ -106,7 +106,7 @@ {% if comments %} comments:

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