Changeset 6216 for main


Ignore:
Timestamp:
29 May 2011, 09:23:30 (14 years ago)
Author:
Henrik Bettermann
Message:

Course codes must be unique. Check catalog when courses are added. Flash the place where course exists.

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

Legend:

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

    r6210 r6216  
    13031303        course = createObject(u'waeup.Course')
    13041304        self.applyData(course, **data)
    1305         try:
    1306             self.context.courses.addCourse(course)
    1307         except KeyError:
    1308             self.status = Invalid('The code chosen already exists '
    1309                                   'in the database')
    1310             return
    1311         except DuplicationError:
    1312             self.status = Invalid('The code chosen already exists '
    1313                                   'in the database')
    1314             return
     1305        message = self.context.courses.addCourse(course)
     1306        self.flash(message)
    13151307        self.redirect(self.url(self.context, u'@@manage')+'#tab-2')
    13161308
  • main/waeup.sirp/trunk/src/waeup/sirp/university/certificatecontainer.py

    r6213 r6216  
    44from waeup.sirp.university.interfaces import (
    55    ICertificateContainer, ICertificate)
    6 from zope.component.interfaces import IFactory
     6from zope.component.interfaces import IFactory, ComponentLookupError
    77from zope.catalog.interfaces import ICatalog
    88from zope.component import getUtility
     
    1919            raise TypeError('CertificateContainers contain only '
    2020                            'ICertificate instances')
    21         cat = getUtility(ICatalog, name='certificates_catalog')
     21        try:
     22            cat = getUtility(ICatalog, name='certificates_catalog')
     23        except ComponentLookupError:
     24            # catalog not available. This might happen during tests.
     25            self[certificate.code] = certificate
     26            return 'Certificate added (for tests only).'
    2227        results = list(cat.searchResults(code=(certificate.code,certificate.code)))
    2328        if results:
  • main/waeup.sirp/trunk/src/waeup/sirp/university/coursecontainer.py

    r5005 r6216  
    33import grok
    44from zope.interface import implementedBy
    5 from zope.component.interfaces import IFactory
     5from zope.component.interfaces import IFactory, ComponentLookupError
     6from zope.catalog.interfaces import ICatalog
     7from zope.component import getUtility
    68from waeup.sirp.university.interfaces import ICourseContainer, ICourse
    79
     
    1719        if not ICourse.providedBy(course):
    1820            raise TypeError('CourseContainers contain only ICourse instances')
     21        try:
     22            cat = getUtility(ICatalog, name='courses_catalog')
     23        except ComponentLookupError:
     24            # catalog not available. This might happen during tests.
     25            self[course.code] = course
     26            return 'Course added (for tests only).'
     27        results = list(cat.searchResults(code=(course.code,course.code)))
     28        if results:
     29            dep = results[0].__parent__.__parent__.longtitle()
     30            fac = results[0].__parent__.__parent__.__parent__.longtitle()
     31            return 'Course exists already in %s / %s.' % (fac,dep)
    1932        self[course.code] = course
    20         return
     33        return 'Course added.'
    2134
    2235    def clear(self):
Note: See TracChangeset for help on using the changeset viewer.