Changeset 6228


Ignore:
Timestamp:
29 May 2011, 23:25:13 (14 years ago)
Author:
uli
Message:

Handle DuplicationError? from addCertificate() properly.

File:
1 edited

Legend:

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

    r6216 r6228  
    1616from zope.authentication.interfaces import (
    1717    IAuthentication, IUnauthenticatedPrincipal, ILogout)
     18from zope.catalog.interfaces import ICatalog
    1819from zope.securitypolicy.interfaces import (
    1920    IPrincipalRoleManager, IPrincipalRoleMap)
     
    2122    getUtility, createObject,getAllUtilitiesRegisteredFor)
    2223from zope.component.interfaces import Invalid
    23 from zope.exceptions import DuplicationError
    2424from zope.session.interfaces import ISession
    2525from zope.event import notify
     
    3636    IWAeUPObject, IUserContainer, IUserAccount, IDataCenter,
    3737    IWAeUPXMLImporter, IWAeUPXMLExporter, IBatchProcessor,
    38     ILocalRolesAssignable)
     38    ILocalRolesAssignable, DuplicationError)
    3939from waeup.sirp.permissions import get_users_with_local_roles, getRoles
    4040from waeup.sirp.university.catalog import search
     
    13301330        certificate = createObject(u'waeup.Certificate')
    13311331        self.applyData(certificate, **data)
    1332         message = self.context.certificates.addCertificate(certificate)
     1332        try:
     1333            self.context.certificates.addCertificate(certificate)
     1334        except DuplicationError, error:
     1335            # signals duplication error
     1336            entries = error.entries
     1337            for entry in entries:
     1338                # show links to all certs with same code
     1339                message = 'A certificate with same code already exists: '
     1340                message += '<a href="%s">%s</a>' % (
     1341                    self.url(entry), getattr(entry, '__name__', u'Unnamed'))
     1342                self.flash(message)
     1343            self.redirect(self.url(self.context, u'@@addcertificate'))
     1344            return
     1345        message = u'Certificate %s successfully created.' % (certificate.code)
    13331346        self.flash(message)
    13341347        self.redirect(self.url(self.context, u'@@manage')+'#tab-3')
     1348        return
    13351349
    13361350    @grok.action('Cancel', validator=NullValidator)
Note: See TracChangeset for help on using the changeset viewer.