diff options
author | nishanth | 2010-02-26 18:34:30 +0530 |
---|---|---|
committer | nishanth | 2010-02-26 18:34:30 +0530 |
commit | d784c93b2fc7332d0e54e5a8039e0692f78d7a35 (patch) | |
tree | 4bd2dccc4856197c67bd8c073f114d4747911d76 /taskapp/utilities | |
parent | 92b98e2cc21315f4d13621744c8797803c4a3c34 (diff) | |
download | pytask-d784c93b2fc7332d0e54e5a8039e0692f78d7a35.tar.gz pytask-d784c93b2fc7332d0e54e5a8039e0692f78d7a35.tar.bz2 pytask-d784c93b2fc7332d0e54e5a8039e0692f78d7a35.zip |
now notification depends on id and not pos.
Diffstat (limited to 'taskapp/utilities')
-rw-r--r-- | taskapp/utilities/notification.py | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/taskapp/utilities/notification.py b/taskapp/utilities/notification.py index 5f72540..5d1d994 100644 --- a/taskapp/utilities/notification.py +++ b/taskapp/utilities/notification.py @@ -1,5 +1,6 @@ -from pytask.taskapp.models import Notification from datetime import datetime +from django.contrib.auth.models import User +from pytask.taskapp.models import Notification def create_notification(to,subject,message): """ @@ -10,7 +11,7 @@ def create_notification(to,subject,message): """ notification = Notification(sent_date = datetime.now()) notification.save() - notification.to = to + notification.sent_to = to notification.sub = subject notification.message = message notification.save() @@ -39,6 +40,24 @@ def delete_notification(notification_id): notification = Notification.objects.get(id = notification_id) except Notification.DoesNotExist: return False - notification.deleted = True + notification.is_deleted = True notification.save() return True + +def get_notification(nid, user): + """ if notification exists, and belongs to the current user, return it. + else return None. + """ + + try: + notify_obj = Notification.objects.get(id=nid) + except Notification.DoesNotExist: + return None + + try: + notify_obj.sent_to.get(id=user.id) + except User.DoesNotExist: + return None + + if not notify_obj.is_deleted: + return notify_obj |