# HG changeset patch # User Marcin Kuzminski # Date 2011-12-19 01:31:22 # Node ID 2aee0dc1784e9214765ea48b7aee8a956978777e # Parent f551007ce0857f004f4fd94cd552b1311d0e2769 mark all read button for notifications diff --git a/rhodecode/config/routing.py b/rhodecode/config/routing.py --- a/rhodecode/config/routing.py +++ b/rhodecode/config/routing.py @@ -26,7 +26,7 @@ def make_map(config): def check_repo(environ, match_dict): """ check for valid repository for proper 404 handling - + :param environ: :param match_dict: """ @@ -37,7 +37,7 @@ def make_map(config): def check_group(environ, match_dict): """ check for valid repositories group for proper 404 handling - + :param environ: :param match_dict: """ @@ -45,7 +45,6 @@ def make_map(config): return is_valid_repos_group(repos_group_name, config['base_path']) - def check_int(environ, match_dict): return match_dict.get('id').isdigit() @@ -274,7 +273,6 @@ def make_map(config): m.connect("admin_settings_create_repository", "/create_repository", action="create_repository", conditions=dict(method=["GET"])) - #NOTIFICATION REST ROUTES with rmap.submapper(path_prefix=ADMIN_PREFIX, controller='admin/notifications') as m: @@ -282,6 +280,8 @@ def make_map(config): action="create", conditions=dict(method=["POST"])) m.connect("notifications", "/notifications", action="index", conditions=dict(method=["GET"])) + m.connect("notifications_mark_all_read", "/notifications/mark_all_read", + action="mark_all_read", conditions=dict(method=["GET"])) m.connect("formatted_notifications", "/notifications.{format}", action="index", conditions=dict(method=["GET"])) m.connect("new_notification", "/notifications/new", diff --git a/rhodecode/controllers/admin/notifications.py b/rhodecode/controllers/admin/notifications.py --- a/rhodecode/controllers/admin/notifications.py +++ b/rhodecode/controllers/admin/notifications.py @@ -1,6 +1,7 @@ import logging import traceback +from pylons import request from pylons import tmpl_context as c, url from pylons.controllers.util import redirect @@ -15,6 +16,7 @@ from rhodecode.model.meta import Session log = logging.getLogger(__name__) + class NotificationsController(BaseController): """REST Controller styled on the Atom Publishing Protocol""" # To properly map this controller, ensure your config/routing.py @@ -27,7 +29,6 @@ class NotificationsController(BaseContro def __before__(self): super(NotificationsController, self).__before__() - def index(self, format='html'): """GET /_admin/notifications: All items in the collection""" # url('notifications') @@ -36,6 +37,16 @@ class NotificationsController(BaseContro .get_for_user(self.rhodecode_user.user_id) return render('admin/notifications/notifications.html') + def mark_all_read(self): + if request.environ.get('HTTP_X_PARTIAL_XHR'): + nm = NotificationModel() + # mark all read + nm.mark_all_read_for_user(self.rhodecode_user.user_id) + Session.commit() + c.user = self.rhodecode_user + c.notifications = nm.get_for_user(self.rhodecode_user.user_id) + return render('admin/notifications/notifications_data.html') + def create(self): """POST /_admin/notifications: Create a new item""" # url('notifications') diff --git a/rhodecode/model/notification.py b/rhodecode/model/notification.py --- a/rhodecode/model/notification.py +++ b/rhodecode/model/notification.py @@ -134,6 +134,12 @@ class NotificationModel(BaseModel): user = self.__get_user(user) return user.notifications + def mark_all_read_for_user(self, user): + user = self.__get_user(user) + UserNotification.query()\ + .filter(UserNotification.read==False)\ + .update({'read': True}) + def get_unread_cnt_for_user(self, user): user = self.__get_user(user) return UserNotification.query()\ diff --git a/rhodecode/templates/admin/notifications/notifications.html b/rhodecode/templates/admin/notifications/notifications.html --- a/rhodecode/templates/admin/notifications/notifications.html +++ b/rhodecode/templates/admin/notifications/notifications.html @@ -24,39 +24,22 @@ - % if c.notifications: - <% - unread = lambda n:{False:'unread'}.get(n) - %> -
-
- %for notification in c.notifications: -
- -
${h.literal(notification.notification.subject)}
-
- %endfor -
-
- %else: -
${_('No notifications here yet')}
- %endif +
+ ${_('Mark all read')} +
+
+ <%include file='notifications_data.html'/> +
diff --git a/rhodecode/templates/admin/notifications/notifications_data.html b/rhodecode/templates/admin/notifications/notifications_data.html new file mode 100644 --- /dev/null +++ b/rhodecode/templates/admin/notifications/notifications_data.html @@ -0,0 +1,28 @@ + +% if c.notifications: +<% +unread = lambda n:{False:'unread'}.get(n) +%> +
+
+ %for notification in c.notifications: +
+ +
${h.literal(notification.notification.subject)}
+
+ %endfor +
+
+%else: +
${_('No notifications here yet')}
+%endif \ No newline at end of file diff --git a/rhodecode/templates/base/base.html b/rhodecode/templates/base/base.html --- a/rhodecode/templates/base/base.html +++ b/rhodecode/templates/base/base.html @@ -53,7 +53,7 @@ ${h.link_to(c.rhodecode_user.username,h.url('admin_settings_my_account'),title='%s %s'%(c.rhodecode_user.name,c.rhodecode_user.lastname))}
- ${c.unread_notifications} + ${c.unread_notifications}
%endif