- Timestamp:
- 4 Dec 2011, 12:59:40 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/applicants/interfaces.py
r7262 r7263 22 22 23 23 from zope import schema 24 from zope.interface import Interface, Attribute 25 from zope.component import getUtilitiesFor 24 from zope.interface import Interface, Attribute, implements, directlyProvides 25 from zope.component import getUtilitiesFor, queryUtility 26 from zope.catalog.interfaces import ICatalog 27 from zope.schema.interfaces import ValidationError, ISource, IContextSourceBinder 26 28 from zc.sourcefactory.basic import BasicSourceFactory 29 from waeup.sirp.schema import TextLineChoice 27 30 from waeup.sirp.interfaces import ( 28 31 IWAeUPObject, year_range, validate_email, academic_sessions_vocab) … … 40 43 MAX_UPLOAD_SIZE = 1024 * 20 41 44 45 class RegNumInSource(ValidationError): 46 """Registration number exists already 47 """ 48 # The docstring of ValidationErrors is used as error description 49 # by zope.formlib. 50 pass 51 52 class RegNumberSource(object): 53 implements(ISource) 54 cat_name = 'applicants_catalog' 55 field_name = 'reg_no' 56 validation_error = RegNumInSource 57 def __init__(self, context): 58 self.context = context 59 return 60 61 def __contains__(self, value): 62 cat = queryUtility(ICatalog, self.cat_name) 63 if cat is None: 64 return True 65 kw = {self.field_name: (value, value)} 66 results = cat.searchResults(**kw) 67 for entry in results: 68 if entry.applicant_id != self.context.applicant_id: 69 # XXX: sources should simply return False. 70 # But then we get some stupid error message in forms 71 # when validation fails. 72 raise self.validation_error(value) 73 #return False 74 return True 75 76 def contextual_reg_num_source(context): 77 source = RegNumberSource(context) 78 return source 79 directlyProvides(contextual_reg_num_source, IContextSourceBinder) 80 42 81 class ApplicantContainerProviderSource(BasicSourceFactory): 43 82 """A source offering all available applicants container types. … … 259 298 readonly = False, 260 299 ) 261 reg_no = schema.TextLine(300 reg_no = TextLineChoice( 262 301 title = u'JAMB Registration Number', 263 readonly = True, 264 required = False, 302 readonly = False, 303 required = True, 304 default = None, 305 source = contextual_reg_num_source, 265 306 ) 266 307 access_code = schema.TextLine(
Note: See TracChangeset for help on using the changeset viewer.