Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
MoinMoin.userprefs.notification.Settings Class Reference
Inheritance diagram for MoinMoin.userprefs.notification.Settings:
Inheritance graph
[legend]
Collaboration diagram for MoinMoin.userprefs.notification.Settings:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def handle_form
def create_form
def allowed
def handle_form
def make_form
def make_row

Public Attributes

 request
 cfg
 title
 name

Private Member Functions

def _decode_pagelist
def _save_notification_settings
def _event_select

Private Attributes

 _
 _form

Detailed Description

Definition at line 16 of file notification.py.


Constructor & Destructor Documentation

Initialize user settings form. 

Reimplemented from MoinMoin.userprefs.UserPrefBase.

Definition at line 17 of file notification.py.

00017 
00018     def __init__(self, request):
00019         """ Initialize user settings form. """
00020         UserPrefBase.__init__(self, request)
00021         self.request = request
00022         self._ = request.getText
00023         self.cfg = request.cfg
00024         self.title = self._("Notification")
00025         self.name = 'notification'


Member Function Documentation

def MoinMoin.userprefs.notification.Settings._decode_pagelist (   self,
  key 
) [private]
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

Definition at line 26 of file notification.py.

00026 
00027     def _decode_pagelist(self, key):
00028         """ Decode list of pages from form input
00029 
00030         Each line is a page name, empty lines ignored.
00031 
00032         @param key: the form key to get
00033         @rtype: list of unicode strings
00034         @return: list of normalized names
00035         """
00036         text = self.request.form.get(key, '')
00037         text = text.replace('\r', '')
00038         items = []
00039         for item in text.split('\n'):
00040             item = item.strip()
00041             if not item:
00042                 continue
00043             items.append(item)
00044         return items

Here is the caller graph for this function:

Create event subscription list. 

Definition at line 89 of file notification.py.

00089 
00090     def _event_select(self):
00091         """ Create event subscription list. """
00092         _ = self._
00093 
00094         types = []
00095         if self.cfg.mail_enabled and self.request.user.email:
00096             types.append(('email', _("'''Email'''", wiki=True)))
00097         if self.cfg.jabber_enabled and self.request.user.jid:
00098             types.append(('jabber', _("'''Jabber'''", wiki=True)))
00099 
00100         table = html.TABLE()
00101         header = html.TR()
00102         table.append(header)
00103         for name, descr in types:
00104             header.append(html.TH().append(html.Raw(descr)))
00105         header.append(html.TH(align='left').append(html.Raw(_("'''Event type'''", wiki=True))))
00106 
00107         event_list = events.get_subscribable_events()
00108         super = self.request.user.isSuperUser()
00109 
00110         # Create a list of (value, name) tuples for display as radiobuttons
00111         # Only include super-user visible events if current user has these rights.
00112         # It's cosmetic - the check for super-user rights should be performed
00113         # in event handling code as well!
00114         allowed = []
00115         for key in event_list.keys():
00116             if not event_list[key]['superuser'] or super:
00117                 allowed.append((key, event_list[key]['desc']))
00118 
00119         for evname, evdescr in allowed:
00120             tr = html.TR()
00121             table.append(tr)
00122             for notiftype, notifdescr in types:
00123                 checked = evname in getattr(self.request.user,
00124                                             '%s_subscribed_events' % notiftype)
00125                 tr.append(html.TD().append(html.INPUT(
00126                         type='checkbox',
00127                         checked=checked,
00128                         name='subscribe:%s:%s' % (notiftype, evname))))
00129             tr.append(html.TD().append(html.Raw(self.request.getText(evdescr))))
00130 
00131         return table

Definition at line 45 of file notification.py.

00045 
00046     def _save_notification_settings(self):
00047         _ = self._
00048         form = self.request.form
00049 
00050         if self.request.method != 'POST':
00051             return
00052         theuser = self.request.user
00053         if not theuser:
00054             return
00055 
00056         # subscription for page change notification
00057         theuser.subscribed_pages = self._decode_pagelist('subscribed_pages')
00058 
00059         # subscription to various events
00060         available = events.get_subscribable_events()
00061         theuser.email_subscribed_events = []
00062         theuser.jabber_subscribed_events = []
00063         types = {
00064             'email': theuser.email_subscribed_events,
00065             'jabber': theuser.jabber_subscribed_events
00066         }
00067         for tp in types:
00068             for evt in available:
00069                 fieldname = 'subscribe:%s:%s' % (tp, evt)
00070                 if fieldname in form:
00071                     types[tp].append(evt)
00072         # save data
00073         theuser.save()
00074 
00075         return 'info', _("Notification settings saved!")
00076 

Here is the call graph for this function:

Here is the caller graph for this function:

    Not all preferences are applicable to all users,
    this method is called to determine whether the
    title should be listed or not and whether
    submissions are accepted.

Reimplemented from MoinMoin.userprefs.UserPrefBase.

Definition at line 172 of file notification.py.

00172 
00173     def allowed(self):
00174         return UserPrefBase.allowed(self) and (
00175             self.cfg.mail_enabled or self.cfg.jabber_enabled)
Create the complete HTML form code. 

Reimplemented from MoinMoin.userprefs.UserPrefBase.

Definition at line 132 of file notification.py.

00132 
00133     def create_form(self):
00134         """ Create the complete HTML form code. """
00135         _ = self._
00136         self._form = self.make_form(
00137             _('Select the events you want to be notified about.'))
00138 
00139         self._form.append(html.INPUT(type="hidden", name="action", value="userprefs"))
00140         self._form.append(html.INPUT(type="hidden", name="handler", value="prefs"))
00141 
00142         if (not (self.cfg.mail_enabled and self.request.user.email)
00143             and not (self.cfg.jabber_enabled and self.request.user.jid)):
00144             self.make_row('', [html.Text(
00145                 _("Before you can be notified, you need to provide a way"
00146                   " to contact you in the general preferences."))])
00147             self.make_row('', [
00148                 html.INPUT(type="submit", name="cancel", value=_("Cancel"))])
00149             return unicode(self._form)
00150 
00151         self.make_row(_('Subscribed events'), [self._event_select()])
00152 
00153         # Get list of subscribe pages, DO NOT sort! it should
00154         # stay in the order the user entered it in his input
00155         # box.
00156         notifylist = self.request.user.getSubscriptionList()
00157 
00158         self.make_row(
00159             html.Raw(_('Subscribed wiki pages<<BR>>(one regex per line)', wiki=True)),
00160             [html.TEXTAREA(name="subscribed_pages", rows="6", cols="50").append(
00161                 '\n'.join(notifylist)), ],
00162             valign="top"
00163         )
00164 
00165         # Add buttons
00166         self.make_row('', [
00167             html.INPUT(type="submit", name="save", value=_("Save")),
00168             ' ',
00169             html.INPUT(type="submit", name="cancel", value=_("Cancel"))])
00170 
00171         return unicode(self._form)

def MoinMoin.userprefs.UserPrefBase.handle_form (   self,
  request 
) [inherited]
    When any of the created forms is submitted and the
    hidden fields are set correctly (see create_form)
    this method will be invoked to handle the user's
    input. Note that GET requests are also handed to
    this method, so if you require POST check that.

Definition at line 50 of file __init__.py.

00050 
00051     def handle_form(self, request):
00052         '''
00053             When any of the created forms is submitted and the
00054             hidden fields are set correctly (see create_form)
00055             this method will be invoked to handle the user's
00056             input. Note that GET requests are also handed to
00057             this method, so if you require POST check that.
00058         '''
00059         raise NotImplementedError

Definition at line 77 of file notification.py.

00077 
00078     def handle_form(self):
00079         _ = self._
00080         form = self.request.form
00081 
00082         if form.has_key('cancel'):
00083             return
00084 
00085         if form.has_key('save'): # Save user profile
00086             return self._save_notification_settings()

Here is the call graph for this function:

def MoinMoin.userprefs.UserPrefBase.make_form (   self,
  explanation = None 
) [inherited]
    To have a consistent UI, use this method for most
    preferences forms and then call make_row(). See
    existing plugins, e.g. changepass.py.

Definition at line 69 of file __init__.py.

00069 
00070     def make_form(self, explanation=None):
00071         '''
00072             To have a consistent UI, use this method for most
00073             preferences forms and then call make_row(). See
00074             existing plugins, e.g. changepass.py.
00075         '''
00076         action = self.request.page.url(self.request)
00077         _form = html.FORM(action=action)
00078         _form.append(html.INPUT(type="hidden", name="action", value="userprefs"))
00079         _form.append(html.INPUT(type="hidden", name="handler", value=self.name))
00080 
00081         self._table = html.TABLE(border="0")
00082 
00083         # Use the user interface language and direction
00084         lang_attr = self.request.theme.ui_lang_attr()
00085         _form.append(html.Raw('<div class="userpref"%s>' % lang_attr))
00086         para = html.P()
00087         _form.append(para)
00088         if explanation:
00089             para.append(explanation)
00090 
00091         para.append(self._table)
00092         _form.append(html.Raw("</div>"))
00093 
00094         return _form

Here is the caller graph for this function:

def MoinMoin.userprefs.UserPrefBase.make_row (   self,
  label,
  cell,
  kw 
) [inherited]
   Create a row in the form table.

Definition at line 95 of file __init__.py.

00095 
00096     def make_row(self, label, cell, **kw):
00097         '''
00098            Create a row in the form table.
00099         '''
00100         self._table.append(html.TR().extend([
00101             html.TD(**kw).extend([html.B().append(label), '   ']),
00102             html.TD().extend(cell),
00103         ]))

Here is the caller graph for this function:


Member Data Documentation

Reimplemented from MoinMoin.userprefs.UserPrefBase.

Definition at line 21 of file notification.py.

Definition at line 135 of file notification.py.

Definition at line 22 of file notification.py.

Reimplemented from MoinMoin.userprefs.UserPrefBase.

Definition at line 24 of file notification.py.

Reimplemented from MoinMoin.userprefs.UserPrefBase.

Definition at line 20 of file notification.py.

Reimplemented from MoinMoin.userprefs.UserPrefBase.

Definition at line 23 of file notification.py.


The documentation for this class was generated from the following file: