Changeset 3248 for WAeUP_SRP/base
- Timestamp:
- 28 Feb 2008, 08:03:50 (17 years ago)
- Location:
- WAeUP_SRP/base
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/base/WAeUPImport.py
r3243 r3248 60 60 self.current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") 61 61 self.waeup_tool = waeup_tool 62 self.students_folder = waeup_tool.portal_url.getPortalObject().campus.students 63 self.academics_folder = waeup_tool.portal_url.getPortalObject().campus.academics 62 64 self.schema_tool = getToolByName(waeup_tool, 'portal_schemas') 63 65 self.layout_tool = getToolByName(waeup_tool, 'portal_layouts') … … 178 180 self._v_certificate_list = [] 179 181 if getattr(self,'_v_department_certificates',None) is None: 180 res = self.portal_catalog(portal_type = "Department")182 departments = self.portal_catalog(portal_type = "Department") 181 183 self._v_department_certificates = {} 182 for d in res: 183 self._v_department_certificates[d.getId] = getattr(d.getObject(),"certificates",None) 184 did = mapping['department_code'] 185 msg = '' 186 while True: 187 d = self._v_department_certificates.get(did,None) 188 if d is None: 189 msg = "no department with id: %s" % did 190 break 191 certificate_id = mapping.get('code') 184 for d in departments: 185 certificates_folder = getattr(d.getObject(),"certificates",None) 186 self._v_department_certificates[d.getId] = certificates_folder.objectIds() 187 department_id = mapping['department_code'] 188 msg = '' 189 certificate_id = mapping.get('code') 190 while True: 191 department_certificates = self._v_department_certificates.get(department_id,None) 192 if department_certificates is None: 193 msg = "No Department with ID: %s" % department_id 194 break 192 195 if certificate_id in self._v_certificate_list: 193 msg = "duplicate certificate id: %s" % did 194 break 195 c = getattr(d,certificate_id,None) 196 if c is not None: 197 msg = "duplicate certificate id: %s" % did 196 msg = "Duplicate Certificate ID: %s" % department_id 197 break 198 if certificate_id in department_certificates: 199 msg = "Duplicate Certificate ID: %s" % department_id 198 200 break 199 201 try: … … 267 269 def edit(self,mapping): ###( 268 270 course_id = mapping.get('code','') 269 res = self.portal_catalog(id=course_id)270 while True: 271 if not res:271 course = self.courses_catalog.getRecordByKey(course_id) 272 while True: 273 if course is None: 272 274 msg = "no course with id: %s" % course_id 273 275 break 274 c = res[0].getObject()275 c .getContent().edit(mapping=mapping)276 course_object = getattr(getattr(self.academics_folder,course.department),course_id) 277 course_object.getContent().edit(mapping=mapping) 276 278 break 277 279 return course_id,msg,mapping … … 289 291 id_field_found = False 290 292 msg = '' 293 student_record = None 294 id_count = 0 291 295 for id_key in ('id','matric_no'): 292 296 id_field = mapping.get(id_key,'') 293 297 if id_field: 294 if id_field_found: 295 msg = "%s must not be provided" % id_key 296 break 298 id_count += 1 297 299 search_key = id_key 298 300 search_field = id_field 299 id_field_found = True 300 #if search_key == "student_id": 301 # search_key = 'id' 302 if not id_field_found: 303 msg = "neither id nor matric_no provided" 304 return None,msg 305 query = Eq(search_key,search_field) 306 res = self.students_catalog.evalAdvancedQuery(query) 307 student_record = None 308 if res: 309 student_record = res[0] 310 if search_key == "matric_no": 311 mapping['id'] = student_record.id 312 elif search_key == "id": 313 mapping['matric_no'] = student_record.matric_no 314 else: 315 msg = "no student with %(search_key)s %(search_field)s" % vars() 301 while True: 302 if id_count > 1: 303 msg = "both id and matric_no are provided" 304 break 305 elif id_count == 0: 306 msg = "neither id nor matric_no provided" 307 break 308 query = Eq(search_key,search_field) 309 res = self.students_catalog.evalAdvancedQuery(query) 310 if res: 311 student_record = res[0] 312 if search_key == "matric_no": 313 mapping['id'] = student_record.id 314 elif search_key == "id": 315 mapping['matric_no'] = student_record.matric_no 316 else: 317 msg = "no student with %(search_key)s %(search_field)s" % vars() 318 break 316 319 return student_record,msg 317 320 ###) … … 337 340 break 338 341 student_id = student_record.id 339 level_id = mapping ['level_id']340 code = mapping ['code']342 level_id = mapping.get('level_id','') 343 code = mapping.get('code','') 341 344 if student_id not in self._v_level_created: 342 345 try: … … 374 377 375 378 def edit(self,mapping): ###( 376 #import pdb;pdb.set_trace()377 379 msg = '' 378 380 key = '' … … 381 383 if msg: 382 384 break 383 if not mapping.get('level_id',''): 384 msg = "level_id is missing" 385 break 386 if not mapping.get('code',''): 387 msg = "code is missing" 388 break 389 student_id = student_record.id 390 level_id = mapping['level_id'] 385 level_id = mapping.get('level_id','') 386 code = mapping.get('code','') 391 387 code = mapping['code'] 392 388 mapping['key'] = key = "%(student_id)s|%(level_id)s|%(code)s" % vars() … … 406 402 if msg: 407 403 break 408 if not mapping.get('level_id',''):409 msg = "level_id is missing"410 break411 if not mapping.get('code',''):412 msg = "code is missing"413 break414 404 student_id = student_record.id 415 level_id = mapping ['level_id']416 code = mapping ['code']405 level_id = mapping.get('level_id','') 406 code = mapping.get('code','') 417 407 key = "%(student_id)s|%(level_id)s|%(code)s" % vars() 418 408 if self.course_results.getRecordByKey(key) is None: -
WAeUP_SRP/base/WAeUPTool.py
r3219 r3248 1478 1478 total += 1 1479 1479 import_mode = item.get('import_mode','edit') 1480 if (import_mode in importer.required_modes and1481 not set(importer.required_keys[import_mode]).issubset(set(import_keys))):1482 diff2import = set(importer.required_keys[import_mode]).difference(set(import_keys))1483 error_string += 'required key(s): "%s" not found in heading' % ", ".join(diff2import)1484 1480 import_method = getattr(importer, '%(import_mode)s' % vars(),None ) 1485 1481 if import_method is None: 1486 1482 error_string += "no %(import_mode)s " % vars() 1483 elif (import_mode in importer.required_modes and 1484 not set(importer.required_keys[import_mode]).issubset(set(item.keys()))): 1485 diff2import = set(importer.required_keys[import_mode]).difference(set(item.keys())) 1486 error_string += 'required key(s): "%s" not found in record' % ", ".join(diff2import) 1487 1487 else: 1488 1488 for k in import_keys:
Note: See TracChangeset for help on using the changeset viewer.