Changeset 4755 for waeup/branches


Ignore:
Timestamp:
9 Jan 2010, 11:14:06 (17 years ago)
Author:
uli
Message:
  • Let certificate code field be editable on certificate add-forms only.
  • Let certificate update() methods handle workflow problems.
File:
1 edited

Legend:

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

    r4735 r4755  
    99from hurry.query import Eq
    1010from hurry.query.query import Query, Text
     11from hurry.workflow.interfaces import NoTransitionAvailableError
    1112from waeup.browser import (WAeUPPage, WAeUPEditFormPage, WAeUPAddFormPage,
    1213                           WAeUPDisplayFormPage)
    … …  
    1920from waeup.widgets.interfaces import ITableProvider
    2021from waeup.utils.helpers import getName
     22from zope import schema
    2123from zope.app.security.interfaces import (IAuthentication,
    2224                                          IUnauthenticatedPrincipal,
    … …  
    585587    title = u'Add certificate'
    586588    pnav = 1
    587    
    588     # We need a deepcopy here, because otherwise also all other
    589     # ICertificate forms would be affected.
    590     form_fields = copy.deepcopy(grok.AutoFields(ICertificate))
    591     form_fields.get('code').field.readonly = False
    592 
     589    form_fields = grok.AutoFields(ICertificate)
     590   
    593591    @grok.action('Add certificate')
    594592    def addCertificate(self, **data):
    595593        certificate = createObject(u'waeup.Certificate')
    596         self.applyData(certificate, **data)
     594        try:
     595            self.applyData(certificate, **data)
     596        except NoTransitionAvailableError:
     597            self.status = Invalid('Review state cannot be changed to '
     598                                  'requested state: no such transition '
     599                                  'available in workflow.')
     600            return
    597601        try:
    598602            self.context.certificates.addCertificate(certificate)
    … …  
    604608
    605609    @grok.action('Cancel')
    606     def cancel(self, **data):
     610    def cancel(self): #, **data):
    607611        self.redirect(self.url(self.context))
    608612        return
    … …  
    717721    grok.name('manage')
    718722    grok.require('waeup.manageUniversity')
    719     form_fields = grok.AutoFields(ICertificate)
     723    # We omit 'code' field from original schema and set prepend a new
     724    # one with 'readonly' set to True.
     725    form_fields = grok.Fields(
     726        code = schema.TextLine(
     727            title = u'Code', readonly=True
     728            )
     729        ) + grok.AutoFields(ICertificate).omit('code')
    720730    pnav = 1
    721731
    … …  
    727737    @grok.action('Save')
    728738    def save(self, **data):
    729         self.applyData(self.context, **data)
     739        try:
     740            self.applyData(self.context, **data)
     741        except NoTransitionAvailableError:
     742            self.status = Invalid('Review state cannot be changed to '
     743                                  'requested state: no such transition '
     744                                  'available in workflow.')
    730745        return
    731746   
    732747    @grok.action('Save and return')
    733748    def saveAndReturn(self, **data):
    734         self.applyData(self.context, **data)
     749        try:
     750            self.applyData(self.context, **data)
     751        except NoTransitionAvailableError:
     752            self.status = Invalid('Review state cannot be changed to '
     753                                  'requested state: no such transition '
     754                                  'available in workflow.')
     755            return
    735756        self.redirect(self.url(self.context))
    736757        return
Note: See TracChangeset for help on using the changeset viewer.