changeset 2153:8e772d72ec6e

Merge with my devel branch.
author Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
date Mon, 18 Jun 2007 02:14:57 +0200
parents 3417a1d559d0 (current diff) cf4c4a3d6085 (diff)
children a8941968efa1
files
diffstat 5 files changed, 95 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/config/multiconfig.py	Mon Jun 18 00:48:31 2007 +0200
+++ b/MoinMoin/config/multiconfig.py	Mon Jun 18 02:14:57 2007 +0200
@@ -435,6 +435,7 @@
     siteid = 'default'
     stylesheets = [] # list of tuples (media, csshref) to insert after theme css, before user css
     subscribed_pages_default = [] # preload user subscribed pages with this page list
+    subscribed_events_default = [] # preload user subscribed events with this list
     superuser = [] # list of unicode user names that have super powers :)
     supplementation_page = False
     supplementation_page_name = u'Discussion'
--- a/MoinMoin/events/__init__.py	Mon Jun 18 00:48:31 2007 +0200
+++ b/MoinMoin/events/__init__.py	Mon Jun 18 02:14:57 2007 +0200
@@ -17,11 +17,14 @@
 # A list of available event handlers
 _event_handlers = None
 
+# A list of event types that user can subscribe to
+_subscribable_events = None
+
 # Create a list of extension actions from the package directory
 modules = pysupport.getPackageModules(__file__)
 
 
-class Event:
+class Event(object):
     """A class handling information common to all events."""
     def __init__(self, request):
         self.request = request
@@ -34,6 +37,10 @@
 
         
 class PageChangedEvent(PageEvent):
+    
+    description = u"""Page has been modified (edit, creation, deletion)"""
+    req_superuser = False
+    
     def __init__(self, request, page, comment, trivial):
         PageEvent.__init__(self, request)
         self.page = page
@@ -46,6 +53,10 @@
 
 
 class PageDeletedEvent(PageEvent):
+    
+    description = u"""Page has been deleted"""
+    req_superuser = False
+    
     def __init__(self, request, page, comment):
         PageEvent.__init__(self, request)
         self.request = request
@@ -54,6 +65,10 @@
 
 
 class FileAttachedEvent(PageEvent):
+    
+    description = u"""A new attachment has been added"""
+    req_superuser = False
+    
     def __init__(self, request, pagename, attachment_name, size):
         PageEvent.__init__(self, request)
         self.request = request
@@ -63,6 +78,10 @@
 
 
 class PageRevertedEvent(PageEvent):
+    
+    description = u"""A page has been reverted to a previous state"""
+    req_superuser = False
+    
     def __init__(self, request, pagename, previous, current):
         PageEvent.__init__(self, request)
         self.pagename = pagename
@@ -71,6 +90,10 @@
 
 
 class SubscribedToPageEvent(PageEvent):
+    
+    description = u"""An user has subscribed to a page"""
+    req_superuser = True
+    
     def __init__(self, request, pagename, username):
         PageEvent.__init__(self, request)    
         self.pagename = pagename
@@ -79,6 +102,7 @@
 
 class JabberIDSetEvent(Event):
     """ Sent when user changes her Jabber ID """
+    
     def __init__(self, request, jid):
         Event.__init__(self, request)
         self.jid = jid
@@ -88,6 +112,7 @@
     
     Obviously this will be usually sent along with JabberIDSetEvent,
     because we require user's jabber id to be unique by default.
+    
     """
     def __init__(self, request, jid):
         Event.__init__(self, request)
@@ -96,6 +121,9 @@
 class UserCreatedEvent(Event):
     """ Sent when a new user has been created """
     
+    description = u"""A new account has been created"""
+    req_superuser = True
+    
     def __init__(self, request, user):
         Event.__init__(self, request)
         self.user = user
@@ -140,3 +168,22 @@
             msg.append(retval)
             
     return msg
+
+def get_subscribable_events():
+    """Create and return a list of user-visible events
+    
+    @return: A list of user-visible events described by dictionaries
+    @rtype: dict
+    """
+    global _subscribable_events
+    defs = globals()
+    
+    if not _subscribable_events:
+        _subscribable_events = {}
+        
+        for ev in defs.values():
+            if type(ev) is type and issubclass(ev, Event) and ev.__dict__.has_key("description"):
+                _subscribable_events[ev.__name__] = {'desc': ev.description,
+                                                     'superuser': ev.req_superuser}
+    
+    return _subscribable_events
--- a/MoinMoin/user.py	Mon Jun 18 00:48:31 2007 +0200
+++ b/MoinMoin/user.py	Mon Jun 18 02:14:57 2007 +0200
@@ -315,6 +315,7 @@
         self.datetime_fmt = ""
         self.quicklinks = self._cfg.quicklinks_default
         self.subscribed_pages = self._cfg.subscribed_pages_default
+        self.subscribed_events = self._cfg.subscribed_events_default
         self.theme_name = self._cfg.theme_default
         self.editor_default = self._cfg.editor_default
         self.editor_ui = self._cfg.editor_ui
@@ -422,7 +423,7 @@
                         val = decodeDict(val)
                     # for compatibility reading old files, keep these explicit
                     # we will store them with [] appended
-                    elif key in ['quicklinks', 'subscribed_pages']:
+                    elif key in ['quicklinks', 'subscribed_pages', 'subscribed_events']:
                         val = decodeList(val)
                     user_data[key] = val
             except ValueError:
--- a/MoinMoin/userform.py	Mon Jun 18 00:48:31 2007 +0200
+++ b/MoinMoin/userform.py	Mon Jun 18 02:14:57 2007 +0200
@@ -330,6 +330,10 @@
 
         # subscription for page change notification
         theuser.subscribed_pages = self._decode_pagelist('subscribed_pages')
+        
+        # subscription to various events
+        available = events.get_subscribable_events()
+        theuser.subscribed_events = [ev for ev in form.get('events')]
 
         # save data
         theuser.save()
@@ -466,6 +470,24 @@
             options.append((theme, theme))
 
         return util.web.makeSelection('theme_name', options, cur_theme)
+    
+    def _event_select(self):
+        """ Create event subscription list. """
+        
+        event_list = events.get_subscribable_events()
+        selected = self.request.user.subscribed_events
+        super = self.request.user.isSuperUser()
+        
+        # Create a list of (value, name) tuples for display in <select>
+        # Only include super-user visible events if current user has these rights.
+        # It's cosmetic - the check for super-user rights should be performed
+        # in event handling code as well!
+        allowed = []
+        for key in event_list.keys():
+            if not event_list[key]['superuser'] or super:
+                allowed.append((key, event_list[key]['desc']))
+        
+        return util.web.makeMultiSelection('events', allowed, selectedvals=selected)
 
     def _editor_default_select(self):
         """ Create editor selection. """
@@ -599,6 +621,10 @@
                 html.TEXTAREA(name="quicklinks", rows="6", cols="50")
                     .append('\n'.join(self.request.user.getQuickLinks())),
             ], valign="top")
+            
+            # FIXME: this depends on Jabber ATM, but may not do so in the future
+            if self.cfg.jabber_enabled:
+                self.make_row(_('Subscribed events'), [self._event_select()])
 
             # subscribed pages
             if self.cfg.mail_enabled:
--- a/MoinMoin/util/web.py	Mon Jun 18 00:48:31 2007 +0200
+++ b/MoinMoin/util/web.py	Mon Jun 18 02:14:57 2007 +0200
@@ -44,6 +44,24 @@
 
     return result
 
+def makeMultiSelection(name, values, selectedvals=None, size=5):
+    """Make a HTML multiple <select> element with named `name` from a value list.
+    
+    The list can either be a list of strings, or a list of (value, label) tuples.
+    `selectedvals` is a list of values that should be pre-selected.
+    
+    """
+    from MoinMoin.widget import html
+    result = html.SELECT(name=name, size="%d" % int(size), multiple=True)
+    for val in values:
+        if not isinstance(val, type(())):
+            val = (val, val)
+        result.append(html.OPTION(
+            value=val[0], selected=(val[0] in selectedvals))
+            .append(html.Text(val[1]))
+        )
+    
+    return result
 
 class Color:
     """ RGB-Triple that automatically converts from and to