Changeset 714 for WAeUP_SRP/trunk/Students.py
- Timestamp:
- 17 Oct 2006, 11:20:25 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/trunk/Students.py
r710 r714 23 23 MAX_TRANS = 1000 24 24 25 def generateStudentId(letter): 26 import random 27 r = random 28 if letter not in ('ABCDEFGIHKLMNOPQRSTUVWXY'): 29 letter= r.choice('ABCDEFGHKLMNPQRSTUVWXY') 30 students = context.portal_catalog(meta_type = "StudentsFolder")[-1] 31 sid = "%c%d" % (letter,r.randint(99999,1000000)) 32 while hasattr(students, sid): 33 sid = "%c%d" % (letter,r.randint(99999,1000000)) 34 return sid 35 #return "%c%d" % (r.choice('ABCDEFGHKLMNPQRSTUVWXY'),r.randint(99999,1000000)) 36 37 def getStudentByRegNo(self,reg_no): 25 26 def getStudentByRegNo(self,reg_no): ###( 38 27 """search student by JAMB Reg No and return StudentFolder""" 39 28 search = ZCatalog.searchResults(self.portal_catalog,{'meta_type': 'StudentApplication', … … 43 32 return None 44 33 return search[0].getObject().aq_parent 34 35 ###) 45 36 46 37 class StudentsFolder(CPSDocument): ###( … … 111 102 if matric_no not in matrics: 112 103 matrics.append(matric_no) 113 sid = generateStudentId(student.get('Lastname')[0])104 sid = self.generateStudentId(student.get('Lastname')[0]) 114 105 #self.log('Creating Faculty %(id)s = %(Title)s' % faculty) 106 students_folder.invokeFactory('Student', sid) 115 107 logger.info('%(tr_count)s: Creating Student with ID %(sid)s Matric_no %(matric_no)s ' % vars()) 116 not_created = True 117 while not_created: 118 try: 119 students_folder.invokeFactory('Student', sid) 120 not_created = False 121 except BadRequest: 122 sid = generateStudentId() 123 logger.info('%(tr_count)s: Creating Student with ID %(sid)s Matric_no %(matric_no)s ' % vars()) 124 s = getattr(self,sid) 108 student_obj = getattr(self,sid) 125 109 access_code = "%d" % random.randint(1000000000,9999999999) 126 110 self.portal_registration.addMember(sid, … … 129 113 'Student',)) 130 114 pwl_dict = {'student_id': sid,'access_code':access_code} 131 s.invokeFactory('StudentApplication','application') 115 student_obj.invokeFactory('StudentApplication','application') 116 application = student_obj.application 132 117 da = {'Title': 'Application Data'} 133 s .invokeFactory('StudentPersonal','personal')118 student_obj.invokeFactory('StudentPersonal','personal') 134 119 da['jamb_reg_no'] = student.get('EntryRegNo') 135 sp = s.personal120 personal = student_obj.personal 136 121 dp = {'Title': 'Personal Data'} 137 s .invokeFactory('StudentClearance','clearance')138 sc = s.clearance122 student_obj.invokeFactory('StudentClearance','clearance') 123 clearance = student_obj.clearance 139 124 dc = {'Title': 'Clearance Data'} 140 125 dc['matric_no'] = matric_no 141 lga = student.get('State') + ' / ' + student.get('LGA') 126 state = student.get('State') 127 lga = student.get('LGA') 128 if state and lga: 129 lga = state + ' / ' + lga 130 else: 131 lga = "None" 142 132 dc['lga'] = lga 143 133 dc['nationality'] = student.get('Nationality') … … 152 142 dp['campus_address'] = student.get('CampusAddress') 153 143 dp['phone'] = student.get('PhoneNumber') 154 s.application.getContent().edit(mapping=da)155 sp.getContent().edit(mapping=dp)156 sc.getContent().edit(mapping=dc)144 application.getContent().edit(mapping=da) 145 personal.getContent().edit(mapping=dp) 146 clearance.getContent().edit(mapping=dc) 157 147 # 158 148 # Study Course 159 149 # 160 s .invokeFactory('StudentStudyCourse','study_course')161 s c = s.study_course150 student_obj.invokeFactory('StudentStudyCourse','study_course') 151 studycourse = student_obj.study_course 162 152 dsc = {} 163 153 dsc['study_course'] = certcode 164 154 css = student.get('CurrentSession') or '2004-2005' 165 155 cs = int(css.split('-')[0]) - 2000 166 cl = int(student.get('StudentLevel') )/100156 cl = int(student.get('StudentLevel') or '100')/100 167 157 dsc['entry_session'] = "200%s" % (cs - cl) 168 158 dsc['clr_ac_pin'] = access_code 169 s c.getContent().edit(mapping=dsc)159 studycourse.getContent().edit(mapping=dsc) 170 160 # 171 161 # Level 172 162 # 173 l = getattr(s c,level,None)163 l = getattr(studycourse,level,None) 174 164 if l is None: 175 165 #self.log('Creating Department %(DeptCode)s = %(Description)s' % dep) 176 166 logger.info('Creating Level %(StudentLevel)s for %(fullname)s' % student) 177 s c.invokeFactory('StudentStudyLevel', level)178 l = getattr(s c, level)167 studycourse.invokeFactory('StudentStudyLevel', level) 168 l = getattr(studycourse, level) 179 169 certificate = certs[certcode] 180 170 cert_level = getattr(certificate,level,None) … … 193 183 no_import.write(em) 194 184 no_import.write('"%(MatricNo)s","%(EntryRegNo)s","%(CurrentSession)s","%(StudentLevel)s","%(fullname)s","%(FirstName)s","%(MiddleName)s","%(Lastname)s","%(FormerSurname)s","%(Sex)s","%(Nationality)s","%(State)s","%(LGA)s","%(PermanentAddress)s","%(PermanentAddressCity)s","%(CampusAddress)s","%(PhoneNumber)s","%(Emailaddress)s","%(Mode)s","%(CourseMajor)s","%(Faculty)s","%(Dept)s"\n' % student) 185 continue 195 186 if tr_count > MAX_TRANS: 196 187 transaction.commit() … … 202 193 pwl_dict.update(da) 203 194 pwl_dict.update(dp) 195 wftool = self.portal_workflow 204 196 pwlist.append(pwl_template.substitute(pwl_dict)) 197 wftool.doActionFor(student_obj,'clear_and_validate') 198 wftool.doActionFor(application,'close') 199 wftool.doActionFor(clearance,'close') 200 wftool.doActionFor(personal,'close') 201 open("%s/import/pwlist-%s.csv" % (i_home,name),"w+").write('\n'.join(pwlist)) 205 202 return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) 206 203 ###) … … 335 332 names = jamb_name.split() 336 333 letter = names[-1][0].upper() 337 sid = generateStudentId(letter) 338 #self.log('Creating Faculty %(id)s = %(Title)s' % faculty) 334 sid = self.generateStudentId(letter) 339 335 not_created = True 340 336 while not_created: … … 343 339 not_created = False 344 340 except BadRequest: 345 sid = generateStudentId(letter)341 sid = self.generateStudentId(letter) 346 342 logger.info('%(tr_count)s: Creating Student with ID %(sid)s REG-NO %(jamb_reg_no)s ' % vars()) 347 343 student = getattr(self,sid) … … 383 379 """compose title""" 384 380 return "Student Section" 381 382 def generateStudentId(self,letter): ###( 383 import random 384 r = random 385 if letter not in ('ABCDEFGIHKLMNOPQRSTUVWXY'): 386 letter= r.choice('ABCDEFGHKLMNPQRSTUVWXY') 387 students = self.portal_catalog(meta_type = "StudentsFolder")[-1] 388 sid = "%c%d" % (letter,r.randint(99999,1000000)) 389 while hasattr(students, sid): 390 sid = "%c%d" % (letter,r.randint(99999,1000000)) 391 return sid 392 #return "%c%d" % (r.choice('ABCDEFGHKLMNPQRSTUVWXY'),r.randint(99999,1000000)) 393 ###) 385 394 386 395 InitializeClass(StudentsFolder)
Note: See TracChangeset for help on using the changeset viewer.