Changeset 8214 for main/waeup.kofa/trunk/src
- Timestamp:
- 19 Apr 2012, 12:43:37 (13 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/interfaces.py
r8202 r8214 37 37 _ = MessageFactory = zope.i18nmessageid.MessageFactory('waeup.kofa') 38 38 39 DELETIONMARKER = 'XXX' 39 DELETION_MARKER = 'XXX' 40 IGNORE_MARKER = '<IGNORE>' 40 41 41 42 CREATED = 'created' … … 825 826 826 827 class IFieldConverter(Interface): 827 def update_request_data(self, name, value, schema_field, prefix=''):828 def request_data(name, value, schema_field, prefix='', mode='create'): 828 829 """Create a dict with key-value mapping as created by a request. 829 830 … … 831 832 similar input and represent an attribute to be set to a 832 833 representation of value. 834 835 `mode` gives the mode of import. 833 836 834 837 :meth:`update_request_data` is then requested to turn this -
main/waeup.kofa/trunk/src/waeup/kofa/students/batching.py
r8209 r8214 34 34 from waeup.kofa.interfaces import ( 35 35 IBatchProcessor, FatalCSVError, IObjectConverter, IUserAccount, 36 IObjectHistory, VALIDATED, DELETION MARKER)36 IObjectHistory, VALIDATED, DELETION_MARKER, IGNORE_MARKER) 37 37 from waeup.kofa.interfaces import MessageFactory as _ 38 38 from waeup.kofa.students.interfaces import ( … … 169 169 elif hasattr(obj, key): 170 170 # Set attribute to None if value is marked for deletion 171 if value == DELETIONMARKER: 172 setattr(obj, key, None) 173 elif value is not None: 171 #if value == DELETION_MARKER: 172 # setattr(obj, key, None) 173 #elif value is not None: 174 # setattr(obj, key, value) 175 #else: 176 # # No change, no change log 177 # continue 178 if value != '<IGNORE>': 174 179 setattr(obj, key, value) 175 else: 176 # No change, no change log 177 continue 178 items_changed += '%s=%s, ' % (key,value) 180 181 items_changed += '%s=%s, ' % (key,value) 179 182 parent = self.getParent(row, site) 180 183 if hasattr(obj,'student_id'): … … 215 218 converter = IObjectConverter(iface) 216 219 errs, inv_errs, conv_dict = converter.fromStringDict( 217 row, self.factory_name )220 row, self.factory_name, mode=mode) 218 221 if row.has_key('reg_state') and \ 219 222 not row['reg_state'] in IMPORTABLE_STATES: … … 304 307 if hasattr(obj, key): 305 308 # Set attribute to None if value is marked for deletion 306 if value == DELETIONMARKER: 307 setattr(obj, key, None) 308 elif value is not None: 309 setattr(obj, key, value) 310 if key == 'certificate': 311 value = value.code 312 items_changed += '%s=%s, ' % (key,value) 309 setattr(obj, key, value) 310 if key == 'certificate': 311 value = value.code 312 313 #if value == DELETIONMARKER: 314 # setattr(obj, key, None) 315 #elif value is not None: 316 # setattr(obj, key, value) 317 # if key == 'certificate': 318 # value = value.code 319 items_changed += '%s=%s, ' % (key,value) 313 320 parent = self.getParent(row, site) 314 321 parent.__parent__.logger.info( … … 698 705 if hasattr(obj, key) and not key in [ 699 706 'current_session','current_level']: 707 setattr(obj, key, value) 700 708 # Set attribute to None if value is marked for deletion 701 if value == DELETIONMARKER:702 setattr(obj, key, None)703 elif value is not None:704 setattr(obj, key, value)705 items_changed += '%s=%s, ' % (key,value)709 #if value == DELETIONMARKER: 710 # setattr(obj, key, None) 711 #elif value is not None: 712 # setattr(obj, key, value) 713 items_changed += '%s=%s, ' % (key,value) 706 714 parent = self.getParent(row, site) 707 715 parent.__parent__.logger.info( -
main/waeup.kofa/trunk/src/waeup/kofa/students/tests/sample_student_data_update2.csv
r8210 r8214 1 1 date_of_birth,matric_number,phone 2 1970-01-02,100000, 2 1970-01-02,100000,<IGNORE> 3 3 1970-01-03,100001,XXX 4 1970-01-04,100002, 4 1970-01-04,100002,<IGNORE> -
main/waeup.kofa/trunk/src/waeup/kofa/utils/batching.py
r8202 r8214 32 32 from waeup.kofa.interfaces import ( 33 33 IBatchProcessor, FatalCSVError, IObjectConverter, 34 ICSVExporter, DELETION MARKER)34 ICSVExporter, DELETION_MARKER, IGNORE_MARKER) 35 35 36 36 class BatchProcessor(grok.GlobalUtility): … … 205 205 if hasattr(obj, key): 206 206 # Set attribute to None if value is marked for deletion 207 if value == DELETIONMARKER: 208 setattr(obj, key, None) 209 elif value is not None: 207 if value != '<IGNORE>': 210 208 setattr(obj, key, value) 209 #if value == DELETIONMARKER: 210 # setattr(obj, key, None) 211 #elif value is not None: 212 # setattr(obj, key, value) 211 213 return 212 214 -
main/waeup.kofa/trunk/src/waeup/kofa/utils/converters.py
r8175 r8214 30 30 from waeup.kofa.interfaces import ( 31 31 IObjectConverter, IResultEntryField, IFieldConverter, SubjectSource, 32 GradeSource )32 GradeSource, DELETION_MARKER, IGNORE_MARKER) 33 33 from waeup.kofa.schema.interfaces import IPhoneNumber 34 34 from waeup.kofa.schoolgrades import ResultEntry … … 114 114 class DefaultFieldConverter(grok.Adapter): 115 115 grok.context(Interface) 116 grok.provides(IFieldConverter) 117 118 def request_data(self, name, value, schema_field, prefix=''): 116 grok.implements(IFieldConverter) 117 118 def request_data(self, name, value, schema_field, prefix='', 119 mode='create'): 119 120 return {prefix: value} 120 121 121 122 class ListFieldConverter(grok.Adapter): 122 123 grok.context(IList) 123 grok.provides(IFieldConverter) 124 125 def request_data(self, name, value, schema_field, prefix=''): 124 grok.implements(IFieldConverter) 125 126 def request_data(self, name, value, schema_field, prefix='', 127 mode='create'): 126 128 value_type = schema_field.value_type 127 129 try: … … 144 146 """ 145 147 grok.context(IPhoneNumber) 146 grok.provides(IFieldConverter) 147 148 def request_data(self, name, value, schema_field, prefix=''): 148 grok.implements(IFieldConverter) 149 150 def request_data(self, name, value, schema_field, prefix='', 151 mode='create'): 149 152 parts = value.split('-', 2) 150 153 country = '' … … 168 171 class ResultEntryConverter(grok.Adapter): 169 172 grok.context(IResultEntryField) 170 grok.provides(IFieldConverter) 171 172 def request_data(self, name, value, schema_field, prefix=''): 173 grok.implements(IFieldConverter) 174 175 def request_data(self, name, value, schema_field, prefix='', 176 mode='create'): 173 177 """Turn CSV values into ResultEntry-compatible form data. 174 178 … … 208 212 209 213 grok.context(Interface) 210 grok. provides(IObjectConverter)214 grok.implements(IObjectConverter) 211 215 212 216 def __init__(self, iface): … … 217 221 return 218 222 219 def fromStringDict(self, data_dict, context, form_fields=None): 223 def fromStringDict(self, data_dict, context, form_fields=None, 224 mode='create'): 220 225 """Convert values in `data_dict`. 221 226 … … 262 267 263 268 request = TestRequest(form={}) 269 new_data = dict() 264 270 for key, val in data_dict.items(): 265 271 field = form_fields.get(key, None) … … 269 275 schema_field = field.interface[field.__name__] 270 276 field_converter = IFieldConverter(schema_field) 277 if mode == 'update': 278 if val == DELETION_MARKER: 279 val = schema_field.missing_value 280 if schema_field.required: 281 val = schema_field.default 282 new_data[key] = val 283 continue 284 if val == IGNORE_MARKER: 285 continue 271 286 request.form.update( 272 287 field_converter.request_data( … … 283 298 form_fields, 'form', obj, request) 284 299 285 new_data = dict()300 #new_data = dict() 286 301 errors = getWidgetsData(widgets, 'form', new_data) 287 302
Note: See TracChangeset for help on using the changeset viewer.