Ignore:
Timestamp:
23 Mar 2015, 10:40:18 (10 years ago)
Author:
Henrik Bettermann
Message:

Skip empty rows produced by spreadsheet software.

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

Legend:

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

    r12632 r12810  
    441.3.2.dev0 (unreleased)
    55=======================
     6
     7* Skip empty rows produced by spreadsheet software.
    68
    79* Add components to  configure a student export jobs in faculties.
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/sample_student_data.csv

    r9932 r12810  
    44,Susann,Berson,3,1990-01-04,100002,aa@aa.ng,1234,F,courses validated
    55,Else,Mueller,4,1990-01-05,100003,aa@aa.ng,1234,f,school fee paid
     6,,,,,,,,,
     7,,,,,,,,,
    68X888888,Alfons,Meier,5,1990-01-02,100004,aa@aa.ng,1234,m,courses validated
    79X999999,Herbert,Mueller,6,1990-01-02,100005,aa@aa.ng,1234,m,courses registered
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_batching.py

    r12623 r12810  
    411411        num, num_warns, fin_file, fail_file = self.processor.doImport(
    412412            self.csv_file, STUDENT_HEADER_FIELDS)
    413         self.assertEqual(num_warns,0)
     413        self.assertEqual(num_warns, 0)
     414        # Nine students have been added.
    414415        self.assertEqual(len(self.app['students']), 10)
     416        # Two empty rows have been skipped.
     417        self.assertEqual(num, 11)
    415418        self.assertEqual(self.app['students']['X666666'].reg_number,'1')
    416419        self.assertEqual(
  • main/waeup.kofa/trunk/src/waeup/kofa/utils/batching.py

    r12516 r12810  
    273273        return errs, inv_errs, conv_dict
    274274
     275
     276    def emptyRow(self, row):
     277        """Detect empty rows.
     278        """
     279        for value in row.values():
     280            if value:
     281                return False
     282        return True
     283
    275284    def doImport(self, path, headerfields, mode='create', user='Unknown',
    276285                 logger=None, ignore_empty=True):
     
    307316        for raw_row in reader:
    308317            num += 1
     318            # Skip row if empty
     319            if self.emptyRow(raw_row):
     320                continue
    309321            string_row = self.applyMapping(raw_row, mapping)
    310322            if ignore_empty and mode in ('update',):
    311                 # replace empty strings with ignore-markers
     323                # Replace empty strings with ignore-markers
    312324                for key, val in string_row.items():
    313325                    if val == '':
Note: See TracChangeset for help on using the changeset viewer.