Changeset 8766
- Timestamp:
- 20 Jun 2012, 09:13:49 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/students/vocabularies.py
r8471 r8766 140 140 141 141 class RegNumberSource(object): 142 """A source that accepts any entry for a certain field if not used 143 already. 144 145 Using this kind of source means a way of setting an invariant. 146 147 We accept a value iff: 148 - the value cannot be found in catalog or 149 - the value can be found as part of some item but the bound item 150 is the context object itself. 151 """ 142 152 implements(ISource) 143 153 cat_name = 'students_catalog' 144 154 field_name = 'reg_number' 145 155 validation_error = RegNumNotInSource 156 comp_field = 'student_id' 146 157 def __init__(self, context): 147 158 self.context = context … … 149 160 150 161 def __contains__(self, value): 162 """We accept all values not already given to other students. 163 """ 151 164 cat = queryUtility(ICatalog, self.cat_name) 152 165 if cat is None: … … 155 168 results = cat.searchResults(**kw) 156 169 for entry in results: 157 if entry.student_id != self.context.student_id: 158 # XXX: sources should simply return False. 159 # But then we get some stupid error message in forms 160 # when validation fails. 170 if not hasattr(self.context, self.comp_field): 171 # we have no context with comp_field (most probably 172 # while adding a new object, where the container is 173 # the context) which means that the value was given 174 # already to another object (as _something_ was found in 175 # the catalog with that value). Fail on first round. 176 raise self.validation_error(value) 177 if getattr(entry, self.comp_field) != getattr( 178 self.context, self.comp_field): 179 # An entry already given to another student is not in our 180 # range of acceptable values. 161 181 raise self.validation_error(value) 162 182 #return False
Note: See TracChangeset for help on using the changeset viewer.