Ignore:
Timestamp:
21 Feb 2022, 06:21:10 (3 years ago)
Author:
Henrik Bettermann
Message:

Don't complain but remove leading and trailing whitespaces while converting values during import.

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

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/utils/converters.py

    r12415 r16818  
    280280        new_data = dict()
    281281        for key, val in data_dict.items():
     282            val = val.strip()
    282283            field = form_fields.get(key, None)
    283284            if field is not None:
  • main/waeup.kofa/trunk/src/waeup/kofa/utils/helpers.py

    r15748 r16818  
    770770    Returns line num of first illegal char or ``None``. Line nums
    771771    start counting with 1 (not zero). Returns -1 if data contain
    772     trailing whitespaces.
     772    trailing whitespaces (deactivated).
    773773    """
    774774    linenum = 1
     
    777777        for row in reader:
    778778            linenum += 1
    779             for value in row.values():
    780                 if value.endswith(' '):
    781                     return -1
     779            #for value in row.values():
     780            #    if value.endswith(' '):
     781            #        return -1
    782782    except UnicodeDecodeError:
    783783        return linenum
  • main/waeup.kofa/trunk/src/waeup/kofa/utils/tests/test_converters.py

    r14008 r16818  
    200200        contact = Contact()
    201201        contact.age = 33
    202         input_data = dict(name='Rudi', age='99')
     202        input_data = dict(name='  Rudi    ', age=' 99 ')
    203203        converter = IObjectConverter(IContact)  # a converter to IContact
    204204        err, inv_err, data = converter.fromStringDict(
     
    283283    def test_textline(self):
    284284        contact = Contact()
    285         input_data = dict(name='Rudi')
     285        input_data = dict(name=' Rudi     ')
    286286        converter = IObjectConverter(IContact)  # a converter to IContact
    287287        err, inv_err, data = converter.fromStringDict(
     
    357357        # pass string ``contact`` instead of a real object
    358358        err, inv_err, data = converter.fromStringDict(
    359             dict(name='Gabi', age='23'), 'contact')
     359            dict(name='  Gabi  ', age='23  '), 'contact')
    360360        self.assertEqual(data['age'], 23)
    361361        self.assertEqual(data['name'], u'Gabi')
  • main/waeup.kofa/trunk/src/waeup/kofa/utils/tests/test_helpers.py

    r14948 r16818  
    545545            "FAC3,Fäcülty 3,school\n"
    546546            ).splitlines()
    547         self.assertEqual(helpers.check_csv_charset(csv), -1)
     547        self.assertEqual(helpers.check_csv_charset(csv), None)
    548548
    549549class MemInfoTestCase(unittest.TestCase):
Note: See TracChangeset for help on using the changeset viewer.