Changeset 4687 for waeup


Ignore:
Timestamp:
6 Jan 2010, 03:35:38 (15 years ago)
Author:
uli
Message:

Add missing facultycontainer pages.

File:
1 edited

Legend:

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

    r4679 r4687  
    1111from waeup.datacenter import Import
    1212from waeup.interfaces import (IUniversity, IWAeUPObject, IUserContainer,
    13                               IUserAccount, IFacultyContainer, IDataCenter)
     13                              IUserAccount, IFacultyContainer, IDataCenter,
     14                              IFaculty)
    1415from waeup.widgets.interfaces import ITableProvider
    1516from zope.app.security.interfaces import (IAuthentication,
    1617                                          IUnauthenticatedPrincipal,
    1718                                          ILogout)
    18 from zope.component import getUtility
     19from zope.component import getUtility, createObject
    1920from zope.exceptions import DuplicationError
    2021
     
    338339
    339340class FacultyContainerPage(WAeUPPage):
     341    """ Index page for faculty containers.
     342    """
    340343    grok.context(IFacultyContainer)
    341344    grok.name('index')
     
    357360            result.append(dict(id=key, name=val.title))
    358361        return result
     362
     363class AddFacultyFormPage(WAeUPAddFormPage):
     364    """ Page form to add a new faculty to a faculty container.
     365    """
     366    grok.context(IFacultyContainer)
     367    grok.require('waeup.manageUniversity')
     368    grok.name('add')
     369    form_fields = grok.AutoFields(IFaculty)
     370    label = 'Add a faculty'
     371    title = 'Add a faculty'
     372    pnav = 1
     373
     374    @grok.action('Add faculty')
     375    def addFaculty(self, **data):
     376        faculty = createObject(u'waeup.Faculty')
     377        self.applyData(faculty, **data)
     378        try:
     379            self.context.addFaculty(faculty)
     380        except DuplicationError:
     381            self.status = Invalid('The name chosen already exists '
     382                                  'in the database')
     383            return
     384        self.redirect(self.url(self.context))
     385
     386class ManageFacultyContainerPage(WAeUPPage):
     387    """ Manage Page
     388    """
     389    grok.context(IFacultyContainer)
     390    grok.require('waeup.manageUniversity')
     391    grok.template('facultycontainermanagepage')
     392    grok.name('manage')
     393    title = "Manage Faculties"
     394    pnav = 1
     395
     396    def update(self):
     397        form = self.request.form
     398        if 'CANCEL' in form.keys():
     399            self.redirect(self.url(self.context))
     400        if not 'DELETE' in form.keys():
     401            return
     402        fac_id = form['fac_id']
     403        if not isinstance(fac_id, list):
     404            fac_id = [fac_id]
     405        deleted = []
     406        for id in fac_id:
     407            try:
     408                del self.context[id]
     409                deleted.append(id)
     410            except:
     411                self.flash('Could not delete %s: %s: %s' % (
     412                        id, sys.exc_info()[0], sys.exc_info()[1]))
     413        if len(deleted):
     414            self.flash('Successfully deleted: %s' % ', '.join(deleted))
     415        # We have to redirect to let flash messages appear immediately...
     416        self.redirect(self.url())
     417        return
Note: See TracChangeset for help on using the changeset viewer.