changeset 2432:81afe010284f

merged main
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 20 Jul 2007 03:47:04 +0200
parents 58260d360f5c (current diff) c7bb078d3318 (diff)
children 738c0c3d001c
files MoinMoin/config/multiconfig.py
diffstat 3 files changed, 194 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/config/multiconfig.py	Fri Jul 20 03:46:38 2007 +0200
+++ b/MoinMoin/config/multiconfig.py	Fri Jul 20 03:47:04 2007 +0200
@@ -15,6 +15,9 @@
 from MoinMoin import config, error, util, wikiutil
 import MoinMoin.auth as authmodule
 import MoinMoin.events as events
+from MoinMoin.events import PageChangedEvent, PageRenamedEvent
+from MoinMoin.events import PageDeletedEvent, PageCopiedEvent
+from MoinMoin.events import PageRevertedEvent, FileAttachedEvent
 from MoinMoin import session
 from MoinMoin.packages import packLine
 from MoinMoin.security import AccessControlList
@@ -205,9 +208,6 @@
 class DefaultConfig:
     """ default config values """
 
-    # internal dict for plugin `modules' lists
-    _site_plugin_lists = {}
-
     # setting DesktopEdition = True gives all local users special powers - ONLY use for MMDE style usage!
     DesktopEdition = False
 
@@ -497,7 +497,15 @@
     stylesheets = [] # list of tuples (media, csshref) to insert after theme css, before user css
     _subscribable_events = None # A list of event types that user can subscribe to
     subscribed_pages_default = [] # preload user subscribed pages with this page list
-    subscribed_events_default = [] # preload user subscribed events with this list
+    email_subscribed_events_default = [
+        PageChangedEvent.__name__,
+        PageRenamedEvent.__name__,
+        PageDeletedEvent.__name__,
+        PageCopiedEvent.__name__,
+        PageRevertedEvent.__name__,
+        FileAttachedEvent.__name__,
+    ]
+    jabber_subscribed_events_default = []
     superuser = [] # list of unicode user names that have super powers :)
     supplementation_page = False
     supplementation_page_name = u'Discussion'
@@ -597,11 +605,10 @@
                               'show_fancy_diff':     1,
                               'wikiname_add_spaces': 0,
                               'remember_me':         1,
-                              'want_trivial':        0,
                              }
 
     # don't let the user change those
-    # user_checkbox_disable = ['disabled', 'want_trivial']
+    # user_checkbox_disable = ['disabled']
     user_checkbox_disable = []
 
     # remove those checkboxes:
@@ -715,6 +722,10 @@
                 self.chart_options = None
 
         # post process
+
+        # internal dict for plugin `modules' lists
+        self._site_plugin_lists = {}
+
         # we replace any string placeholders with config values
         # e.g u'%(page_front_page)s' % self
         self.navi_bar = [elem % self for elem in self.navi_bar]
--- a/MoinMoin/user.py	Fri Jul 20 03:46:38 2007 +0200
+++ b/MoinMoin/user.py	Fri Jul 20 03:47:04 2007 +0200
@@ -329,8 +329,8 @@
         self.datetime_fmt = ""
         self.quicklinks = self._cfg.quicklinks_default
         self.subscribed_pages = self._cfg.subscribed_pages_default
-        self.email_subscribed_events = self._cfg.subscribed_events_default
-        self.jabber_subscribed_events = []
+        self.email_subscribed_events = self._cfg.email_subscribed_events_default
+        self.jabber_subscribed_events = self._cfg.jabber_subscribed_events_default
         self.theme_name = self._cfg.theme_default
         self.editor_default = self._cfg.editor_default
         self.editor_ui = self._cfg.editor_ui
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/userprefs/notification.py	Fri Jul 20 03:47:04 2007 +0200
@@ -0,0 +1,175 @@
+# -*- coding: iso-8859-1 -*-
+"""
+    MoinMoin - Notification preferences
+
+    @copyright: 2001-2004 Juergen Hermann <jh@web.de>,
+                2003-2007 MoinMoin:ThomasWaldmann
+                2007      MoinMoin:JohannesBerg
+    @license: GNU GPL, see COPYING for details.
+"""
+
+import time
+from MoinMoin import user, util, wikiutil, events
+from MoinMoin.widget import html
+from MoinMoin.userprefs import UserPrefBase
+
+
+class Settings(UserPrefBase):
+    def __init__(self, request):
+        """ Initialize user settings form. """
+        UserPrefBase.__init__(self, request)
+        self.request = request
+        self._ = request.getText
+        self.cfg = request.cfg
+        self.title = self._("Notification")
+        self.name = 'notification'
+
+    def _decode_pagelist(self, key):
+        """ Decode list of pages from form input
+
+        Each line is a page name, empty lines ignored.
+
+        @param key: the form key to get
+        @rtype: list of unicode strings
+        @return: list of normalized names
+        """
+        text = self.request.form.get(key, [''])[0]
+        text = text.replace('\r', '')
+        items = []
+        for item in text.split('\n'):
+            item = item.strip()
+            if not item:
+                continue
+            items.append(item)
+        return items
+
+    def _save_notification_settings(self):
+        _ = self._
+        form = self.request.form
+
+        if self.request.request_method != 'POST':
+            return
+        theuser = self.request.user
+        if not theuser:
+            return
+
+        # subscription for page change notification
+        theuser.subscribed_pages = self._decode_pagelist('subscribed_pages')
+
+        # subscription to various events
+        available = events.get_subscribable_events()
+        theuser.email_subscribed_events = []
+        theuser.jabber_subscribed_events = []
+        types = {
+            'email': theuser.email_subscribed_events,
+            'jabber': theuser.jabber_subscribed_events
+        }
+        for tp in types:
+            for evt in available:
+                fieldname = 'subscribe:%s:%s' % (tp, evt)
+                if fieldname in form:
+                    types[tp].append(evt)
+        # save data
+        theuser.save()
+
+        return _("Notification settings saved!")
+
+
+    def handle_form(self):
+        _ = self._
+        form = self.request.form
+
+        if form.has_key('cancel'):
+            return
+
+        if form.has_key('save'): # Save user profile
+            return self._save_notification_settings()
+
+    # form generation part
+
+    def _event_select(self):
+        """ Create event subscription list. """
+        _ = self._
+
+        types = []
+        if self.cfg.mail_enabled and self.request.user.email:
+            types.append(('email', _("'''Email'''")))
+        if self.cfg.jabber_enabled and self.request.user.jid:
+            types.append(('jabber', _("'''Jabber'''")))
+
+        table = html.TABLE()
+        header = html.TR()
+        table.append(header)
+        for name, descr in types:
+            header.append(html.TH().append(html.Raw(descr)))
+        header.append(html.TH(align='left').append(html.Raw(_("'''Event type'''"))))
+
+        event_list = events.get_subscribable_events()
+        super = self.request.user.isSuperUser()
+
+        # Create a list of (value, name) tuples for display as radiobuttons
+        # 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']))
+
+        for evname, evdescr in allowed:
+            tr = html.TR()
+            table.append(tr)
+            for notiftype, notifdescr in types:
+                checked = evname in getattr(self.request.user,
+                                            '%s_subscribed_events' % notiftype)
+                tr.append(html.TD().append(html.INPUT(
+                        type='checkbox',
+                        checked=checked,
+                        name='subscribe:%s:%s' % (notiftype, evname))))
+            tr.append(html.TD().append(html.Raw(self.request.getText(evdescr))))
+
+        return table
+
+    def create_form(self):
+        """ Create the complete HTML form code. """
+        _ = self._
+        self._form = self.make_form(
+            _('Select the events you want to be notified about.'))
+
+        self._form.append(html.INPUT(type="hidden", name="action", value="userprefs"))
+        self._form.append(html.INPUT(type="hidden", name="handler", value="prefs"))
+
+        if (not (self.cfg.mail_enabled and self.request.user.email)
+            and not (self.cfg.jabber_enabled and self.request.user.jid)):
+            self.make_row('', [html.Text(
+                _("Before you can be notified, you need to provide a way"
+                  " to contact you in the general preferences."))])
+            self.make_row('', [
+                html.INPUT(type="submit", name="cancel", value=_("Cancel"))])
+            return unicode(self._form)
+
+        self.make_row(_('Subscribed events'), [self._event_select()])
+
+        # Get list of subscribe pages, DO NOT sort! it should
+        # stay in the order the user entered it in his input
+        # box.
+        notifylist = self.request.user.getSubscriptionList()
+
+        self.make_row(
+            html.Raw(_('Subscribed wiki pages[[BR]](one regex per line)')),
+            [html.TEXTAREA(name="subscribed_pages", rows="6", cols="50").append(
+                '\n'.join(notifylist)), ],
+            valign="top"
+        )
+
+        # Add buttons
+        self.make_row('', [
+            html.INPUT(type="submit", name="save", value=_("Save")),
+            ' ',
+            html.INPUT(type="submit", name="cancel", value=_("Cancel"))])
+
+        return unicode(self._form)
+
+    def allowed(self):
+        return UserPrefBase.allowed(self) and (
+            self.cfg.mail_enabled or self.cfg.jabber_enabled)