Changeset 13159


Ignore:
Timestamp:
10 Jul 2015, 11:33:03 (9 years ago)
Author:
Henrik Bettermann
Message:

Enable import of list-of-choices fields.

Location:
main/waeup.kofa/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/CHANGES.txt

    r13156 r13159  
    441.3.2.dev0 (unreleased)
    55=======================
     6
     7* Enable import of list-of-choices fields.
    68
    79* Include 'end day' when searching for payments in a given period.
  • main/waeup.kofa/trunk/src/waeup/kofa/hostels/batching.py

    r12883 r13159  
    6868        """Update obj to the values given in row.
    6969        """
    70         changed = []
    71         for key, value in row.items():
    72             # Skip fields to be ignored.
    73             if value == IGNORE_MARKER:
    74                 continue
    75             if not hasattr(obj, key):
    76                 continue
    77             try:
    78                 evalvalue = eval(value)
    79                 if isinstance(evalvalue, list):
    80                     value = evalvalue
    81             except:
    82                 pass
    83             setattr(obj, key, value)
    84             log_value = getattr(value, 'code', value)
    85             changed.append('%s=%s' % (key, log_value))
    86 
     70        items_changed = super(HostelProcessor, self).updateEntry(
     71            obj, row, site, filename)
    8772        # Log actions...
    8873        location_field = self.location_fields[0]
    89         items_changed = ', '.join(changed)
    9074        grok.getSite()['hostels'].logger.info(
    9175            '%s - %s - %s - updated: %s'
  • main/waeup.kofa/trunk/src/waeup/kofa/utils/batching.py

    r12997 r13159  
    221221            if not hasattr(obj, key):
    222222                continue
     223            # DefaultObjectConverter.fromStringDict fails for
     224            # list-of-choices fields because we are using a different
     225            # widget for this combination. Thus the ListFieldConverter
     226            # returns a useless dictionary which causes getWidgetsData to
     227            # skip the field. The value in row remains unchanged.
     228            # We have to evaluate the string and replace the value here.
     229            try:
     230                evalvalue = eval(value)
     231                if isinstance(evalvalue, list):
     232                    value = evalvalue
     233            except:
     234                pass
    223235            try:
    224236                setattr(obj, key, value)
  • main/waeup.kofa/trunk/src/waeup/kofa/utils/tests/test_converters.py

    r8216 r13159  
    9898        default = [],
    9999        )
     100    fav_colors = schema.List(
     101        title = u'Favourite colors',
     102        value_type = schema.Choice(
     103            vocabulary = colors
     104            ),
     105        required = True,
     106        default = [],
     107        )
    100108    friends = schema.List(
    101109        title = u'Friends',
     
    405413        return
    406414
     415    def test_list_of_choices(self):
     416        # We cannot handle lists of choices because we are using
     417        # a widget which is not yet supported.
     418        converter = IObjectConverter(IContact)
     419        err, inv_err, data = converter.fromStringDict(
     420            {"fav_colors": "['red', 'green']"}, 'contact')
     421        self.assertEqual(
     422            data, {})
     423        return
     424
    407425    def test_ignore_values(self):
    408426        # in update mode we ignore marked values
Note: See TracChangeset for help on using the changeset viewer.