Source

melange-mq / issue_460.patch

The default branch has multiple heads

Adds buttons to notifications list.

The buttons are Mark as read, Mark as unread and Delete buttons. Also adds
checkbox to each of the notification in the list. So once the user selects
a number of notifications using checkbox and clicks one of the options
the action performed as per the button clicked will be performed.

Fixes issue 450.

diff -r d76f3356ad7e app/soc/templates/soc/notification/list/heading.html
--- a/app/soc/templates/soc/notification/list/heading.html	Wed Nov 11 23:18:03 2009 +0530
+++ b/app/soc/templates/soc/notification/list/heading.html	Sun Nov 15 02:17:20 2009 +0530
@@ -1,4 +1,5 @@
 <tr align="left">
+  <th></th>
   <th>From</th>
   <th>Subject</th>
   <th>Received on</th>
diff -r d76f3356ad7e app/soc/templates/soc/notification/list/notification.html
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/templates/soc/notification/list/notification.html	Sun Nov 15 02:17:20 2009 +0530
@@ -0,0 +1,16 @@
+{% extends "soc/models/list.html" %}
+
+{% block body %}
+<form method="POST">
+<input style="font-weight: bold" type="submit" name="read"
+value="Mark as read"/></span>
+<input style="font-weight: bold" type="submit" name="unread"
+value="Mark as unread"/></span>
+<input style="font-weight: bold" type="submit" name="delete"
+value="Delete"/></span>
+{% if error_message %}
+<div class="error">{{ error_message|safe }}</div>
+{% endif %}
+{{ block.super }}
+</form>
+{% endblock %}
diff -r d76f3356ad7e app/soc/templates/soc/notification/list/row.html
--- a/app/soc/templates/soc/notification/list/row.html	Wed Nov 11 23:18:03 2009 +0530
+++ b/app/soc/templates/soc/notification/list/row.html	Sun Nov 15 02:17:20 2009 +0530
@@ -1,6 +1,10 @@
-<tr class="off" onmouseover="this.className='on'; do_redirect=true" onmouseout="this.className='off'"
-onclick="if (do_redirect) document.location.href='{{ list.redirect }}'" name="name">
-  <td align="right"><div class="name"><a class="noul" onclick="do_redirect=false"
+<tr class="off" onmouseover="this.className='on'; do_redirect=true"
+onmouseout="this.className='off'" name="name">
+  <td align="right><div class="select">
+    <input type="checkbox" value="{{list.item.key.name}}"
+    name="notification_key"/>
+  </div></td>
+  <td><div class="name"><a class="noul" onclick="do_redirect=false"
          href="{{ list.redirect }}">
          {% if list.item.from_user %}
            {{ list.item.from_user.name }}
diff -r d76f3356ad7e app/soc/views/models/notification.py
--- a/app/soc/views/models/notification.py	Wed Nov 11 23:18:03 2009 +0530
+++ b/app/soc/views/models/notification.py	Sun Nov 15 02:17:20 2009 +0530
@@ -24,7 +24,10 @@
 
 import time
 
+from google.appengine.ext import db
+
 from django import forms
+from django import http
 from django.utils.translation import ugettext
 
 from soc.logic import cleaning
@@ -100,6 +103,8 @@
 
     new_params['edit_redirect'] = '/%(url_name)s/list'
 
+    new_params['list_template'] = 'soc/notification/list/notification.html'
+
     params = dicts.merge(params, new_params)
 
     super(View, self).__init__(params=params)
@@ -107,12 +112,53 @@
   @decorators.merge_params
   @decorators.check_access
   def list(self, request, access_type,
-           page_name=None, params=None, filter=None, order=None, **kwargs):
+            page_name=None, params=None, filter=None, order=None, **kwargs):
     """Lists all notifications that the current logged in user has stored.
 
     for parameters see base.list()
     """
 
+    if request.method == 'POST':
+      return self.listPost(request, params, **kwargs)
+    else: # request.method == 'GET'
+      return self.listGet(request, page_name, params, **kwargs)
+
+  def listPost(self, request, params, **kwargs):
+    """Handles the POST request for the list of notifications.
+    """
+
+    post_dict = request.POST
+    notification_keys = post_dict.getlist('notification_key')
+
+    # if delete all the specified notifications
+    if post_dict.get('delete'):
+      db.delete([notification_logic.getFromKeyName(key_name) 
+                 for key_name in notification_keys])
+    else:
+      # determine the action
+      filter = {}
+      if post_dict.get('unread'):
+        filter['unread'] = True
+      elif post_dict.get('read'):
+        filter['unread'] = False
+
+      entities = []
+      # perform the action for each notification
+      for key_name in notification_keys:
+        entity = notification_logic.getFromKeyName(key_name)
+        entity = notification_logic.updateEntityProperties(
+            entity, filter, store=False)
+        entities.append(entity)
+
+      db.put(entities)
+
+    # redirect to the same page
+    return http.HttpResponseRedirect('')
+
+  def listGet(self, request, page_name=None, params=None, **kwargs):
+    """Handles the GET request for the list of notifications.
+    """
+
     # get the current user
     user_entity = user_logic.getForCurrentAccount()
 
@@ -211,4 +257,3 @@
 list = decorators.view(view.list)
 public = decorators.view(view.public)
 export = decorators.view(view.export)
-