diff options
author | nishanth | 2010-02-28 22:49:05 +0530 |
---|---|---|
committer | nishanth | 2010-02-28 22:49:05 +0530 |
commit | 2e78ea670355735b7a717dcfd87f1690cacf6ef6 (patch) | |
tree | 95456e7d23f862a2748dc5bb130bcaaa8733aa22 | |
parent | 32a2753b002516357f6504a76d28851f0cc94829 (diff) | |
download | pytask-2e78ea670355735b7a717dcfd87f1690cacf6ef6.tar.gz pytask-2e78ea670355735b7a717dcfd87f1690cacf6ef6.tar.bz2 pytask-2e78ea670355735b7a717dcfd87f1690cacf6ef6.zip |
ditchaxed credit model.
-rw-r--r-- | taskapp/admin.py | 3 | ||||
-rw-r--r-- | taskapp/events/request.py | 11 | ||||
-rw-r--r-- | taskapp/events/task.py | 45 | ||||
-rw-r--r-- | taskapp/events/user.py | 2 | ||||
-rw-r--r-- | taskapp/models.py | 11 | ||||
-rw-r--r-- | taskapp/utilities/notification.py | 21 | ||||
-rw-r--r-- | taskapp/views/task.py | 6 |
7 files changed, 49 insertions, 50 deletions
diff --git a/taskapp/admin.py b/taskapp/admin.py index 1d18b4e..719c87e 100644 --- a/taskapp/admin.py +++ b/taskapp/admin.py @@ -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) diff --git a/taskapp/events/request.py b/taskapp/events/request.py index b74f678..8d83851 100644 --- a/taskapp/events/request.py +++ b/taskapp/events/request.py @@ -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 @@ def reply_to_request(request_obj, reply, replied_by): 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 diff --git a/taskapp/events/task.py b/taskapp/events/task.py index fb3c3f3..0d214ef 100644 --- a/taskapp/events/task.py +++ b/taskapp/events/task.py @@ -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 @@ def addMentor(task,mentor): 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 @@ def removeUser(main_task, rem_user): 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 @@ def completeTask(task, marked_by): ## 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 @@ def closeTask(task, closed_by): ## 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) + diff --git a/taskapp/events/user.py b/taskapp/events/user.py index dab0ff2..754cab0 100644 --- a/taskapp/events/user.py +++ b/taskapp/events/user.py @@ -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. diff --git a/taskapp/models.py b/taskapp/models.py index dea15e6..e6e1133 100644 --- a/taskapp/models.py +++ b/taskapp/models.py @@ -127,17 +127,6 @@ class Comment(models.Model): 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') diff --git a/taskapp/utilities/notification.py b/taskapp/utilities/notification.py index afa0faa..75c35db 100644 --- a/taskapp/utilities/notification.py +++ b/taskapp/utilities/notification.py @@ -102,13 +102,30 @@ def create_notification(role, sent_to, sent_from=None, reply=None, task=None, re 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): diff --git a/taskapp/views/task.py b/taskapp/views/task.py index d90e7cd..fb05bd5 100644 --- a/taskapp/views/task.py +++ b/taskapp/views/task.py @@ -3,7 +3,7 @@ from datetime import datetime 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 @@ def edit_task(request, tid): 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 @@ def close_task(request, tid): 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) |