Changeset 723 for WAeUP_SRP/trunk/Students.py
- Timestamp:
- 19 Oct 2006, 17:06:51 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/trunk/Students.py
r714 r723 23 23 MAX_TRANS = 1000 24 24 25 def getInt(s): 26 try: 27 return int(s) 28 except: 29 return 0 25 30 26 31 def getStudentByRegNo(self,reg_no): ###( … … 152 157 dsc = {} 153 158 dsc['study_course'] = certcode 159 dsc['department'] = student.get('Dept') 160 dsc['faculty'] = student.get('Faculty') 154 161 css = student.get('CurrentSession') or '2004-2005' 155 162 cs = int(css.split('-')[0]) - 2000 … … 161 168 # Level 162 169 # 163 l = getattr(studycourse,level,None) 164 if l is None: 165 #self.log('Creating Department %(DeptCode)s = %(Description)s' % dep) 166 logger.info('Creating Level %(StudentLevel)s for %(fullname)s' % student) 167 studycourse.invokeFactory('StudentStudyLevel', level) 168 l = getattr(studycourse, level) 169 certificate = certs[certcode] 170 cert_level = getattr(certificate,level,None) 171 if cert_level is None: 172 logger.info('Level %(level)s not in %(certcode)s' % vars()) 173 l.getContent().edit(mapping={'Title': "Level %s" % level}) 174 ## l.invokeFactory('StudentSemester','first') 175 ## l.invokeFactory('StudentSemester','second') 176 ## first_s = getattr(l,'first') 177 ## first_s.getContent().edit(mapping={'Title': 'First Semester'}) 178 ## second_s = getattr(l,'second') 179 ## second_s.getContent().edit(mapping={'Title': 'Second Semester'}) 170 ## l = getattr(studycourse,level,None) 171 ## if 0 and l is None: 172 ## #self.log('Creating Department %(DeptCode)s = %(Description)s' % dep) 173 ## logger.info('Creating Level %(StudentLevel)s for %(fullname)s' % student) 174 ## studycourse.invokeFactory('StudentStudyLevel', level) 175 ## l = getattr(studycourse, level) 176 ## certificate = certs[certcode] 177 ## cert_level = getattr(certificate,level,None) 178 ## if cert_level is None: 179 ## logger.info('Level %(level)s not in %(certcode)s' % vars()) 180 ## l.getContent().edit(mapping={'Title': "Level %s" % level}) 180 181 else: 181 182 em = 'Student with ID %(MatricNo)s %(fullname)s already exists\n' % student … … 207 208 """load Fulltime Studentdata from CSV values""" 208 209 #return 210 level_wf_actions = {} 211 level_wf_actions["SUCCESSFUL STUDENT"] = "pass_A" 212 level_wf_actions["STUDENT WITH CARRYOVER COURSES"] = "pass_B" 213 level_wf_actions["STUDENT FOR PROBATION"] = "pass_C" 214 level_wf_actions["STUDENT ON PROBATION/TRANSFER"] = "pass_D" 209 215 import transaction 216 wftool = self.portal_workflow 210 217 tr_count = 0 211 218 name = 'short_full_time_results_2004_2005' … … 226 233 for c in l: 227 234 courses[c.id] = c.getObject() 235 level_changed = False 236 student_changed = False 237 sid = '' 238 #import pdb;pdb.set_trace() 228 239 for result in results: 229 sid = result.get('Matnumber') 230 res = self.portal_catalog({'meta_type': "StudentClearance", 231 'matric_no': sid }) 232 if not res: 233 em = 'Student with ID %(Matnumber)s not found\n' % result 234 logger.info(em) 235 no_import.write(em) 236 no_import.write('"%(Matnumber)s","%(CosCode)s","%(Ansbook)s","%(CosStuatus)s","%(Session)s","%(Mat_Cos)s","%(Score)s","%(CarryLevel)s","%(Grade)s","%(Weight)s","%(Semster)s","%(Verdict)s","%(Level)s","%(id)s","%(GPA)s"\n' % result) 237 continue 238 sf = res[0].getObject().aq_parent 239 result['StudentId'] = sf.getId() 240 temp_sid = result.get('Matnumber') 241 if temp_sid != sid: 242 student_changed = True 243 res = self.portal_catalog({'meta_type': "StudentClearance", 244 'SearchableText': temp_sid }) 245 if not res: 246 em = 'Student with ID %(Matnumber)s not found\n' % result 247 logger.info(em) 248 no_import.write(em) 249 no_import.write('"%(Matnumber)s","%(CosCode)s","%(Ansbook)s","%(CosStuatus)s","%(Session)s","%(Mat_Cos)s","%(Score)s","%(CarryLevel)s","%(Grade)s","%(Weight)s","%(Semster)s","%(Verdict)s","%(Level)s","%(id)s","%(GPA)s"\n' % result) 250 continue 251 elif len(res) > 1: 252 em = 'More than one Student with ID %(Matnumber)s found\n' % result 253 logger.info(em) 254 no_import.write(em) 255 no_import.write('"%(Matnumber)s","%(CosCode)s","%(Ansbook)s","%(CosStuatus)s","%(Session)s","%(Mat_Cos)s","%(Score)s","%(CarryLevel)s","%(Grade)s","%(Weight)s","%(Semster)s","%(Verdict)s","%(Level)s","%(id)s","%(GPA)s"\n' % result) 256 continue 257 sid = temp_sid 258 sf = res[0].getObject().aq_parent 259 sc = getattr(sf,'study_course') 260 level = '' 261 else: 262 student_changed = False 240 263 course = result.get('CosCode') 241 264 if course not in courses.keys(): … … 245 268 no_import.write('"%(Matnumber)s","%(CosCode)s","%(Ansbook)s","%(CosStuatus)s","%(Session)s","%(Mat_Cos)s","%(Score)s","%(CarryLevel)s","%(Grade)s","%(Weight)s","%(Semster)s","%(Verdict)s","%(Level)s","%(id)s","%(GPA)s"\n' % result) 246 269 continue 247 level = result.get('Level') 248 try: 249 int(level) 250 except: 251 em = 'Result for result with ID %(Matnumber)s Course %(CosCode)s Level is empty\n' % result 252 logger.info(em) 253 no_import.write(em) 254 no_import.write('"%(Matnumber)s","%(CosCode)s","%(Ansbook)s","%(CosStuatus)s","%(Session)s","%(Mat_Cos)s","%(Score)s","%(CarryLevel)s","%(Grade)s","%(Weight)s","%(Semster)s","%(Verdict)s","%(Level)s","%(id)s","%(GPA)s"\n' % result) 255 continue 256 sc = getattr(sf,'study_course') 257 l = getattr(sc,level,None) 258 if l is None: 259 #self.log('Creating Department %(DeptCode)s = %(Description)s' % dep) 260 logger.info('Creating Level %(Level)s for %(StudentId)s %(Matnumber)s' % result) 261 sc.invokeFactory('StudentStudyLevel', level) 262 l = getattr(sc, level) 263 l.invokeFactory('StudentSemester','first') 264 l.invokeFactory('StudentSemester','second') 265 first_s = getattr(l,'first') 266 first_s.getContent().edit(mapping={'Title': 'First Semester'}) 267 second_s = getattr(l,'second') 268 second_s.getContent().edit(mapping={'Title': 'Second Semester'}) 269 snr = result.get('Semster') 270 semester = getattr(l,'first') 271 if snr == "2": 272 semester = getattr(l,'second') 273 logger.info('Creating StudentCourseResult %(CosCode)s in Level %(Level)s for %(StudentId)s %(Matnumber)s' % result) 274 semester.invokeFactory('StudentCourseResult',course) 275 ct = getattr(semester,course) 276 d = {} 270 temp_level = result.get('Level') 271 result['StudentId'] = sf.getId() 272 if temp_level != level: 273 try: 274 int(temp_level) 275 except: 276 em = 'Result with ID %(Matnumber)s Course %(CosCode)s Level is empty\n' % result 277 logger.info(em) 278 no_import.write(em) 279 no_import.write('"%(Matnumber)s","%(CosCode)s","%(Ansbook)s","%(CosStuatus)s","%(Session)s","%(Mat_Cos)s","%(Score)s","%(CarryLevel)s","%(Grade)s","%(Weight)s","%(Semster)s","%(Verdict)s","%(Level)s","%(id)s","%(GPA)s"\n' % result) 280 continue 281 if level_changed: 282 wftool.doActionFor(l,level_wf_actions[dlev['verdict']]) 283 level_changed = True 284 level = temp_level 285 l = getattr(sc,level,None) 286 if l is None: 287 logger.info('Creating Level %(Level)s for %(StudentId)s %(Matnumber)s' % result) 288 sc.invokeFactory('StudentStudyLevel', level) 289 l = getattr(sc, level) 290 else: 291 level_changed = False 292 cr = getattr(l,course,None) 293 if cr is None: 294 logger.info('Creating Course %(CosCode)s for %(StudentId)s %(Matnumber)s in Level %(Level)s' % result) 295 l.invokeFactory('StudentCourseResult',course) 296 cr = getattr(l,course) 297 dcr = {} 277 298 dlev = {} 278 d['ansbook'] = result.get('Ansbook') 279 d['status'] = result.get('CosStuatus') 280 d['score'] = result.get('Score') 299 dcr['ansbook'] = result.get('Ansbook') 300 dcr['semester'] = getInt(result.get('Semster')) 301 dcr['status'] = result.get('CosStuatus') 302 dcr['score'] = getInt(result.get('Score')) 281 303 dlev['session'] = result.get('Session') 282 d lev['carry_level'] = result.get('CarryLevel')283 d ['grade'] = result.get('Grade')304 dcr['carry_level'] = result.get('CarryLevel') 305 dcr['grade'] = result.get('Grade') 284 306 #d['weight'] = result.get('Weight') 285 307 dlev['verdict'] = result.get('Verdict') … … 287 309 #gpa = result.get('GPA').replace(',','.') 288 310 #d['gpa'] = float(gpa) 289 c t.getContent().edit(mapping = d)311 cr.getContent().edit(mapping = dcr) 290 312 l.getContent().edit(mapping = dlev) 291 313 if tr_count > MAX_TRANS: … … 293 315 tr_count = 0 294 316 tr_count += 1 317 wftool.doActionFor(cr,'close') 318 wftool.doActionFor(l,level_wf_actions[dlev['verdict']]) 295 319 return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) 296 320 … … 564 588 return "Level %s" % self.aq_parent.getId() 565 589 566 security.declareProtected(View,"gpa")567 def gpa(self):568 """calculate the gpa"""569 sum = 0570 course_count = 0571 for semester in ('first','second'):572 sf=getattr(self,semester)573 for sc in sf.objectValues():574 result = sc.getContent() 575 576 577 578 579 580 581 582 if course_count:583 return sum/course_count584 return 0.0590 ## security.declarePublic("gpa") 591 ## def gpa(self): 592 ## """calculate the gpa""" 593 ## sum = 0 594 ## course_count = 0 595 ## for sc in self.objectValues(): 596 ## result = sc.getContent() 597 ## if not result.grade: 598 ## continue 599 ## res = self.portal_catalog({'meta_type': 'Course', 600 ## 'id': sc.aq_parent.id}) 601 ## if len(res) != 1: 602 ## continue 603 ## course = res[0].getObject().getContent() 604 ## sum += course.credits * ['F','E','D','C','B','A'].index(result.grade) 605 ## course_count += 1 606 ## if course_count: 607 ## return sum/course_count 608 ## return 0.0 585 609 586 610 InitializeClass(StudentStudyLevel) … … 683 707 684 708 def getCourseEntry(self,cid): 685 res = self.portal_catalog({'meta_type': " StudentCourse",709 res = self.portal_catalog({'meta_type': "Course", 686 710 'id': cid}) 687 711 if res: … … 693 717 def Title(self): 694 718 """compose title""" 695 cid = self. getId()719 cid = self.aq_parent.getId() 696 720 ce = self.getCourseEntry(cid) 697 721 if ce:
Note: See TracChangeset for help on using the changeset viewer.