edit task works now
authorNishanth Amuluru <nishanth@fossee.in>
Sun, 09 Jan 2011 19:35:31 +0530
changeset 366 4c349f310dfc
parent 365 32457bce3437
child 367 13e171f09941
edit task works now
pytask/taskapp/urls.py
pytask/taskapp/views.py
pytask/templates/task/edit.html
pytask/templates/task/view.html
--- 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),
 )
 
--- 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
--- /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 %}
+    <form action="" method="post">
+    {% csrf_token %}
+    {{form.as_p}}
+    <input type="submit" value="Update">
+    </form>
+{% endblock %}
--- 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:<br /><br />
         {% for comment in comments %}
-            <a href="/user/view/uid={{comment.commented_by.uniq_key}}">{{ comment.commented_by.username }}</a> 
+            <a href="/user/view/uid={{comment.commented_by.id}}">{{ 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 />
         {% endfor %}