implemented notification functionality for AD MG DV.
--- a/taskapp/events/request.py Sat Feb 27 17:20:22 2010 +0530
+++ b/taskapp/events/request.py Sat Feb 27 19:21:15 2010 +0530
@@ -1,4 +1,5 @@
from datetime import datetime
+from pytask.taskapp.models import Profile
from pytask.taskapp.events.task import addCredits, addMentor
from pytask.taskapp.events.user import changeRole
from pytask.taskapp.utilities.notification import create_notification
@@ -49,13 +50,36 @@
## tell the requested user that his request was rejected due to these reasons.
create_notification(request_obj.role, requested_by, replied_by, False, task, request_obj.remarks, requested_by)
- elif request_obj.role in ["AD", "MG", "DV"]:
+ elif request_obj.role == "DV":
+ if reply:
+ ## tell only the user who made him a DV
+ ## drop a welcome message to that fucker
+ changeRole(role=request_obj.role, user=request_obj.replied_by)
+ create_notification(request_obj.role, request_obj.sent_by, request_obj.replied_by, reply, requested_by=request_obj.sent_by)
+ else:
+ create_notification(request_obj.role, request_obj.sent_by, request_obj.replied_by, reply, remarks=request_obj.remarks, requested_by=request_obj.sent_by)
+
+ elif request_obj.role == "MG":
if reply:
- ## make him the role
- ## here we check for rights just in case to be fine with demoted users. we change only the user who made request has that rights.
+ ## tell all the MG and AD
+ ## drop a welcome message to that fucker
changeRole(role=request_obj.role, user=request_obj.replied_by)
+ alerting_users = Profile.objects.filter(user__is_active=True).exclude(rights="CT").exclude(rights="DV")
+ for a_profile in alerting_users:
+ create_notification(request_obj.role, a_profile.user, request_obj.replied_by, reply, requested_by=request_obj.sent_by)
else:
- ## notify request_obj.sent_by that it has been rejected
- pass
+ create_notification(request_obj.role, request_obj.sent_by, request_obj.replied_by, reply, remarks=request_obj.remarks, requested_by=request_obj.sent_by)
+
+ elif request_obj.role == "AD":
+ if reply:
+ ## tell all the AD
+ ## drop a welcome message to that fucker
+ changeRole(role=request_obj.role, user=request_obj.replied_by)
+ alerting_users = Profile.objects.filter(user__is_active=True).filter(rights="AD")
+ for a_profile in alerting_users:
+ create_notification(request_obj.role, a_profile.user, request_obj.replied_by, reply, requested_by=request_obj.sent_by)
+ else:
+ create_notification(request_obj.role, request_obj.sent_by, request_obj.replied_by, reply, remarks=request_obj.remarks, requested_by=request_obj.sent_by)
+
return True #Reply has been added successfully
return False #Already replied
--- a/taskapp/management/commands/seed_db.py Sat Feb 27 17:20:22 2010 +0530
+++ b/taskapp/management/commands/seed_db.py Sat Feb 27 19:21:15 2010 +0530
@@ -7,6 +7,8 @@
from pytask.taskapp.events import task as taskEvents
from pytask.taskapp.events import user as userEvents
+from pytask.taskapp.utilities.request import create_request
+
def seed_db():
""" a method to seed the database with random data """
@@ -15,14 +17,24 @@
mentor_profile = defaultMentor.get_profile()
userEvents.updateProfile(mentor_profile, {'rights':"AD"})
- for i in range(1,10):
+ for i in range(1,21):
username = 'user'+str(i)
email = username+'@example.com'
password = '123456'
dob = datetime.now()
gender = "M"
- userEvents.createUser(username,email,password,dob,gender)
+ user = userEvents.createUser(username,email,password,dob,gender)
+
+ if i%4==0:
+ create_request(defaultMentor, "MG", user)
+ elif i%3==0:
+ create_request(defaultMentor, "DV", user)
+ elif i%2==0:
+ create_request(defaultMentor, "AD", user)
+ elif i in ["7", "13"]:
+ user.is_active = False
+ user.save()
for i in range(1,21):
--- a/taskapp/utilities/notification.py Sat Feb 27 17:20:22 2010 +0530
+++ b/taskapp/utilities/notification.py Sat Feb 27 19:21:15 2010 +0530
@@ -1,6 +1,6 @@
from datetime import datetime
from django.contrib.auth.models import User
-from pytask.taskapp.models import Notification
+from pytask.taskapp.models import Notification, RIGHTS_CHOICES
def create_notification(role, sent_to, sent_from=None, reply=None, task=None, remarks=None, requested_by=None, receiving_user=None, pynts=None):
"""
@@ -68,6 +68,23 @@
if remarks:
notification.message += "Remarks: %s<br />"%remarks
+ elif role in ["DV", "MG", "AD"]:
+
+ accepting_user = sent_from
+ user_url = '<a href="/user/view/uid=%s">%s</a>'%(accepting_user.id,accepting_user.username) ## i mean the user who has accepted it
+ requested_by_url = '<a href="/user/view/uid=%s">%s</a>'%(requested_by.id,requested_by.username)
+ role_rights = dict(RIGHTS_CHOICES)[role]
+ role_learn_url = "/about/%s"%role_rights.lower()
+ a_or_an = "an" if role == "AD" else "a"
+
+ if reply:
+ notification.sub = "New %s for the site"%role_rights
+ notification.message = "%s has accepted request made by %s asking him to act as %s %s for the website.<br />"%(user_url, requested_by_url, a_or_an, role_rights)
+ else:
+ notification.sub = "Rejected your request to act as %s"%role_rights
+ notification.message = "%s has rejected your request asking him to act as %s %s for the website.<br />"%(user_url, a_or_an, role_rights)
+ if remarks:
+ notification.message += "Remarks: %s<br />"%remarks
elif role == "NT":
--- a/taskapp/utilities/request.py Sat Feb 27 17:20:22 2010 +0530
+++ b/taskapp/utilities/request.py Sat Feb 27 19:21:15 2010 +0530
@@ -6,7 +6,7 @@
def create_request(sent_by,role,sent_to=None,task=None,receiving_user=None,pynts=0):
"""
creates an unreplied request, based on the passed arguments
- sent_to - a list of users to which the notification is to be sent
+ sent_to - a list of users to which the request is to be sent
sent_by - sender of request
role - a two character field which represents the role requested, if role = 'PY' then sent to all admins
task - a requesting task (useful for sending admins a request to give Pynts to the user)