Changeset 6825 for main/waeup.sirp/trunk/src/waeup/sirp
- Timestamp:
- 28 Sep 2011, 17:08:45 (13 years ago)
- 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
r6821 r6825 9 9 import grok 10 10 from zope.interface import Interface 11 from waeup.sirp.interfaces import IBatchProcessor 12 from waeup.sirp.students.interfaces import IStudent 11 from zope.schema import getFields 12 from zope.component import queryUtility 13 from zope.catalog.interfaces import ICatalog 14 from waeup.sirp.interfaces import IBatchProcessor, FatalCSVError 15 from waeup.sirp.students.interfaces import ( 16 IStudent, IStudentStudyCourse, IStudentStudyCourseImport) 13 17 from waeup.sirp.utils.batching import BatchProcessor 14 18 … … 66 70 del parent[row['student_id']] 67 71 pass 72 73 class StudentStudyCourseProcessor(BatchProcessor): 74 """A batch processor for IStudentStudyCourse objects. 75 """ 76 grok.implements(IBatchProcessor) 77 grok.provides(IBatchProcessor) 78 grok.context(Interface) 79 util_name = 'studycourseimporter' 80 grok.name(util_name) 81 82 name = u'StudentStudyCourse Importer' 83 iface = IStudentStudyCourseImport 84 factory_name = 'waeup.StudentStudyCourse' 85 86 @property 87 def available_fields(self): 88 result = [] 89 return sorted(list(set( 90 ['student_id','reg_number'] + getFields(self.iface).keys()))) 91 92 def checkHeaders(self, headerfields, mode='update'): 93 if not 'reg_number' in headerfields or 'student_id' in headerfields: 94 raise FatalCSVError( 95 "Need at least columns student_id or reg_number for import!") 96 # Check for double fields... 97 not_ignored_fields = [x for x in headerfields 98 if not x.startswith('--')] 99 if len(set(not_ignored_fields)) < len(not_ignored_fields): 100 raise FatalCSVError( 101 "Double headers: each column name may only appear once.") 102 return True 103 104 def parentsExist(self, row, site): 105 if not 'students' in site.keys(): 106 return False 107 if 'student_id' in row.keys(): 108 if row['student_id'] in site['students']: 109 student = site['students'][row['student_id']] 110 return student 111 else: 112 # Here we know that the reg_number is in row 113 reg_number = row['reg_number'] 114 cat = queryUtility(ICatalog, name='students_catalog') 115 results = list( 116 cat.searchResults(reg_number=(reg_number, reg_number))) 117 if results: 118 return results[0] 119 return False 120 121 def entryExists(self, row, site): 122 student = self.parentsExist(row, site) 123 if not student: 124 return False 125 if 'studycourse' in student: 126 return student 127 return False 128 129 def getEntry(self, row, site): 130 student = self.entryExists(row, site) 131 if not student: 132 return None 133 return student.get('studycourse') -
main/waeup.sirp/trunk/src/waeup/sirp/students/interfaces.py
r6818 r6825 206 206 ) 207 207 208 class IStudentStudyCourseImport(IStudentStudyCourse): 209 """A container for student study levels. 210 211 """ 212 213 current_level = schema.Int( 214 title = u'Current Level', 215 default = None, 216 ) 217 208 218 class IStudentStudyLevel(IWAeUPObject): 209 219 """A container for course tickets.
Note: See TracChangeset for help on using the changeset viewer.