Changeset 4633 for waeup


Ignore:
Timestamp:
2 Jan 2010, 14:30:33 (15 years ago)
Author:
uli
Message:

Add form for adding user accounts to user containers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • waeup/branches/ulif-layout/src/waeup/browser/pages.py

    r4632 r4633  
    33"""
    44import grok
    5 from waeup.browser import WAeUPPage, WAeUPEditFormPage
     5from waeup.browser import WAeUPPage, WAeUPEditFormPage, WAeUPAddFormPage
    66from waeup.interfaces import (IUniversity, IWAeUPObject, IUserContainer,
    77                              IUserAccount)
     
    129129            self.flash('User %s successfully deleted.' % userid)
    130130
     131class AddUserFormPage(WAeUPAddFormPage):
     132    grok.require('waeup.manageUsers')
     133    grok.context(IUserContainer)
     134    grok.name('add')
     135    form_fields = grok.AutoFields(IUserAccount)
     136    label = 'Add user'
     137    title = 'Add user'
     138
     139    @grok.action('Add user')
     140    def addUser(self, **data):
     141        name = data['name']
     142        title = data['title']
     143        description = data['description']
     144        password = data['password']
     145        roles = data['roles']
     146        try:
     147            self.context.addUser(name, password, title=title,
     148                                 description=description, roles=roles)
     149        except DuplicationError:
     150            self.status = Invalid('The userid chosen already exists '
     151                                  'in the database')
     152            return
     153        self.redirect(self.url(self.context))
     154
    131155class UserEditFormPage(WAeUPEditFormPage):
    132156    """Edit a user account.
Note: See TracChangeset for help on using the changeset viewer.