ditchaxed credit model.
--- a/taskapp/admin.py Sun Feb 28 20:49:59 2010 +0530
+++ b/taskapp/admin.py Sun Feb 28 22:49:05 2010 +0530
@@ -1,11 +1,10 @@
from django.contrib import admin
-from pytask.taskapp.models import Profile, Task, Credit, Comment, Claim, Notification, Request
+from pytask.taskapp.models import Profile, Task, Comment, Claim, Notification, Request
admin.site.register(Profile)
admin.site.register(Task)
admin.site.register(Comment)
-admin.site.register(Credit)
admin.site.register(Claim)
admin.site.register(Notification)
admin.site.register(Request)
--- a/taskapp/events/request.py Sun Feb 28 20:49:59 2010 +0530
+++ b/taskapp/events/request.py Sun Feb 28 22:49:05 2010 +0530
@@ -1,6 +1,6 @@
from datetime import datetime
from pytask.taskapp.models import Profile
-from pytask.taskapp.events.task import addCredits, addMentor
+from pytask.taskapp.events.task import addMentor
from pytask.taskapp.events.user import changeRole
from pytask.taskapp.utilities.notification import create_notification
@@ -25,12 +25,9 @@
pynts = request_obj.pynts
receiving_user = request_obj.receiving_user
requested_by = request_obj.sent_by
- for a_mentor in task.mentors.all():
- if reply:
- addCredits(task, request_obj.sent_by, request_obj.receiving_user, pynts)
- create_notification(request_obj.role, a_mentor, replied_by, True, task, request_obj.remarks, requested_by, receiving_user, pynts)
- else:
- create_notification(request_obj.role, a_mentor, replied_by, False, task, request_obj.remarks, requested_by, receiving_user, pynts)
+ create_notification(request_obj.role, receiving_user, replied_by, reply, task, request_obj.remarks, requested_by, receiving_user, pynts)
+ if receiving_user != requested_by:
+ create_notification(request_obj.role, requested_by, replied_by, reply, task, request_obj.remarks, requested_by, receiving_user, pynts)
elif request_obj.role == "MT":
task = request_obj.task
--- a/taskapp/events/task.py Sun Feb 28 20:49:59 2010 +0530
+++ b/taskapp/events/task.py Sun Feb 28 22:49:05 2010 +0530
@@ -1,5 +1,5 @@
from datetime import datetime
-from pytask.taskapp.models import Profile, Task, Comment, Credit, Claim, Map
+from pytask.taskapp.models import Profile, Task, Comment, Claim, Map
from pytask.taskapp.utilities.task import getTask
from pytask.taskapp.utilities.request import create_request
from pytask.taskapp.utilities.helper import get_key
@@ -102,8 +102,6 @@
task.save()
return task
-
-
def createTask(title,desc,created_by,credits):
""" creates a bare minimum task with title, description and credits.
the creator of the task will be assigned as a mentor for the task.
@@ -189,31 +187,12 @@
main_task.assigned_users.remove(rem_user)
main_task.save()
-def completeTask(main_task):
- """ set the status of task to CP.
- """
-
- main_task.status = "CP"
- main_task.save()
-
def assignCredits(task, given_by, given_to, points):
""" make a proper request object.
"""
create_request(sent_by=given_by, role="PY", task=task, receiving_user=given_to, pynts=points )
-def addCredits(task, given_by, given_to, points):
- """ add credit to the credits model.
- """
-
- creditobj = Credit()
- creditobj.task = task
- creditobj.given_by = given_by
- creditobj.given_to = given_to
- 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.
@@ -229,7 +208,18 @@
## generate notification appropriately using marked_by
## we also have to mark unread requests as invalid
-def closeTask(task, closed_by):
+ for a_user in task.assigned_users.all():
+ create_notification(role="CM", sent_to=a_user, sent_from=marked_by, task=task)
+
+ for a_user in task.claimed_users.all():
+ create_notification(role="CM", sent_to=a_user, sent_from=marked_by, task=task)
+
+ for a_mentor in task.mentors.all():
+ create_notification(role="CM", sent_to=a_mentor, sent_from=marked_by, task=task)
+
+
+
+def closeTask(task, closed_by, reason=None):
""" set the status of task as CD.
generate notifications accordingly.
"""
@@ -242,4 +232,13 @@
## generate notifications here
+ for a_user in task.assigned_users.all():
+ create_notification(role="CD", sent_to=a_user, sent_from=marked_by, task=task)
+ for a_user in task.claimed_users.all():
+ create_notification(role="CD", sent_to=a_user, sent_from=marked_by, task=task)
+
+ for a_mentor in task.mentors.all():
+ create_notification(role="CD", sent_to=a_mentor, sent_from=marked_by, task=task)
+
+
--- a/taskapp/events/user.py Sun Feb 28 20:49:59 2010 +0530
+++ b/taskapp/events/user.py Sun Feb 28 22:49:05 2010 +0530
@@ -1,5 +1,5 @@
from django.contrib.auth.models import User
-from pytask.taskapp.models import Profile, Task, Comment, Credit
+from pytask.taskapp.models import Profile, Task, Comment
""" A collection of helper methods. note that there is no validation done here.
we take care of validation and others checks in methods that invoke these methods.
--- a/taskapp/models.py Sun Feb 28 20:49:59 2010 +0530
+++ b/taskapp/models.py Sun Feb 28 22:49:05 2010 +0530
@@ -127,17 +127,6 @@
def __unicode__(self):
return unicode(self.task.title)
-class Credit(models.Model):
-
- task = models.ForeignKey('Task')
- given_by = models.ForeignKey(User, related_name = "%(class)s_given_by")
- given_to = models.ForeignKey(User, related_name = "%(class)s_given_to")
- points = models.PositiveSmallIntegerField()
- given_time = models.DateTimeField()
-
- def __unicode__(self):
- return unicode(self.task.title)
-
class Claim(models.Model):
task = models.ForeignKey('Task')
--- a/taskapp/utilities/notification.py Sun Feb 28 20:49:59 2010 +0530
+++ b/taskapp/utilities/notification.py Sun Feb 28 22:49:05 2010 +0530
@@ -102,13 +102,30 @@
working_users = task.assigned_users.all()
if working_users:
- notification_message += "List of users working on the task.<br />"
- notification_message += "<ul>"
+ notification.message += "List of users working on the task.<br />"
+ notification.message += "<ul>"
for a_user in working_users:
notification.message += "<li> %s - %s </li>"%(a_user.username, a_user.email)
notification.message += "</ul><br />"
notification.message += "Happy Mentoring."
+ elif role in ["CM", "CD"]:
+ mentor = sent_from
+ mentor_url = '<a href="/user/view/uid=%s">%s</a>'%(mentor.id, mentor.username)
+ task_url= '<a href="/task/view/tid=%s">%s</a>'%(task.id, task.title)
+
+ if role == "CM":
+ notification.sub = "%s has been marked complete"%task.title
+ notification.message = "The task %s has been marked complete by %s.<br />"%(task_url, mentor_url)
+
+ elif role == "CD":
+ notification.sub = "%s has been closed"%task.title
+ notification.message = "The task %s has been closed by %s.<br />"%(task_url, mentor_url)
+
+ if remarks:
+ notification.message += "<b>Remarks:</b> %s"%remarks
+
+
notification.save()
def mark_notification_read(notification_id):
--- a/taskapp/views/task.py Sun Feb 28 20:49:59 2010 +0530
+++ b/taskapp/views/task.py Sun Feb 28 22:49:05 2010 +0530
@@ -3,7 +3,7 @@
from django.http import HttpResponse, Http404
from django.shortcuts import render_to_response, redirect
-from pytask.taskapp.models import User, Task, Comment, Claim, Credit, Request
+from pytask.taskapp.models import User, Task, Comment, Claim, Request
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, closeTask
@@ -492,9 +492,7 @@
task = Task.objects.get(id=tid)
user = get_user(request.user) if request.user.is_authenticated() else request.user
-
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.
"""
@@ -562,7 +560,7 @@
context["error"] = "Please enter a reason for closing the task"
return render_to_response('task/close.html', context)
else:
- closeTask(task, user)
+ closeTask(task, user, data['reason'])
return show_msg(user, "The task has been closed.", task_url, "view the task.")
else:
return render_to_response('task/close.html', context)