Changeset 4113 for waeup


Ignore:
Timestamp:
6 May 2009, 07:22:44 (16 years ago)
Author:
uli
Message:

Make user accounts addable.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • waeup/branches/ulif-rewrite/src/waeup/users.py

    r4111 r4113  
    33import grok
    44from hurry import yui
     5from zope.exceptions import DuplicationError
    56from waeup.authentication import Account
    67from waeup.interfaces import IUserContainer, IUserAccount
    7 from waeup.viewlets import LeftSidebar, MainArea, Index, Manage, FormWrapMixin
     8from waeup.viewlets import LeftSidebar, MainArea, Index, Add, FormWrapMixin
    89
    910class UserContainer(grok.Container):
     
    4344    def render(self, *args, **kw):
    4445        return super(UserContainerView, self).render(*args, **kw)
    45    
     46
     47class AddUserForm(grok.AddForm):
     48    grok.require('waeup.manageUsers')
     49    grok.context(UserContainer)
     50    form_fields = grok.AutoFields(IUserAccount)
     51    label = 'Add user'
     52
     53    @grok.action('Add user')
     54    def addFaculty(self, **data):
     55        #user = Account(**data)
     56        name = data['name']
     57        title = data['title']
     58        description = data['description']
     59        password = data['password']
     60        try:
     61            self.context.addUser(name, password, title=title,
     62                                 description=description)
     63        except DuplicationError:
     64            self.status = Invalid('The userid chosen already exists '
     65                                  'in the database')
     66            return
     67        self.redirect(self.url(self.context))
     68
     69class AddUser(FormWrapMixin, grok.Viewlet):
     70    """A viewlet that wraps the `AddUserForm`.
     71    """
     72    grok.viewletmanager(MainArea)
     73    grok.context(UserContainer)
     74    grok.view(Add)
     75    grok.require('waeup.manageUsers')
     76
     77    formview_name = 'adduserform' # The name of the formview we want
     78                                  # to be rendered in this viewlet.
     79
    4680class UserContainerMain(grok.Viewlet):
    4781    grok.require('waeup.manageUsers')
Note: See TracChangeset for help on using the changeset viewer.