source: main/waeup.sirp/trunk/src/waeup/sirp/university/batching.py @ 7156

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

Set value Id for property svn:keywords in all Python files.

  • Property svn:keywords set to Id
File size: 7.8 KB
RevLine 
[5009]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.university.interfaces import (
13    IFacultyContainer, IFaculty, ICourse, IDepartment, ICertificate,
14    ICertificateCourse)
15from waeup.sirp.utils.batching import BatchProcessor
16
17class FacultyProcessor(BatchProcessor):
18    """A batch processor for IFaculty objects.
19    """
[6628]20    grok.implements(IBatchProcessor)
[5009]21    grok.provides(IBatchProcessor)
22    grok.context(Interface)
23    util_name = 'facultyimporter'
24    grok.name(util_name)
25
[6821]26    name = u'Faculty Importer'
[5009]27    iface = IFaculty
28
29    location_fields = ['code',]
30    factory_name = 'waeup.Faculty'
31
[6628]32    mode = None
33
[5009]34    def parentsExist(self, row, site):
35        return 'faculties' in site.keys()
36
37    def entryExists(self, row, site):
38        return row['code'] in site['faculties'].keys()
39
40    def getParent(self, row, site):
41        return site['faculties']
42
43    def getEntry(self, row, site):
44        if not self.entryExists(row, site):
45            return None
46        parent = self.getParent(row, site)
47        return parent.get(row['code'])
[6628]48
[5009]49    def addEntry(self, obj, row, site):
50        parent = self.getParent(row, site)
51        parent.addFaculty(obj)
52        return
53
54    def delEntry(self, row, site):
55        parent = self.getParent(row, site)
56        del parent[row['code']]
57        pass
58
59class DepartmentProcessor(BatchProcessor):
60    """A batch processor for IDepartment objects.
61    """
[6628]62    grok.implements(IBatchProcessor)
[5009]63    grok.provides(IBatchProcessor)
64    grok.context(Interface)
65    util_name = 'departmentimporter'
66    grok.name(util_name)
67
[6821]68    name = u'Department Importer'
[5009]69    iface = IDepartment
70
71    location_fields = ['code', 'faculty_code']
72    factory_name = 'waeup.Department'
73
[6628]74    mode = None
75
[5009]76    def parentsExist(self, row, site):
77        if not 'faculties' in site.keys():
78            return False
79        return row['faculty_code'] in site['faculties']
80
81    def entryExists(self, row, site):
82        if not self.parentsExist(row, site):
83            return False
84        parent = self.getParent(row, site)
85        return row['code'] in parent.keys()
86
87    def getParent(self, row, site):
88        return site['faculties'][row['faculty_code']]
89
90    def getEntry(self, row, site):
91        if not self.entryExists(row, site):
92            return None
93        parent = self.getParent(row, site)
94        return parent.get(row['code'])
[6628]95
[5009]96    def addEntry(self, obj, row, site):
97        parent = self.getParent(row, site)
98        parent.addDepartment(obj)
99        return
100
101    def delEntry(self, row, site):
102        parent = self.getParent(row, site)
103        del parent[row['code']]
104        return
105
106class CourseProcessor(BatchProcessor):
107    """A batch processor for ICourse objects.
108    """
[6628]109    grok.implements(IBatchProcessor)
[5009]110    grok.provides(IBatchProcessor)
111    grok.context(Interface)
112    util_name = 'courseimporter'
113    grok.name(util_name)
114
[6821]115    name = u'Course Importer'
[5009]116    iface = ICourse
117
118    location_fields = ['code', 'faculty_code', 'department_code']
119    factory_name = 'waeup.Course'
120
[6628]121    mode = None
122
[5009]123    def parentsExist(self, row, site):
124        if not 'faculties' in site.keys():
125            return False
126        if not row['faculty_code'] in site['faculties'].keys():
127            return False
128        faculty = site['faculties'][row['faculty_code']]
129        return row['department_code'] in faculty.keys()
130
131    def entryExists(self, row, site):
132        if not self.parentsExist(row, site):
133            return False
134        parent = self.getParent(row, site)
135        return row['code'] in parent.keys()
136
137    def getParent(self, row, site):
138        dept = site['faculties'][row['faculty_code']][row['department_code']]
139        return dept.courses
140
141    def getEntry(self, row, site):
142        if not self.entryExists(row, site):
143            return None
144        parent = self.getParent(row, site)
145        return parent.get(row['code'])
[6628]146
[5009]147    def addEntry(self, obj, row, site):
148        parent = self.getParent(row, site)
149        parent.addCourse(obj)
150        return
151
152    def delEntry(self, row, site):
153        parent = self.getParent(row, site)
154        del parent[row['code']]
155        return
156
157class CertificateProcessor(BatchProcessor):
158    """A batch processor for ICertificate objects.
159    """
[6628]160    grok.implements(IBatchProcessor)
[5009]161    grok.provides(IBatchProcessor)
162    grok.context(Interface)
163    util_name = 'certificateimporter'
164    grok.name(util_name)
165
[6821]166    name = u'Certificate Importer'
[5009]167    iface = ICertificate
168
169    location_fields = ['code', 'faculty_code', 'department_code']
170    factory_name = 'waeup.Certificate'
171
[6628]172    mode = None
173
[5009]174    def parentsExist(self, row, site):
175        if not 'faculties' in site.keys():
176            return False
177        if not row['faculty_code'] in site['faculties'].keys():
178            return False
179        faculty = site['faculties'][row['faculty_code']]
180        return row['department_code'] in faculty.keys()
181
182    def entryExists(self, row, site):
183        if not self.parentsExist(row, site):
184            return False
185        parent = self.getParent(row, site)
186        return row['code'] in parent.keys()
187
188    def getParent(self, row, site):
189        dept = site['faculties'][row['faculty_code']][row['department_code']]
190        return dept.certificates
191
192    def getEntry(self, row, site):
193        if not self.entryExists(row, site):
194            return None
195        parent = self.getParent(row, site)
196        return parent.get(row['code'])
197
198    def addEntry(self, obj, row, site):
199        parent = self.getParent(row, site)
[6243]200        parent.addCertificate(obj)
201        return
[5009]202
203    def delEntry(self, row, site):
204        parent = self.getParent(row, site)
205        del parent[row['code']]
206        return
207
208class CertificateCourseProcessor(BatchProcessor):
209    """A batch processor for ICertificateCourse objects.
210    """
[6628]211    grok.implements(IBatchProcessor)
[5009]212    grok.provides(IBatchProcessor)
213    grok.context(Interface)
214    util_name = 'certificatecourseimporter'
215    grok.name(util_name)
216
[6821]217    name = u'CertificateCourse Importer'
[5009]218    iface = ICertificateCourse
219
220    location_fields = ['course', 'level', 'faculty_code', 'department_code',
221                       'certificate_code',]
222    factory_name = 'waeup.CertificateCourse'
223
[6628]224    mode = None
225
[5009]226    def parentsExist(self, row, site):
227        if not 'faculties' in site.keys():
228            return False
229        if not row['faculty_code'] in site['faculties'].keys():
230            return False
231        faculty = site['faculties'][row['faculty_code']]
232        if not row['department_code'] in faculty.keys():
233            return False
234        dept = faculty[row['department_code']]
235        return row['certificate_code'] in dept.certificates.keys()
236
237    def entryExists(self, row, site):
238        if not self.parentsExist(row, site):
239            return False
240        parent = self.getParent(row, site)
241        code = "%s_%s" % (row['course'].code, row['level'])
242        return code in parent.keys()
243
244    def getParent(self, row, site):
245        dept = site['faculties'][row['faculty_code']][row['department_code']]
246        return dept.certificates[row['certificate_code']]
247
248    def getEntry(self, row, site):
249        if not self.entryExists(row, site):
250            return None
251        parent = self.getParent(row, site)
[6628]252        return parent.get("%s_%s" % (row['course'].code, row['level']))
[5009]253
254    def addEntry(self, obj, row, site):
255        parent = self.getParent(row, site)
256        parent.addCourseRef(row['course'],
257                            row['level'], row['core_or_elective'])
258        return
259
260    def delEntry(self, row, site):
261        parent = self.getParent(row, site)
262        parent.delCourseRef(row['course'].code, row['level'])
263        return
Note: See TracBrowser for help on using the repository browser.