Back to index

moin  1.9.0~rc2
__init__.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003     MoinMoin - User preferences implementation
00004 
00005     See also MoinMoin/action/userprefs.py
00006 
00007     @copyright: 2007 MoinMoin:Johannesberg
00008     @license: GNU GPL, see COPYING for details.
00009 """
00010 from MoinMoin.util import pysupport
00011 from MoinMoin.widget import html
00012 
00013 
00014 # create a list of extension actions from the package directory
00015 modules = pysupport.getPackageModules(__file__)
00016 
00017 
00018 class UserPrefBase(object):
00019     '''
00020         Base class for Settings objects
00021 
00022         To get a new page in the wiki settings, create
00023         a new 'userprefs' plugin and in it declare a class
00024         named 'Settings' that inherits from this class.
00025     '''
00026     def __init__(self, request):
00027         '''
00028             Initialise a settings object. This should set the
00029             object's title (which is displayed in the list of
00030             possible settings)
00031         '''
00032         self.request = request
00033         self._ = request.getText
00034         self.name = None
00035         self.title = 'No name set'
00036 
00037     def create_form(self):
00038         '''
00039             This method should return HTML code for at least
00040             one form. Each created form *must* contain the
00041             hidden fields
00042               * action: set to "userprefs"
00043               * handler: set to the plugin name
00044             It can additionally contain the hidden field
00045             'sub' set to the plugin name if the plugin needs
00046             multiple forms (wizard-like.)
00047         '''
00048         raise NotImplementedError
00049 
00050     def handle_form(self, request):
00051         '''
00052             When any of the created forms is submitted and the
00053             hidden fields are set correctly (see create_form)
00054             this method will be invoked to handle the user's
00055             input. Note that GET requests are also handed to
00056             this method, so if you require POST check that.
00057         '''
00058         raise NotImplementedError
00059 
00060     def allowed(self):
00061         '''
00062             Not all preferences are applicable to all users,
00063             this method is called to determine whether the
00064             title should be listed or not and whether
00065             submissions are accepted.
00066         '''
00067         return self.request.user and self.request.user.valid
00068 
00069     def make_form(self, explanation=None):
00070         '''
00071             To have a consistent UI, use this method for most
00072             preferences forms and then call make_row(). See
00073             existing plugins, e.g. changepass.py.
00074         '''
00075         action = self.request.page.url(self.request)
00076         _form = html.FORM(action=action)
00077         _form.append(html.INPUT(type="hidden", name="action", value="userprefs"))
00078         _form.append(html.INPUT(type="hidden", name="handler", value=self.name))
00079 
00080         self._table = html.TABLE(border="0")
00081 
00082         # Use the user interface language and direction
00083         lang_attr = self.request.theme.ui_lang_attr()
00084         _form.append(html.Raw('<div class="userpref"%s>' % lang_attr))
00085         para = html.P()
00086         _form.append(para)
00087         if explanation:
00088             para.append(explanation)
00089 
00090         para.append(self._table)
00091         _form.append(html.Raw("</div>"))
00092 
00093         return _form
00094 
00095     def make_row(self, label, cell, **kw):
00096         '''
00097            Create a row in the form table.
00098         '''
00099         self._table.append(html.TR().extend([
00100             html.TD(**kw).extend([html.B().append(label), '   ']),
00101             html.TD().extend(cell),
00102         ]))