Ignore:
Timestamp:
2 Oct 2011, 09:45:29 (13 years ago)
Author:
Henrik Bettermann
Message:

Enable locating students by reg_number or matric_number for update and removal.

Allow adding students by pre-selecting the student_id and bypassing the random student_id generator. This is important for the migration of student data.

Further tests are needed and will follow!

Location:
main/waeup.sirp/trunk/src/waeup/sirp/students
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/students/batching.py

    r6843 r6846  
    4747
    4848    # The entry never exists in create mode.
    49     # To do: Use reg_number and matric_number for locating as well.
    5049    def entryExists(self, row, site):
    51         if row.has_key('student_id'):
    52             return row['student_id'] in site['students'].keys()
     50        if not 'students' in site.keys():
     51            return False
     52        if 'student_id' in row.keys() and row['student_id']:
     53            if row['student_id'] in site['students']:
     54                student = site['students'][row['student_id']]
     55                return student
     56        elif 'reg_number' in row.keys() and row['reg_number']:
     57            reg_number = row['reg_number']
     58            cat = queryUtility(ICatalog, name='students_catalog')
     59            results = list(
     60                cat.searchResults(reg_number=(reg_number, reg_number)))
     61            if results:
     62                return results[0]
     63        elif 'matric_number' in row.keys() and row['matric_number']:
     64            #import pdb; pdb.set_trace()
     65            matric_number = row['matric_number']
     66            cat = queryUtility(ICatalog, name='students_catalog')
     67            results = list(
     68                cat.searchResults(matric_number=(matric_number, matric_number)))
     69            if results:
     70                return results[0]
    5371        return False
    5472
     
    5775
    5876    def getEntry(self, row, site):
    59         if not self.entryExists(row, site):
    60             return None
    61         parent = self.getParent(row, site)
    62         return parent.get(row['student_id'])
     77        return self.entryExists(row, site)
    6378
    6479    def addEntry(self, obj, row, site):
     
    6883
    6984    def delEntry(self, row, site):
    70         parent = self.getParent(row, site)
    71         del parent[row['student_id']]
     85        student = self.entryExists(row, site)
     86        if student:
     87            parent = self.getParent(row, site)
     88            del parent[student.student_id]
    7289        pass
    7390
     
    107124
    108125    def parentsExist(self, row, site):
    109         if not 'students' in site.keys() and row['student_id']:
     126        if not 'students' in site.keys():
    110127            return False
    111         if 'student_id' in row.keys():
     128        if 'student_id' in row.keys() and row['student_id']:
    112129            if row['student_id'] in site['students']:
    113130                student = site['students'][row['student_id']]
     
    121138                return results[0]
    122139        elif 'matric_number' in row.keys() and row['matric_number']:
    123             #import pdb; pdb.set_trace()
    124140            matric_number = row['matric_number']
    125141            cat = queryUtility(ICatalog, name='students_catalog')
  • main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_batching.py

    r6843 r6846  
    107107        assert self.importer.entryExists(
    108108            dict(student_id='ID_NONE'), self.app) is False
    109         assert self.importer.entryExists(
    110             dict(student_id=self.student.student_id), self.app) is True
     109        student = dict(student_id=self.student.student_id), self.app)
     110        self.assertEqual(student.reg_number, u'123')
    111111
    112112    def test_getParent(self):
Note: See TracChangeset for help on using the changeset viewer.