Changeset 6916


Ignore:
Timestamp:
21 Oct 2011, 08:01:14 (13 years ago)
Author:
Henrik Bettermann
Message:

Implement SessionConfiguration?, SessionConfigurationAddFormPage?, SessionConfigurationFactory? (work in progress).

Location:
main/waeup.sirp/trunk/src/waeup/sirp
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/pages.py

    r6908 r6916  
    3434    IWAeUPObject, IUserContainer, IUserAccount, IDataCenter,
    3535    IWAeUPXMLImporter, IWAeUPXMLExporter, IBatchProcessor,
    36     ILocalRolesAssignable, DuplicationError, IConfigurationContainer)
     36    ILocalRolesAssignable, DuplicationError, IConfigurationContainer,
     37    ISessionConfiguration, ISessionConfigurationAdd, academic_sessions_vocab)
    3738from waeup.sirp.permissions import get_users_with_local_roles, getRoles
    3839from waeup.sirp.university.catalog import search
     
    417418    form_fields['frontpage'].custom_widget = ReSTDisplayWidget
    418419
    419     #def renderFrontpage(self):
    420     #    self.setUpWidgets()
    421     #    return widgets['frontpage']
    422 
    423420class ConfigurationContainerManageFormPage(WAeUPEditFormPage):
    424     """Manage page of the configuration container.
     421    """Manage page of the configuration container. We always use the
     422    manage page in the UI not the view page, thus we use the index name here.
    425423    """
    426424    grok.require('waeup.managePortalConfiguration')
    427425    grok.name('index')
    428426    grok.context(IConfigurationContainer)
     427    grok.template('configurationmanagepage')
    429428    pnav = 0
    430429    label = u'Edit portal configuration'
    431430    title = u'Portal Configuration'
     431    taboneactions = ['Save', 'Update plugins']
     432    tabtwoactions = [
     433        'Add session configuration',
     434        'Remove selected sesson configurations']
    432435
    433436    form_fields = grok.AutoFields(IConfigurationContainer)
     437
     438    def update(self):
     439        tabs.need()
     440        datatable.need()
     441        return super(ConfigurationContainerManageFormPage, self).update()
    434442
    435443    @grok.action('Save')
     
    439447        return
    440448
     449    @grok.action('Add session configuration', validator=NullValidator)
     450    def addSubunit(self, **data):
     451        self.redirect(self.url(self.context, '@@add'))
     452        return
     453
     454    def getSessionConfigurations(self):
     455        """Get a list of all stored session configuration objects.
     456        """
     457        for key, val in self.context.items():
     458            url = self.url(val)
     459            session_string = academic_sessions_vocab.getTermByToken(key).title
     460            title = 'Session %s Configuration Data' % session_string
     461            yield(dict(url=url, name=key, title=title))
     462
     463    # ToDo: Show warning message before deletion
     464    @grok.action('Remove selected sesson configurations')
     465    def delSubobjects(self, **data):
     466        form = self.request.form
     467        if form.has_key('val_id'):
     468            child_id = form['val_id']
     469        else:
     470            self.flash('No item selected.')
     471            self.redirect(self.url(self.context, '@@index')+'#tab-2')
     472            return
     473        if not isinstance(child_id, list):
     474            child_id = [child_id]
     475        deleted = []
     476        for id in child_id:
     477            try:
     478                del self.context[id]
     479                deleted.append(id)
     480            except:
     481                self.flash('Could not delete %s: %s: %s' % (
     482                        id, sys.exc_info()[0], sys.exc_info()[1]))
     483        if len(deleted):
     484            self.flash('Successfully removed: %s' % ', '.join(deleted))
     485        self.redirect(self.url(self.context, '@@index')+'#tab-2')
     486        return
     487
    441488    @grok.action('Update plugins', validator=NullValidator)
    442489    def updatePlugins(self, **data):
     
    445492        return
    446493
     494class SessionConfigurationAddFormPage(WAeUPAddFormPage):
     495    """Add a session configuration object to configuration container.
     496    """
     497    grok.context(IConfigurationContainer)
     498    grok.name('add')
     499    grok.require('waeup.managePortalConfiguration')
     500    label = 'Add session configuration'
     501    title = 'Configuration'
     502    form_fields = grok.AutoFields(ISessionConfigurationAdd)
     503    pnav = 0
     504
     505    @grok.action('Add Session Configuration')
     506    def addSessionConfiguration(self, **data):
     507        sessionconfiguration = createObject(u'waeup.SessionConfiguration')
     508        self.applyData(sessionconfiguration, **data)
     509        try:
     510            self.context.addSessionConfiguration(sessionconfiguration)
     511        except KeyError:
     512            self.flash('The session chosen already exists ')
     513            return
     514        self.redirect(self.url(self.context, '@@index')+'#tab-2')
     515        return
     516
     517    @grok.action('Cancel', validator=NullValidator)
     518    def cancel(self):
     519        self.redirect(self.url(self.context, '@@index')+'#tab-2')
     520        return
    447521
    448522#
  • main/waeup.sirp/trunk/src/waeup/sirp/configuration.py

    r6907 r6916  
    1818"""
    1919import grok
     20from zope.component.interfaces import IFactory
    2021from waeup.sirp.interfaces import (
    21     ISessionConfiguration, IConfigurationContainer)
     22    ISessionConfiguration, IConfigurationContainer, ISessionConfigurationAdd)
    2223from waeup.sirp.utils.helpers import attrs_to_fields
    2324
     
    3435        if not ISessionConfiguration.providedBy(sessionconfiguration):
    3536            raise TypeError(
    36                 'StudentsContainers contain only IStudent instances')
    37         self[sessionconfiguration.year] = sessionconfiguration
     37                'ConfigurationContainers contain only ISessionConfiguration instances')
     38        code = unicode(sessionconfiguration.academic_session)
     39        self[code] = sessionconfiguration
    3840        return
    3941
    4042ConfigurationContainer = attrs_to_fields(ConfigurationContainer)
     43
     44class SessionConfiguration(grok.Model):
     45    """
     46    Session configuration model
     47    """
     48
     49    grok.implements(ISessionConfiguration, ISessionConfigurationAdd)
     50
     51SessionConfiguration = attrs_to_fields(SessionConfiguration)
     52
     53class SessionConfigurationFactory(grok.GlobalUtility):
     54    """A factory for session configuration objects.
     55    """
     56    grok.implements(IFactory)
     57    grok.name(u'waeup.SessionConfiguration')
     58    title = u"Create a new session configuration object.",
     59    description = u"This factory instantiates new session configurations."
     60
     61    def __call__(self, *args, **kw):
     62        return SessionConfiguration(*args, **kw)
     63
     64    def getInterfaces(self):
     65        return implementedBy(SessionConfiguration)
  • main/waeup.sirp/trunk/src/waeup/sirp/interfaces.py

    r6915 r6916  
    244244        )
    245245
     246    fee_2 = schema.Int(
     247        title = u'Surcharge',
     248        default = 0,
     249        )
     250
     251class ISessionConfigurationAdd(ISessionConfiguration):
     252    """A session configuration object in add mode.
     253    """
     254
     255    academic_session = schema.Choice(
     256        title = u'Academic Session',
     257        source = academic_sessions_vocab,
     258        default = None,
     259        required = True,
     260        readonly = False,
     261        )
     262
     263ISessionConfigurationAdd['academic_session'].order =  ISessionConfiguration[
     264    'academic_session'].order
     265
    246266class IDataCenter(IWAeUPObject):
    247267    """A data center.
Note: See TracChangeset for help on using the changeset viewer.