added the functionality to close a task.
authornishanth
Sat, 27 Feb 2010 00:48:50 +0530
changeset 126 e5377fdaf110
parent 125 d3cfceb8e120
child 127 71888e23f323
added the functionality to close a task.
taskapp/events/task.py
taskapp/views/task.py
templates/task/close.html
templates/task/publish.html
templates/task/view.html
urls.py
--- a/taskapp/events/task.py	Fri Feb 26 23:22:23 2010 +0530
+++ b/taskapp/events/task.py	Sat Feb 27 00:48:50 2010 +0530
@@ -222,9 +222,23 @@
     task.status = "CM"
     task.save()
 
-    task.request_task.filter(is_replied=False).update(is_valid=False)
+    pending_requests = task.request_task.filter(is_replied=False)
+    pending_requests.update(is_valid=False)
 
     ## generate notification appropriately using marked_by
     ## we also have to mark unread requests as invalid
 
+def closeTask(task, closed_by):
+    """ set the status of task as CD.
+    generate notifications accordingly.
+    """
 
+    task.status = "CD"
+    task.save()
+
+    pending_requests = task.request_task.filter(is_replied=False)
+    pending_requests.update(is_valid=False)
+
+    ## generate notifications here
+
+
--- a/taskapp/views/task.py	Fri Feb 26 23:22:23 2010 +0530
+++ b/taskapp/views/task.py	Sat Feb 27 00:48:50 2010 +0530
@@ -6,7 +6,7 @@
 from pytask.taskapp.models import User, Task, Comment, Claim, Credit
 from pytask.taskapp.utilities.task import getTask
 from pytask.taskapp.forms.task import TaskCreateForm, AddMentorForm, AddTaskForm, ChoiceForm, AssignCreditForm, RemoveUserForm
-from pytask.taskapp.events.task import createTask, reqMentor, publishTask, addSubTask, addDep, addClaim, assignTask, updateTask, removeTask, removeUser, assignCredits, completeTask
+from pytask.taskapp.events.task import createTask, reqMentor, publishTask, addSubTask, addDep, addClaim, assignTask, updateTask, removeTask, removeUser, assignCredits, completeTask, closeTask
 from pytask.taskapp.views.user import show_msg
 
 ## everywhere if there is no task, django should display 500 message.. but take care of that in sensitive views like add mentor and all
@@ -83,7 +83,7 @@
               }
 
     context['can_publish'] = True if task.status == "UP" and user == task.created_by else False
-    context['task_viewable'] = True if ( task.status not in ["UP", "DL"] ) or is_mentor else False
+    context['task_viewable'] = True if ( task.status != "DL" ) or is_mentor else False
     context['task_claimable'] = True if task.status in ["OP", "WR"] else False
 
     context['can_mod_mentors'] = True if task.status in ["UP", "OP", "LO", "WR"] and is_mentor else False
@@ -513,3 +513,38 @@
     else:
         return show_msg(user, "You are not authorised to do this", task_url, "view the task")
 
+def close_task(request, tid):
+    """ task can be closed only if task is published.
+    call the event close task if everything is fine.
+    """
+
+    task_url = "/task/view/tid=%s"%tid
+    
+    user = request.user
+    task = getTask(tid)
+    
+    is_guest = True if not user.is_authenticated() else False
+    is_mentor = True if user in task.mentors.all() else False
+
+    if is_mentor:
+
+        context = {
+            'user':user,
+            'task':task,
+        }
+
+        if not task.status in ["UP", "CD", "DL", "CM"]:
+            if request.method == "POST":
+                data = request.POST
+                if not data.get("reason", None):
+                    context["error"] = "Please enter a reason for closing the task"
+                    return render_to_response('task/close.html', context)
+                else:
+                    closeTask(task, user)
+                    return show_msg(user, "The task has been closed.", task_url, "view the task.")
+            else:
+                return render_to_response('task/close.html', context)
+        else:
+            return show_msg(user, "The task is already closed or the task cannot be closed at this stage", task_url, "view the task")
+    else:
+        return show_msg(user, "You are not authorised to do this", task_url, "view the task")
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/templates/task/close.html	Sat Feb 27 00:48:50 2010 +0530
@@ -0,0 +1,22 @@
+{% extends 'base.html' %}
+{% block title %}
+    {{task.title}}
+{% endblock %}
+{% block content %}
+    <b>Disclaimer:</b><br />
+    If a task is closed, it implies the task is no more a valid task. The task cannot be edited or added subtasks/dependencies.
+    Please <a href="/task/assigncredits/tid={{task.id}}">click here</a> to return to assign credits page if you want to request assign of credits.
+    You cannot request assign of credits and all the pending requests on this task will be made invalid when a task is closed.<br /><br />
+    
+    The only difference between marking a task as closed and completed is that the tasks depending on completed tasks will be free to be claimed 
+    and worked on. This action cannot be undone. If you have double checked every thing, please provide a reason and close the task.<br />
+    
+    <br />
+    {% if error %}
+    Please provide a reason for closing the task.
+    {% endif %}
+    <form action="" method="post">
+        Reason: <input type="text" name="reason">
+        <input value="Close the task" type="submit">
+    </form>
+{% endblock %}
--- a/templates/task/publish.html	Fri Feb 26 23:22:23 2010 +0530
+++ b/templates/task/publish.html	Sat Feb 27 00:48:50 2010 +0530
@@ -4,10 +4,10 @@
 {% endblock %}
 {% block content %}
     <b>Disclaimer:</b><br />
-    Publishing a task will make the task visible to every one.
-    Only you will have mentoring rights on this task. But you can request another user also to mentor the task.<br />
+    Publishing a task will make the task visible to every one and cannot be edited there after.<br /><br />
+    Only you will have mentoring rights on this task. But you can request other users also to mentor the task. <br /><br />
     This action cannot be undone.
-    <br /><br />
+    <br />
     Please confirm if you want to publish.
     <form action="" method="post">
         <input value="Publish" type="submit">
--- a/templates/task/view.html	Fri Feb 26 23:22:23 2010 +0530
+++ b/templates/task/view.html	Sat Feb 27 00:48:50 2010 +0530
@@ -7,10 +7,18 @@
         <h3>{{ task.title }}</h3><br />
         <!-- we have to write our own datetime.strftime filter and use in the next line -->
         created by <a href="/user/view/uid={{ task.created_by.id }}">{{ task.created_by.username }}</a> on {{ task.creation_datetime.ctime }}<br />
-        if task_editable ..<br />
+
         {% if is_mentor %}
-            <a href="/task/edit/tid={{task.id}}">Edit task</a>
-            {% if can_publish %}|<a href="/task/publish/tid={{task.id}}">Publish task</a>{% endif %}
+        
+            {% ifequal task.status "UP" %}
+                <a href="/task/edit/tid={{task.id}}">Edit task</a>
+            {% else %}
+                <a href="/task/close/tid={{task.id}}">Close this task</a>
+            {% endifequal %}
+            
+            {% if can_publish %}
+                <a href="/task/publish/tid={{task.id}}">Publish task</a>
+            {% endif %}
             <br />
         {% endif %}
         
@@ -86,10 +94,10 @@
                 There are no users currently working on this task.<br />
             {% endif %}
             {% if can_assign_credits %}
-                <a href="/task/assigncredits/tid={{task.id}}">Assign credits</a>
+                <a href="/task/assigncredits/tid={{task.id}}">View/Assign credits</a>
             {% endif %}
             {% if not is_guest and task_claimable %}
-                <a href="/task/claim/tid={{task.id}}">View claims for this task</a>.<br />
+                <a href="/task/claim/tid={{task.id}}">View claims</a><br />
             {% endif %}
         {% else %}
             {% ifequal task.status "CD" %}
--- a/urls.py	Fri Feb 26 23:22:23 2010 +0530
+++ b/urls.py	Sat Feb 27 00:48:50 2010 +0530
@@ -28,7 +28,6 @@
     (r'^task/create/$', taskViews.create_task),
     (r'task/publish/tid=(\w+)/$', taskViews.publish_task),
     (r'^task/addmentor/tid=(\w+)$', taskViews.add_mentor),
-    #(r'^task/addtasks/tid=(\w+)', taskViews.add_tasks),
     (r'^task/edit/tid=(\w+)$', taskViews.edit_task),
     (r'^task/claim/tid=(\w+)$', taskViews.claim_task),
     (r'^task/assign/tid=(\w+)$', taskViews.assign_task),
@@ -37,6 +36,7 @@
     (r'^task/remtask/tid=(\w+)$', taskViews.remove_task),
     (r'^task/assigncredits/tid=(\w+)$', taskViews.assign_credits),
     (r'^task/complete/tid=(\w+)$', taskViews.complete_task),
+    (r'^task/close/tid=(\w+)$', taskViews.close_task),
     
     (r'^admin/', include(admin.site.urls)),