- Timestamp:
- 18 Sep 2011, 00:07:07 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/students/vocabularies.py
r6744 r6787 2 2 """ 3 3 from datetime import datetime 4 from zope.component import getUtility 4 from zope.component import getUtility, queryUtility 5 5 from zope.catalog.interfaces import ICatalog 6 from zope.interface import implements, directlyProvides 7 from zope.schema.interfaces import ISource, IContextSourceBinder 8 from zope.schema.interfaces import ValidationError 6 9 from zc.sourcefactory.basic import BasicSourceFactory 7 10 from zc.sourcefactory.contextual import BasicContextualSourceFactory … … 9 12 from waeup.sirp.students.lgas import LGAS 10 13 from waeup.sirp.university.vocabularies import course_levels 14 15 11 16 12 17 def year_range(): … … 33 38 except AttributeError: 34 39 return [] 35 40 36 41 class StudyLevelSource(BasicContextualSourceFactory): 37 42 """The StudyLevelSource is based on and extends the … … 130 135 if value == 'f': 131 136 return 'Female' 137 138 class RegNumNotInSource(ValidationError): 139 """Registration number exists already 140 """ 141 # The docstring of ValidationErrors is used as error description 142 # by zope.formlib. 143 pass 144 145 class MatNumNotInSource(ValidationError): 146 """Matriculation number exists already 147 """ 148 # The docstring of ValidationErrors is used as error description 149 # by zope.formlib. 150 pass 151 152 class RegNumberSource(object): 153 implements(ISource) 154 cat_name = 'students_catalog' 155 field_name = 'reg_number' 156 validation_error = RegNumNotInSource 157 def __init__(self, context): 158 self.context = context 159 return 160 161 def __contains__(self, value): 162 cat = queryUtility(ICatalog, self.cat_name) 163 if cat is None: 164 return True 165 kw = {self.field_name: (value, value)} 166 results = cat.searchResults(**kw) 167 for entry in results: 168 if entry.student_id != self.context.student_id: 169 # XXX: sources should simply return False. 170 # But then we get some stupid error message in forms 171 # when validation fails. 172 raise self.validation_error(value) 173 #return False 174 return True 175 176 def contextual_reg_num_source(context): 177 source = RegNumberSource(context) 178 return source 179 directlyProvides(contextual_reg_num_source, IContextSourceBinder) 180 181 class MatNumberSource(RegNumberSource): 182 field_name = 'matric_number' 183 validation_error = MatNumNotInSource 184 185 def contextual_mat_num_source(context): 186 source = MatNumberSource(context) 187 return source 188 directlyProvides(contextual_mat_num_source, IContextSourceBinder)
Note: See TracChangeset for help on using the changeset viewer.