mark task as complete functionality is added.
authornishanth
Fri, 26 Feb 2010 13:22:13 +0530
changeset 114 38793914921b
parent 113 ea962d5fe99e
child 115 52f2b9968ccd
mark task as complete functionality is added.
taskapp/events/task.py
taskapp/management/commands/seed_db.py
taskapp/views/task.py
templates/task/assigncredits.html
templates/task/complete.html
templates/task/publish.html
templates/task/view.html
urls.py
--- a/taskapp/events/task.py	Fri Feb 26 11:34:17 2010 +0530
+++ b/taskapp/events/task.py	Fri Feb 26 13:22:13 2010 +0530
@@ -223,3 +223,17 @@
     creditobj.points = points
     creditobj.given_time = datetime.now()
     creditobj.save()
+
+def completeTask(task, marked_by):
+    """ set the status of task as completed.
+    We dont have to inform parent tasks.
+    That part is taken care by getTask method.
+    """
+
+    task.status = "CM"
+    task.save()
+
+    ## generate notification appropriately using marked_by
+    ## we also have to mark unread requests as invalid
+
+
--- a/taskapp/management/commands/seed_db.py	Fri Feb 26 11:34:17 2010 +0530
+++ b/taskapp/management/commands/seed_db.py	Fri Feb 26 13:22:13 2010 +0530
@@ -12,6 +12,8 @@
     """ a method to seed the database with random data """
     
     defaultMentor = userEvents.createSuUser("admin", "admin@example.com", "123456", datetime.now(), "M")
+    mentor_profile = defaultMentor.get_profile()
+    userEvents.updateProfile(mentor_profile, {'rights':"AD"})
     
     for i in range(1,10):
         
--- a/taskapp/views/task.py	Fri Feb 26 11:34:17 2010 +0530
+++ b/taskapp/views/task.py	Fri Feb 26 13:22:13 2010 +0530
@@ -5,7 +5,7 @@
 
 from pytask.taskapp.models import User, Task, Comment, Claim, Credit
 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, getTask, updateTask, removeTask, removeUser, assignCredits
+from pytask.taskapp.events.task import createTask, reqMentor, publishTask, addSubTask, addDep, addClaim, assignTask, getTask, updateTask, removeTask, removeUser, assignCredits, completeTask
 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
@@ -470,3 +470,46 @@
     """
     
     task = Task.objects.get(id=tid) 
+
+def complete_task(request, tid):
+
+    """ call the event called complete task.
+    and also pass it the current user to know who marked it as complete. 
+    """
+
+    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
+
+    claimed_users = task.claimed_users.all()
+    assigned_users = task.assigned_users.all()
+
+    assign_credits_url = '/task/assigncredits/tid=%s'%task.id
+    task_assigned_credits = task.credit_set.all()
+
+
+    if is_mentor:
+        if task.status in ["OP", "WR"]:
+
+            context = {
+                'user':user,
+                'task':task,
+            }
+
+            if task_assigned_credits:
+                if request.method=="POST":
+                    completeTask(task, user)
+                    return redirect(task_url)
+                else:
+                    return render_to_response('task/complete.html', context)
+            else:
+                return show_msg(user, "Nobody has been credited for doing this task.", assign_credits_url, "assign credits")
+        else:
+            return show_msg(user, "The task cannot be marked as completed 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")
+
--- a/templates/task/assigncredits.html	Fri Feb 26 11:34:17 2010 +0530
+++ b/templates/task/assigncredits.html	Fri Feb 26 13:22:13 2010 +0530
@@ -11,6 +11,7 @@
                 {{credit.points}} pynts were given by <a href="/user/view/uid={{credit.given_by.id}}">{{credit.given_by.username}}</a> to
                 <a href="/user/view/uid={{credit.given_to.id}}">{{credit.given_to.username}}</a> at {{credit.given_time.ctime}}<br />
             {% endfor %}
+            <a href="/task/complete/tid={{task.id}}">Mark task as complete.</a>
         {% endif %}
 
         <form action="" method="post">
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/templates/task/complete.html	Fri Feb 26 13:22:13 2010 +0530
@@ -0,0 +1,19 @@
+{% extends 'base.html' %}
+{% block title %}
+    {{task.title}}
+{% endblock %}
+{% block content %}
+    <b>Disclaimer:</b><br />
+    Marking a task as complete implies the task has been completed successfully. It implies that all the required files 
+    are available as attatchments in comments and all the users worked on this task were credited accordingly.<br /><br />
+    This action sets the task as completed and frees all the tasks depending on this task. Henceforth, the task <strong>can not</strong> be 
+    commented upon or edited by anyone.<br /><br />
+    If there are pending requests for assigning credits, they will be deleted and admins will not be able to approve those requests.
+    Hence you cannot assign credits to anyone for this task anymore. You must wait for the requests to be approved by any of the admins. 
+    If you would like to request for assigning more credits, return to assign credits page by clicking 
+    <a href="/task/assigncredits/tid={{task.id}}">here</a>.<br /><br />
+    If you have double checked everything, confirm this action by clicking the button below.
+    <form action="" method="post">
+        <input value="Mark as Complete" type="submit">
+    </form>
+{% endblock %}
--- a/templates/task/publish.html	Fri Feb 26 11:34:17 2010 +0530
+++ b/templates/task/publish.html	Fri Feb 26 13:22:13 2010 +0530
@@ -5,8 +5,9 @@
 {% block content %}
     <b>Disclaimer:</b><br />
     Publishing a task will make the task visible to every one.
-    All the existing mentors will be removed from the list of mentors and only you will have the rights to edit and mentor the task.
-    But mentors can be added by sending them a request later on.<br /><br />
+    Only you will have mentoring rights on this task. But you can request another user also to mentor the task.<br />
+    This action cannot be undone.
+    <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 11:34:17 2010 +0530
+++ b/templates/task/view.html	Fri Feb 26 13:22:13 2010 +0530
@@ -7,6 +7,7 @@
         <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 %}
@@ -71,25 +72,32 @@
         <br />{{ task.desc }}<br />
         <hr>
         
-        status of task is {{task.status}}<br />
-        {% if assigned_users %}
-            Users working on this task:
-            {% for user in assigned_users %}
-                <a href="/user/view/uid={{user.id}}">{{user.username}}</a>|
-            {% endfor %}
-            {% if is_mentor %}
-                <a href="/task/remuser/tid={{task.id}}">Remove an existing user</a>
-            <br />
+        {% ifnotequal task.status "CM" %}
+            {% if assigned_users %}
+                Users working on this task:
+                {% for user in assigned_users %}
+                    <a href="/user/view/uid={{user.id}}">{{user.username}}</a>|
+                {% endfor %}
+                {% if is_mentor %}
+                    <a href="/task/remuser/tid={{task.id}}">Remove an existing user</a>
+                <br />
+                {% endif %}
+            {% else %}
+                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>
+            {% endif %}
+            {% if not is_guest and task_claimable %}
+                <a href="/task/claim/tid={{task.id}}">View claims for this task</a>.<br />
             {% endif %}
         {% else %}
-            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>
-        {% endif %}
-        {% if not is_guest and task_claimable %}
-            <a href="/task/claim/tid={{task.id}}">View claims for this task</a>.<br />
-        {% endif %}
+            {% ifequal task.status "CD" %}
+                The task has been closed by .. due to ..
+            {% else %}
+                The task is complete.
+            {% endifequal %}
+        {% endifnotequal %}
         
         {% if comments %}
             <hr />
@@ -101,12 +109,14 @@
         {% endif %}
 
         {% if not is_guest %}
-            <br />Add comment:<br />
-            <form action="" method="post">
-            <!-- we might even want to use forms here -->
-            <textarea  name="data"></textarea><br />
-            <input type="submit" value="Submit">
-            </form>
+            {% ifnotequal task.status "CM" %}
+                <br />Add comment:<br />
+                <form action="" method="post">
+                <!-- we might even want to use forms here -->
+                <textarea  name="data"></textarea><br />
+                <input type="submit" value="Submit">
+                </form>
+            {% endifnotequal %}
         {% endif %}
     {% else %}
         You are not authorised to view this task. <a href="/task/browse/">click here</a> to return to browsing the tasks.
--- a/urls.py	Fri Feb 26 11:34:17 2010 +0530
+++ b/urls.py	Fri Feb 26 13:22:13 2010 +0530
@@ -36,6 +36,7 @@
     (r'^task/addtask/tid=(\d+)$', taskViews.add_tasks),
     (r'^task/remtask/tid=(\d+)$', taskViews.remove_task),
     (r'^task/assigncredits/tid=(\d+)$', taskViews.assign_credits),
+    (r'^task/complete/tid=(\d+)$', taskViews.complete_task),
     
     (r'^admin/', include(admin.site.urls)),