- Timestamp:
- 14 Oct 2012, 04:54:11 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/university/batching.py
r9087 r9333 211 211 return 212 212 213 class CourseProcessor(FacultyProcessor):214 """A batch processor for ICourse objects.215 """216 grok.implements(IBatchProcessor)217 grok.provides(IBatchProcessor)218 grok.context(Interface)219 util_name = 'courseprocessor'220 grok.name(util_name)221 222 name = u'Course Processor'223 iface = ICourse224 allowed_roles = Course.local_roles225 226 location_fields = ['code', 'faculty_code', 'department_code']227 factory_name = 'waeup.Course'228 229 mode = None230 231 def parentsExist(self, row, site):232 if not 'faculties' in site.keys():233 return False234 if not row['faculty_code'] in site['faculties'].keys():235 return False236 faculty = site['faculties'][row['faculty_code']]237 return row['department_code'] in faculty.keys()238 239 def entryExists(self, row, site):240 if not self.parentsExist(row, site):241 return False242 parent = self.getParent(row, site)243 return row['code'] in parent.keys()244 245 def getParent(self, row, site):246 dept = site['faculties'][row['faculty_code']][row['department_code']]247 return dept.courses248 249 def getEntry(self, row, site):250 if not self.entryExists(row, site):251 return None252 parent = self.getParent(row, site)253 return parent.get(row['code'])254 255 def addEntry(self, obj, row, site):256 parent = self.getParent(row, site)257 parent.addCourse(obj)258 return259 260 def delEntry(self, row, site):261 parent = self.getParent(row, site)262 del parent[row['code']]263 return264 265 213 class CertificateProcessor(FacultyProcessor): 266 214 """A batch processor for ICertificate objects. … … 289 237 290 238 def checkHeaders(self, headerfields, mode='create'): 291 req = self.req[mode] 292 # Check for required fields... 293 for field in req: 294 if not field in headerfields: 295 raise FatalCSVError( 296 "Need at least columns %s for import!" % 297 ', '.join(["'%s'" % x for x in req])) 298 # Check for double fields. Cannot happen because this error is 299 # already catched in views 300 not_ignored_fields = [x for x in headerfields 301 if not x.startswith('--')] 302 if len(set(not_ignored_fields)) < len(not_ignored_fields): 303 raise FatalCSVError( 304 "Double headers: each column name may only appear once.") 239 super(CertificateProcessor, self).checkHeaders(headerfields, mode) 305 240 if mode == 'create': 306 241 if not 'faculty_code' in headerfields \ … … 359 294 return 360 295 296 class CourseProcessor(CertificateProcessor): 297 """A batch processor for ICourse objects. 298 """ 299 grok.implements(IBatchProcessor) 300 grok.provides(IBatchProcessor) 301 grok.context(Interface) 302 util_name = 'courseprocessor' 303 grok.name(util_name) 304 305 name = u'Course Processor' 306 iface = ICourse 307 allowed_roles = Course.local_roles 308 309 location_fields = ['code'] 310 factory_name = 'waeup.Course' 311 312 mode = None 313 314 def getParent(self, row, site): 315 if not 'faculties' in site.keys(): 316 return None 317 # If both faculty and department codes are provided, use 318 # these to get parent. 319 if row.get('faculty_code',None) not in (None, IGNORE_MARKER) and \ 320 row.get('department_code',None) not in (None, IGNORE_MARKER): 321 if not row['faculty_code'] in site['faculties'].keys(): 322 return None 323 faculty = site['faculties'][row['faculty_code']] 324 if not row['department_code'] in faculty.keys(): 325 return None 326 dept = faculty[row['department_code']] 327 return dept.courses 328 # If department code or faculty code is missing, 329 # use catalog to get parent. Makes only sense in update mode but 330 # does also work in create mode. 331 cat = queryUtility(ICatalog, name='courses_catalog') 332 results = list( 333 cat.searchResults(code=(row['code'], row['code']))) 334 if results: 335 return results[0].__parent__ 336 return None 337 338 def addEntry(self, obj, row, site): 339 parent = self.getParent(row, site) 340 parent.addCourse(obj) 341 return 342 361 343 class CertificateCourseProcessor(FacultyProcessor): 362 344 """A batch processor for ICertificateCourse objects.
Note: See TracChangeset for help on using the changeset viewer.