From 6126d148bb0569cb185614437369535b43b4ca8e Mon Sep 17 00:00:00 2001 From: nishanth Date: Thu, 25 Feb 2010 20:13:59 +0530 Subject: added the functionality to view each notification --- taskapp/views/user.py | 43 +++++++++++++++++++++++++++++++++++ templates/user/view_notification.html | 10 ++++++++ urls.py | 2 ++ 3 files changed, 55 insertions(+) create mode 100644 templates/user/view_notification.html diff --git a/taskapp/views/user.py b/taskapp/views/user.py index 5dc686d..e1e3fbd 100644 --- a/taskapp/views/user.py +++ b/taskapp/views/user.py @@ -171,3 +171,46 @@ def browse_notifications(request): } return render_to_response('user/browse_notifications.html', context) + +@login_required +def view_notification(request, nid): + """ get the notification depending on nid. + Display it. + """ + + user = request.user + notifications = user.notification_to.filter(deleted=False).order_by('sent_date') + notification = notifications[int(nid)] + notification.is_read = True + notification.save() + + context = { + 'user':user, + 'notification':notification, + } + + return render_to_response('user/view_notification.html', context) + +@login_required +def edit_notification(request, nid, action): + """ if action is delete, set is_deleted. + if it is unread, unset is_read. + save the notification and redirect to browse_notifications. + """ + + user = request.user + notifications = user.notification_to.filter(deleted=False).order_by('sent_date') + notification = notifications[int(nid)] + notifications_url = "/user/notifications/" + + if request.method == "POST": + if action == "delete": + notification.deleted = True + elif action == "unread": + notification.is_read = False + + notification.save() + return redirect(notifications_url) + else: + return show_msg('This is wrong', notification_url, "view the notification") + diff --git a/templates/user/view_notification.html b/templates/user/view_notification.html new file mode 100644 index 0000000..f31eed9 --- /dev/null +++ b/templates/user/view_notification.html @@ -0,0 +1,10 @@ +{% extends 'base.html' %} +{% block content %} + Subject: {{notification.sub}}
+ Sent time: {{notification.sent_date}}
+ {% autoescape off %} + {{notification.message}} + {% endautoescape %} +
+
+{% endblock %} diff --git a/urls.py b/urls.py index 2a417ad..e46665f 100644 --- a/urls.py +++ b/urls.py @@ -50,5 +50,7 @@ urlpatterns = patterns('', (r'^user/requests/rid=(\d+)/(\w+)/$', userViews.process_request), (r'^user/notifications/$', userViews.browse_notifications), + (r'^user/notifications/nid=(\d+)/$', userViews.view_notification), + (r'^user/notifications/nid=(\d+)/(\w+)/$', userViews.edit_notification), ) -- cgit