source: main/waeup.sirp/trunk/src/waeup/sirp/students/batching.py @ 6821

Last change on this file since 6821 was 6821, checked in by Henrik Bettermann, 13 years ago

Add first version of Student Importer. This student importer imports student base data only.

  • Property svn:keywords set to Id
File size: 1.9 KB
Line 
1"""Batch processing components for academics objects.
2
3Batch processors eat CSV files to add, update or remove large numbers
4of certain kinds of objects at once.
5
6Here we define the processors for academics specific objects like
7faculties, departments and the like.
8"""
9import grok
10from zope.interface import Interface
11from waeup.sirp.interfaces import IBatchProcessor
12from waeup.sirp.students.interfaces import IStudent
13from waeup.sirp.utils.batching import BatchProcessor
14
15class StudentProcessor(BatchProcessor):
16    """A batch processor for IStudent objects.
17    """
18    grok.implements(IBatchProcessor)
19    grok.provides(IBatchProcessor)
20    grok.context(Interface)
21    util_name = 'studentimporter'
22    grok.name(util_name)
23
24    name = u'Student Importer'
25    iface = IStudent
26
27    location_fields = ['student_id',]
28    factory_name = 'waeup.Student'
29
30    mode = None
31
32    @property
33    def req(self):
34        result = dict(
35            create = self.required_fields,
36            update = self.location_fields,
37            remove = self.location_fields,
38        )
39        return result
40
41    def parentsExist(self, row, site):
42        return 'students' in site.keys()
43
44    # The entry never exists in create mode.
45    def entryExists(self, row, site):
46        if row.has_key('student_id'):
47            return row['student_id'] in site['students'].keys()
48        return False
49
50    def getParent(self, row, site):
51        return site['students']
52
53    def getEntry(self, row, site):
54        if not self.entryExists(row, site):
55            return None
56        parent = self.getParent(row, site)
57        return parent.get(row['student_id'])
58
59    def addEntry(self, obj, row, site):
60        parent = self.getParent(row, site)
61        parent.addStudent(obj)
62        return
63
64    def delEntry(self, row, site):
65        parent = self.getParent(row, site)
66        del parent[row['student_id']]
67        pass
Note: See TracBrowser for help on using the repository browser.