# HG changeset patch
# User nishanth
# Date 1267170733 -19800
# Node ID 38793914921b96b304603fd9eca122bd77cd078d
# Parent ea962d5fe99e15e704a7e6609a928f870179b36c
mark task as complete functionality is added.
diff -r ea962d5fe99e -r 38793914921b taskapp/events/task.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
+
+
diff -r ea962d5fe99e -r 38793914921b taskapp/management/commands/seed_db.py
--- 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):
diff -r ea962d5fe99e -r 38793914921b taskapp/views/task.py
--- 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")
+
diff -r ea962d5fe99e -r 38793914921b templates/task/assigncredits.html
--- 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 {{credit.given_by.username}} to
{{credit.given_to.username}} at {{credit.given_time.ctime}}
{% endfor %}
+ Mark task as complete.
{% endif %}