Changeset 6245 for main/waeup.sirp/trunk/src/waeup
- Timestamp:
- 30 May 2011, 07:41:18 (14 years ago)
- Location:
- main/waeup.sirp/trunk/src/waeup/sirp
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/browser/browser.txt
r6229 r6245 337 337 >>> print browser.contents 338 338 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... 339 ...<li class="message"> Course exists already in...</li>339 ...<li class="message">A course with same code already exists:...</li> 340 340 ... 341 341 -
main/waeup.sirp/trunk/src/waeup/sirp/browser/pages.py
r6243 r6245 1292 1292 course = createObject(u'waeup.Course') 1293 1293 self.applyData(course, **data) 1294 message = self.context.courses.addCourse(course) 1294 try: 1295 self.context.courses.addCourse(course) 1296 except DuplicationError, error: 1297 # signals duplication error 1298 entries = error.entries 1299 for entry in entries: 1300 # do not use error.msg but render a more detailed message instead 1301 # and show links to all certs with same code 1302 message = 'A course with same code already exists: ' 1303 message += '<a href="%s">%s</a>' % ( 1304 self.url(entry), getattr(entry, '__name__', u'Unnamed')) 1305 self.flash(message) 1306 self.redirect(self.url(self.context, u'@@addcourse')) 1307 return 1308 message = u'Course %s successfully created.' % (course.code) 1295 1309 self.flash(message) 1296 1310 self.redirect(self.url(self.context, u'@@manage')+'#tab-2') -
main/waeup.sirp/trunk/src/waeup/sirp/university/coursecontainer.py
r6216 r6245 5 5 from zope.component.interfaces import IFactory, ComponentLookupError 6 6 from zope.catalog.interfaces import ICatalog 7 from zope.component import getUtility 7 from zope.component import queryUtility 8 from waeup.sirp.interfaces import DuplicationError 8 9 from waeup.sirp.university.interfaces import ICourseContainer, ICourse 9 10 … … 14 15 grok.require('waeup.manageUniversity') 15 16 16 def addCourse(self, course):17 """ Add a course.17 def __setitem__(self, name, course): 18 """See corresponding docstring in certificatecontainer.py. 18 19 """ 19 20 if not ICourse.providedBy(course): 20 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) 32 self[course.code] = course 33 return 'Course added.' 21 raise TypeError('CourseContainers contain only ' 22 'ICourse instances') 23 24 # Only accept courses with code == key. 25 if course.code != name: 26 raise ValueError('key must match course code: ' 27 '%s, %s' % (name, course.code)) 28 29 # Lookup catalog. If we find none: no duplicates possible. 30 cat = queryUtility(ICatalog, name='courses_catalog', default=None) 31 if cat is not None: 32 entries = cat.searchResults( 33 code=(course.code,course.code)) 34 if len(entries) > 0: 35 raise DuplicationError( 36 'Course exists already elsewhere.', entries) 37 else: 38 # No catalog, then this addition won't do harm to anything. 39 pass 40 super(CourseContainer, self).__setitem__(name, course) 41 42 def addCourse(self, course): 43 """See corresponding docstring in certificatecontainer.py. 44 """ 45 self[getattr(course, 'code', None)] = course 34 46 35 47 def clear(self): 36 """ Remove all objects from course container.48 """See corresponding docstring and comments in certificatecontainer.py. 37 49 """ 38 keys = self.keys() 39 for key in keys: 40 del self[key] 50 self._SampleContainer__data.clear() 51 del self.__dict__['_BTreeContainer__len'] 41 52 42 53 class CourseContainerFactory(grok.GlobalUtility): -
main/waeup.sirp/trunk/src/waeup/sirp/university/coursecontainer.txt
r6217 r6245 71 71 >>> mycourse = Course(code='COURSE1') 72 72 >>> mycontainer.addCourse(mycourse) 73 'Course added (for tests only).'74 73 >>> list(mycontainer.keys()) 75 74 [u'COURSE1']
Note: See TracChangeset for help on using the changeset viewer.