Ignore:
Timestamp:
19 Apr 2012, 12:43:37 (13 years ago)
Author:
uli
Message:

Lots of trash to sketch filtered imports.

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  
    3737_ = MessageFactory = zope.i18nmessageid.MessageFactory('waeup.kofa')
    3838
    39 DELETIONMARKER = 'XXX'
     39DELETION_MARKER = 'XXX'
     40IGNORE_MARKER = '<IGNORE>'
    4041
    4142CREATED = 'created'
     
    825826
    826827class IFieldConverter(Interface):
    827     def update_request_data(self, name, value, schema_field, prefix=''):
     828    def request_data(name, value, schema_field, prefix='', mode='create'):
    828829        """Create a dict with key-value mapping as created by a request.
    829830
     
    831832        similar input and represent an attribute to be set to a
    832833        representation of value.
     834
     835        `mode` gives the mode of import.
    833836
    834837        :meth:`update_request_data` is then requested to turn this
  • main/waeup.kofa/trunk/src/waeup/kofa/students/batching.py

    r8209 r8214  
    3434from waeup.kofa.interfaces import (
    3535    IBatchProcessor, FatalCSVError, IObjectConverter, IUserAccount,
    36     IObjectHistory, VALIDATED, DELETIONMARKER)
     36    IObjectHistory, VALIDATED, DELETION_MARKER, IGNORE_MARKER)
    3737from waeup.kofa.interfaces import MessageFactory as _
    3838from waeup.kofa.students.interfaces import (
     
    169169            elif hasattr(obj, key):
    170170                # 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>':
    174179                    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)
    179182        parent = self.getParent(row, site)
    180183        if hasattr(obj,'student_id'):
     
    215218        converter = IObjectConverter(iface)
    216219        errs, inv_errs, conv_dict =  converter.fromStringDict(
    217             row, self.factory_name)
     220            row, self.factory_name, mode=mode)
    218221        if row.has_key('reg_state') and \
    219222            not row['reg_state'] in IMPORTABLE_STATES:
     
    304307            if hasattr(obj, key):
    305308                # 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)
    313320        parent = self.getParent(row, site)
    314321        parent.__parent__.logger.info(
     
    698705            if hasattr(obj, key) and not key in [
    699706                'current_session','current_level']:
     707                setattr(obj, key, value)
    700708                # 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)
    706714        parent = self.getParent(row, site)
    707715        parent.__parent__.logger.info(
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/sample_student_data_update2.csv

    r8210 r8214  
    11date_of_birth,matric_number,phone
    2 1970-01-02,100000,
     21970-01-02,100000,<IGNORE>
    331970-01-03,100001,XXX
    4 1970-01-04,100002,
     41970-01-04,100002,<IGNORE>
  • main/waeup.kofa/trunk/src/waeup/kofa/utils/batching.py

    r8202 r8214  
    3232from waeup.kofa.interfaces import (
    3333    IBatchProcessor, FatalCSVError, IObjectConverter,
    34     ICSVExporter, DELETIONMARKER)
     34    ICSVExporter, DELETION_MARKER, IGNORE_MARKER)
    3535
    3636class BatchProcessor(grok.GlobalUtility):
     
    205205            if hasattr(obj, key):
    206206                # 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>':
    210208                    setattr(obj, key, value)
     209                #if value == DELETIONMARKER:
     210                #    setattr(obj, key, None)
     211                #elif value is not None:
     212                #    setattr(obj, key, value)
    211213        return
    212214
  • main/waeup.kofa/trunk/src/waeup/kofa/utils/converters.py

    r8175 r8214  
    3030from waeup.kofa.interfaces import (
    3131    IObjectConverter, IResultEntryField, IFieldConverter, SubjectSource,
    32     GradeSource)
     32    GradeSource, DELETION_MARKER, IGNORE_MARKER)
    3333from waeup.kofa.schema.interfaces import IPhoneNumber
    3434from waeup.kofa.schoolgrades import ResultEntry
     
    114114class DefaultFieldConverter(grok.Adapter):
    115115    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'):
    119120        return {prefix: value}
    120121
    121122class ListFieldConverter(grok.Adapter):
    122123    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'):
    126128        value_type = schema_field.value_type
    127129        try:
     
    144146    """
    145147    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'):
    149152        parts = value.split('-', 2)
    150153        country = ''
     
    168171class ResultEntryConverter(grok.Adapter):
    169172    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'):
    173177        """Turn CSV values into ResultEntry-compatible form data.
    174178
     
    208212
    209213    grok.context(Interface)
    210     grok.provides(IObjectConverter)
     214    grok.implements(IObjectConverter)
    211215
    212216    def __init__(self, iface):
     
    217221        return
    218222
    219     def fromStringDict(self, data_dict, context, form_fields=None):
     223    def fromStringDict(self, data_dict, context, form_fields=None,
     224                       mode='create'):
    220225        """Convert values in `data_dict`.
    221226
     
    262267
    263268        request = TestRequest(form={})
     269        new_data = dict()
    264270        for key, val in data_dict.items():
    265271            field = form_fields.get(key, None)
     
    269275                schema_field = field.interface[field.__name__]
    270276                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
    271286                request.form.update(
    272287                    field_converter.request_data(
     
    283298            form_fields, 'form', obj, request)
    284299
    285         new_data = dict()
     300        #new_data = dict()
    286301        errors = getWidgetsData(widgets, 'form', new_data)
    287302
Note: See TracChangeset for help on using the changeset viewer.