1 | #-*- mode: python; mode: fold -*- |
---|
2 | # $Id: Students.py 727 2006-10-20 13:06:08Z joachim $ |
---|
3 | from string import Template |
---|
4 | from Globals import InitializeClass |
---|
5 | from AccessControl import ClassSecurityInfo |
---|
6 | from AccessControl.SecurityManagement import newSecurityManager |
---|
7 | from zExceptions import BadRequest |
---|
8 | from Products.ZCatalog.ZCatalog import ZCatalog |
---|
9 | from Products.CMFCore.utils import UniqueObject, getToolByName |
---|
10 | from Products.CMFCore.permissions import View |
---|
11 | from Products.CMFCore.permissions import ModifyPortalContent |
---|
12 | from Products.CPSCore.CPSBase import CPSBase_adder, CPSBaseFolder |
---|
13 | #from Products.CPSCore.CPSBase import CPSBaseDocument as BaseDocument |
---|
14 | from Products.CPSDocument.CPSDocument import CPSDocument |
---|
15 | from Products.CPSCore.CPSBase import CPSBaseBTreeFolder as BaseBTreeFolder |
---|
16 | from Products.CPSCore.CPSMembershipTool import CPSUnrestrictedUser |
---|
17 | from Products.WAeUP_SRP.Academics import makeCertificateCode |
---|
18 | import logging |
---|
19 | import csv,re |
---|
20 | import Globals |
---|
21 | p_home = Globals.package_home(globals()) |
---|
22 | i_home = Globals.INSTANCE_HOME |
---|
23 | MAX_TRANS = 1000 |
---|
24 | |
---|
25 | def getInt(s): |
---|
26 | try: |
---|
27 | return int(s) |
---|
28 | except: |
---|
29 | return 0 |
---|
30 | |
---|
31 | def getFloat(s): |
---|
32 | try: |
---|
33 | return float(s) |
---|
34 | except: |
---|
35 | return 0.0 |
---|
36 | |
---|
37 | def getStudentByRegNo(self,reg_no): ###( |
---|
38 | """search student by JAMB Reg No and return StudentFolder""" |
---|
39 | search = ZCatalog.searchResults(self.portal_catalog,{'meta_type': 'StudentApplication', |
---|
40 | 'SearchableText': reg_no, |
---|
41 | }) |
---|
42 | if len(search) < 1: |
---|
43 | return None |
---|
44 | return search[0].getObject().aq_parent |
---|
45 | |
---|
46 | ###) |
---|
47 | |
---|
48 | class StudentsFolder(CPSDocument): ###( |
---|
49 | """ |
---|
50 | WAeUP container for the various WAeUP containers data |
---|
51 | """ |
---|
52 | meta_type = 'StudentsFolder' |
---|
53 | portal_type = meta_type |
---|
54 | security = ClassSecurityInfo() |
---|
55 | |
---|
56 | security.declareProtected(ModifyPortalContent,"loadFullTimeStudentsFromCSV")###( |
---|
57 | def loadFullTimeStudentsFromCSV(self): |
---|
58 | """load Fulltime Studentdata from CSV values""" |
---|
59 | import transaction |
---|
60 | import random |
---|
61 | tr_count = 0 |
---|
62 | name = 'short_full_time' |
---|
63 | no_import = False |
---|
64 | if not no_import: |
---|
65 | no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w") |
---|
66 | no_import.write('"MatricNo","EntryRegNo","CurrentSession","StudentLevel","fullname","FirstName","MiddleName","Lastname","FormerSurname","Sex","Nationality","State","LGA","PermanentAddress","PermanentAddressCity","CampusAddress","PhoneNumber","Emailaddress","Mode","CourseMajor","Faculty","Dept"\n') |
---|
67 | logger = logging.getLogger('%s_import' % name) |
---|
68 | logger.info('Start loading from %s.csv' % name) |
---|
69 | pwlist = [] |
---|
70 | pwlist.append('"student_id","firstname","middlename","lastname","matric_no","jamb_reg_no","access_code"') |
---|
71 | pwl_template = Template('"$student_id","$firstname","$middlename","$lastname","$matric_no","$jamb_reg_no","$access_code"') |
---|
72 | students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() |
---|
73 | try: |
---|
74 | students = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
75 | except: |
---|
76 | logger.error('Error reading %s.csv' % name) |
---|
77 | return |
---|
78 | l = self.portal_catalog({'meta_type': "StudentClearance",}) |
---|
79 | matrics = [] |
---|
80 | for s in l: |
---|
81 | matrics.append(s.getObject().getContent().matric_no) |
---|
82 | print matrics |
---|
83 | l = self.portal_catalog({'meta_type': "Certificate"}) |
---|
84 | certs = {} |
---|
85 | for c in l: |
---|
86 | ca,ac,fa,dep_id,co,certcode = c.relative_path.split('/') |
---|
87 | cid = "%(dep_id)s_%(certcode)s" % vars() |
---|
88 | certs[cid] = c.getObject() |
---|
89 | for student in students: |
---|
90 | logger.info('processing "%(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) |
---|
91 | sid = student.get('MatricNo') |
---|
92 | if sid == "": |
---|
93 | em = 'Empty MatricNo\n' |
---|
94 | logger.info(em) |
---|
95 | no_import.write(em) |
---|
96 | 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) |
---|
97 | continue |
---|
98 | certcode = makeCertificateCode(student.get('CourseMajor')) |
---|
99 | dep_id = student.get('Dept') |
---|
100 | fac_id = student.get('Faculty') |
---|
101 | cid = "%(dep_id)s_%(certcode)s" % vars() |
---|
102 | if cid not in certs.keys(): |
---|
103 | em = 'Certificate with ID %s %s not found\n' % (certcode, student.get('CourseMajor')) |
---|
104 | logger.info(em) |
---|
105 | no_import.write(em) |
---|
106 | 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) |
---|
107 | continue |
---|
108 | certificate_doc = certs[cid].getContent() |
---|
109 | level = student.get('StudentLevel') |
---|
110 | try: |
---|
111 | int(level) |
---|
112 | except: |
---|
113 | em = 'Student with ID %(MatricNo)s StudentLevel is empty\n' % student |
---|
114 | logger.info(em) |
---|
115 | no_import.write(em) |
---|
116 | 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) |
---|
117 | continue |
---|
118 | matric_no = student.get('MatricNo') |
---|
119 | if matric_no not in matrics: |
---|
120 | matrics.append(matric_no) |
---|
121 | sid = self.generateStudentId(student.get('Lastname')[0]) |
---|
122 | #self.log('Creating Faculty %(id)s = %(Title)s' % faculty) |
---|
123 | students_folder.invokeFactory('Student', sid) |
---|
124 | logger.info('%(tr_count)s: Creating Student with ID %(sid)s Matric_no %(matric_no)s ' % vars()) |
---|
125 | student_obj = getattr(self,sid) |
---|
126 | access_code = "%d" % random.randint(1000000000,9999999999) |
---|
127 | self.portal_registration.addMember(sid, |
---|
128 | access_code , |
---|
129 | roles=('Member', |
---|
130 | 'Student',)) |
---|
131 | pwl_dict = {'student_id': sid,'access_code':access_code} |
---|
132 | student_obj.invokeFactory('StudentApplication','application') |
---|
133 | application = student_obj.application |
---|
134 | da = {'Title': 'Application Data'} |
---|
135 | student_obj.invokeFactory('StudentPersonal','personal') |
---|
136 | da['jamb_reg_no'] = student.get('EntryRegNo') |
---|
137 | personal = student_obj.personal |
---|
138 | dp = {'Title': 'Personal Data'} |
---|
139 | student_obj.invokeFactory('StudentClearance','clearance') |
---|
140 | clearance = student_obj.clearance |
---|
141 | dc = {'Title': 'Clearance Data'} |
---|
142 | dc['matric_no'] = matric_no |
---|
143 | state = student.get('State') |
---|
144 | lga = student.get('LGA') |
---|
145 | if state and lga: |
---|
146 | lga = state + ' / ' + lga |
---|
147 | else: |
---|
148 | lga = "None" |
---|
149 | dc['lga'] = lga |
---|
150 | dc['nationality'] = student.get('Nationality') |
---|
151 | dc['email'] = student.get('Emailaddress') |
---|
152 | dp['firstname'] = student.get('FirstName') |
---|
153 | dp['middlename'] = student.get('MiddleName') |
---|
154 | dp['lastname'] = student.get('Lastname') |
---|
155 | dp['former_surname'] = student.get('FormerSurname') |
---|
156 | dp['sex'] = student.get('Sex') == 'F' |
---|
157 | dp['perm_address'] = student.get('PermanentAddress') |
---|
158 | dp['perm_city'] = student.get('PermanentAddressCity') |
---|
159 | dp['campus_address'] = student.get('CampusAddress') |
---|
160 | dp['phone'] = student.get('PhoneNumber') |
---|
161 | application.getContent().edit(mapping=da) |
---|
162 | personal.getContent().edit(mapping=dp) |
---|
163 | clearance.getContent().edit(mapping=dc) |
---|
164 | # |
---|
165 | # Study Course |
---|
166 | # |
---|
167 | student_obj.invokeFactory('StudentStudyCourse','study_course') |
---|
168 | studycourse = student_obj.study_course |
---|
169 | dsc = {} |
---|
170 | from_certificate = ['title', |
---|
171 | 'max_elect', |
---|
172 | 'max_pass', |
---|
173 | 'n_core', |
---|
174 | 'nr_years', |
---|
175 | 'probation_credits', |
---|
176 | 'promotion_credits', |
---|
177 | 'start_level', |
---|
178 | ] |
---|
179 | for f in from_certificate: |
---|
180 | dsc[f] = getattr(certificate_doc,f) |
---|
181 | dsc['faculty'] = fac_id |
---|
182 | dsc['department'] = dep_id |
---|
183 | dsc['study_course'] = certcode |
---|
184 | css = student.get('CurrentSession') or '2004-2005' |
---|
185 | cs = int(css.split('-')[0]) - 2000 |
---|
186 | cl = int(student.get('StudentLevel') or '100')/100 |
---|
187 | dsc['entry_session'] = "200%s" % (cs - cl) |
---|
188 | dsc['clr_ac_pin'] = access_code |
---|
189 | studycourse.getContent().edit(mapping=dsc) |
---|
190 | # |
---|
191 | # Level |
---|
192 | # |
---|
193 | ## l = getattr(studycourse,level,None) |
---|
194 | ## if 0 and l is None: |
---|
195 | ## #self.log('Creating Department %(DeptCode)s = %(Description)s' % dep) |
---|
196 | ## logger.info('Creating Level %(StudentLevel)s for %(fullname)s' % student) |
---|
197 | ## studycourse.invokeFactory('StudentStudyLevel', level) |
---|
198 | ## l = getattr(studycourse, level) |
---|
199 | ## certificate = certs[certcode] |
---|
200 | ## cert_level = getattr(certificate,level,None) |
---|
201 | ## if cert_level is None: |
---|
202 | ## logger.info('Level %(level)s not in %(certcode)s' % vars()) |
---|
203 | ## l.getContent().edit(mapping={'Title': "Level %s" % level}) |
---|
204 | else: |
---|
205 | em = 'Student with ID %(MatricNo)s %(fullname)s already exists\n' % student |
---|
206 | logger.info(em) |
---|
207 | no_import.write(em) |
---|
208 | 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) |
---|
209 | continue |
---|
210 | if tr_count > MAX_TRANS: |
---|
211 | transaction.commit() |
---|
212 | em = 'Transaction commited\n' % student |
---|
213 | logger.info(em) |
---|
214 | tr_count = 0 |
---|
215 | tr_count += 1 |
---|
216 | pwl_dict.update(dc) |
---|
217 | pwl_dict.update(da) |
---|
218 | pwl_dict.update(dp) |
---|
219 | wftool = self.portal_workflow |
---|
220 | pwlist.append(pwl_template.substitute(pwl_dict)) |
---|
221 | wftool.doActionFor(student_obj,'clear_and_validate') |
---|
222 | wftool.doActionFor(application,'close') |
---|
223 | wftool.doActionFor(clearance,'close') |
---|
224 | wftool.doActionFor(personal,'close') |
---|
225 | wftool.doActionFor(studycourse,'close_for_edit') |
---|
226 | open("%s/import/pwlist-%s.csv" % (i_home,name),"w+").write('\n'.join(pwlist)) |
---|
227 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
228 | ###) |
---|
229 | |
---|
230 | security.declareProtected(ModifyPortalContent,"loadFullTimeStudentsResultsFromCSV") ###( |
---|
231 | def loadFullTimeStudentsResultsFromCSV(self): |
---|
232 | """load Fulltime Studentdata from CSV values""" |
---|
233 | #return |
---|
234 | level_wf_actions = {} |
---|
235 | level_wf_actions["SUCCESSFUL STUDENT"] = "pass_A" |
---|
236 | level_wf_actions["STUDENT WITH CARRYOVER COURSES"] = "pass_B" |
---|
237 | level_wf_actions["STUDENT FOR PROBATION"] = "probate_C" |
---|
238 | level_wf_actions["STUDENT ON PROBATION/TRANSFER"] = "reject_D" |
---|
239 | import transaction |
---|
240 | wftool = self.portal_workflow |
---|
241 | tr_count = 0 |
---|
242 | name = 'short_full_time_results_2004_2005' |
---|
243 | no_import = False |
---|
244 | if not no_import: |
---|
245 | no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w") |
---|
246 | no_import.write('"Matnumber","CosCode","Ansbook","CosStuatus","Session","Mat_Cos","Score","CarryLevel","Grade","Weight","Semster","Verdict","Level","id","GPA"\n') |
---|
247 | logger = logging.getLogger('%s_import' % name) |
---|
248 | logger.info('Start loading from %s.csv' % name) |
---|
249 | students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() |
---|
250 | try: |
---|
251 | results = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
252 | except: |
---|
253 | logger.error('Error reading %s.csv' % name) |
---|
254 | return |
---|
255 | l = self.portal_catalog({'meta_type': "Course"}) |
---|
256 | courses = {} |
---|
257 | for c in l: |
---|
258 | courses[c.id] = c.getObject() |
---|
259 | level_changed = False |
---|
260 | student_changed = False |
---|
261 | sid = '' |
---|
262 | #import pdb;pdb.set_trace() |
---|
263 | for result in results: |
---|
264 | temp_sid = result.get('Matnumber') |
---|
265 | if temp_sid != sid: |
---|
266 | student_changed = True |
---|
267 | res = self.portal_catalog({'meta_type': "StudentClearance", |
---|
268 | 'SearchableText': temp_sid }) |
---|
269 | if not res: |
---|
270 | em = 'Student with ID %(Matnumber)s not found\n' % result |
---|
271 | logger.info(em) |
---|
272 | no_import.write(em) |
---|
273 | 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) |
---|
274 | continue |
---|
275 | elif len(res) > 1: |
---|
276 | em = 'More than one Student with ID %(Matnumber)s found\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 | sid = temp_sid |
---|
282 | sf = res[0].getObject().aq_parent |
---|
283 | sc = getattr(sf,'study_course') |
---|
284 | level = '' |
---|
285 | else: |
---|
286 | student_changed = False |
---|
287 | course = result.get('CosCode') |
---|
288 | if course not in courses.keys(): |
---|
289 | em = 'Course with ID %(CosCode)s not found\n' % result |
---|
290 | logger.info(em) |
---|
291 | no_import.write(em) |
---|
292 | 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) |
---|
293 | continue |
---|
294 | course_doc = courses[course].getContent() |
---|
295 | temp_level = result.get('Level') |
---|
296 | result['StudentId'] = sf.getId() |
---|
297 | if temp_level != level: |
---|
298 | try: |
---|
299 | int(temp_level) |
---|
300 | except: |
---|
301 | em = 'Result with ID %(Matnumber)s Course %(CosCode)s Level is empty\n' % result |
---|
302 | logger.info(em) |
---|
303 | no_import.write(em) |
---|
304 | 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) |
---|
305 | continue |
---|
306 | level_changed = True |
---|
307 | if 'dlev' in vars().keys(): |
---|
308 | wftool.doActionFor(l,level_wf_actions[dlev['verdict']]) |
---|
309 | level = temp_level |
---|
310 | l = getattr(sc,level,None) |
---|
311 | if l is None: |
---|
312 | logger.info('Creating Level %(Level)s for %(StudentId)s %(Matnumber)s' % result) |
---|
313 | sc.invokeFactory('StudentStudyLevel', level) |
---|
314 | l = getattr(sc, level) |
---|
315 | else: |
---|
316 | level_changed = False |
---|
317 | cr = getattr(l,course,None) |
---|
318 | if cr is None: |
---|
319 | logger.info('Creating Course %(CosCode)s for %(StudentId)s %(Matnumber)s in Level %(Level)s' % result) |
---|
320 | l.invokeFactory('StudentCourseResult',course) |
---|
321 | cr = getattr(l,course) |
---|
322 | dcr = {} |
---|
323 | from_course = ['title', |
---|
324 | 'credits', |
---|
325 | 'passmark', |
---|
326 | ] |
---|
327 | for f in from_course: |
---|
328 | dcr[f] = getattr(course_doc,f) |
---|
329 | dlev = {} |
---|
330 | dcr['ansbook'] = result.get('Ansbook') |
---|
331 | dcr['semester'] = getInt(result.get('Semster')) |
---|
332 | dcr['status'] = result.get('CosStuatus') |
---|
333 | dcr['score'] = getInt(result.get('Score')) |
---|
334 | dlev['session'] = result.get('Session') |
---|
335 | dcr['carry_level'] = result.get('CarryLevel') |
---|
336 | dcr['grade'] = result.get('Grade') |
---|
337 | dcr['weight'] = result.get('Weight') |
---|
338 | dlev['verdict'] = result.get('Verdict') |
---|
339 | dcr['import_id'] = result.get('id') |
---|
340 | gpa = result.get('GPA').replace(',','.') |
---|
341 | dlev['imported_gpa'] = getFloat(gpa) |
---|
342 | cr.getContent().edit(mapping = dcr) |
---|
343 | l.getContent().edit(mapping = dlev) |
---|
344 | if tr_count > MAX_TRANS: |
---|
345 | transaction.commit() |
---|
346 | tr_count = 0 |
---|
347 | tr_count += 1 |
---|
348 | wftool.doActionFor(cr,'close') |
---|
349 | wftool.doActionFor(l,level_wf_actions[dlev['verdict']]) |
---|
350 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
351 | |
---|
352 | ###) |
---|
353 | |
---|
354 | security.declareProtected(ModifyPortalContent,"loadJAMBFromCSV")###( |
---|
355 | def loadJAMBFromCSV(self): |
---|
356 | """load JAMB data from CSV values""" |
---|
357 | #return |
---|
358 | students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() |
---|
359 | import transaction |
---|
360 | tr_count = 0 |
---|
361 | name = 'SampleJAMBDataII' |
---|
362 | wftool = self.portal_workflow |
---|
363 | no_import = False |
---|
364 | if not no_import: |
---|
365 | no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w") |
---|
366 | no_import.write('REG-NO,NAME,SEX,STATE,LGA,ENG-SCORE,SUBJ1,SUBJ1-SCORE,SUBJ2,SUBJ2-SCORE,SUBJ3,SUBJ3-SCORE,AGGREGATE,UNIV1,FACULTY1,COURSE1,UNIV2,FACULTY2,COURSE2') |
---|
367 | logger = logging.getLogger('%s_import' % name) |
---|
368 | logger.info('Start loading from %s.csv' % name) |
---|
369 | try: |
---|
370 | result = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
371 | except: |
---|
372 | logger.error('Error reading %s.csv' % name) |
---|
373 | return |
---|
374 | for jamb in result: |
---|
375 | logger.info('processing %(REG-NO)s,%(NAME)s,%(SEX)s,%(STATE)s,%(LGA)s,%(ENG-SCORE)s,%(SUBJ1)s,%(SUBJ1-SCORE)s,%(SUBJ2)s,%(SUBJ2-SCORE)s,%(SUBJ3)s,%(SUBJ3-SCORE)s,%(AGGREGATE)s,%(UNIV1)s,%(FACULTY1)s,%(COURSE1)s,%(UNIV2)s,%(FACULTY2)s,%(COURSE2)s\n' % jamb) |
---|
376 | jamb_reg_no = jamb.get('REG-NO') |
---|
377 | res = self.portal_catalog({'meta_type': "StudentApplication", |
---|
378 | 'jamb_reg_no': jamb_reg_no }) |
---|
379 | if res: |
---|
380 | em = 'Student with REG-NO %(REG-NO)s already exists\n' % jamb |
---|
381 | logger.info(em) |
---|
382 | no_import.write(em) |
---|
383 | no_import.write('%(REG-NO)s,%(NAME)s,%(SEX)s,%(STATE)s,%(LGA)s,%(ENG-SCORE)s,%(SUBJ1)s,%(SUBJ1-SCORE)s,%(SUBJ2)s,%(SUBJ2-SCORE)s,%(SUBJ3)s,%(SUBJ3-SCORE)s,%(AGGREGATE)s,%(UNIV1)s,%(FACULTY1)s,%(COURSE1)s,%(UNIV2)s,%(FACULTY2)s,%(COURSE2)s\n' % jamb) |
---|
384 | continue |
---|
385 | jamb_name = jamb.get("NAME") |
---|
386 | jamb_name.replace('>','') |
---|
387 | names = jamb_name.split() |
---|
388 | letter = names[-1][0].upper() |
---|
389 | sid = self.generateStudentId(letter) |
---|
390 | not_created = True |
---|
391 | while not_created: |
---|
392 | try: |
---|
393 | students_folder.invokeFactory('Student', sid) |
---|
394 | not_created = False |
---|
395 | except BadRequest: |
---|
396 | sid = self.generateStudentId(letter) |
---|
397 | logger.info('%(tr_count)s: Creating Student with ID %(sid)s REG-NO %(jamb_reg_no)s ' % vars()) |
---|
398 | student = getattr(self,sid) |
---|
399 | student.manage_setLocalRoles(sid, ['Owner',]) |
---|
400 | student.invokeFactory('StudentApplication','application') |
---|
401 | da = {'Title': 'Application Data'} |
---|
402 | da["jamb_reg_no"] = jamb.get("REG-NO") |
---|
403 | da["jamb_lastname"] = jamb_name |
---|
404 | da["jamb_sex"] = jamb.get("SEX") |
---|
405 | da["jamb_state"] = jamb.get("STATE") |
---|
406 | da["jamb_lga"] = jamb.get("LGA") |
---|
407 | da["jamb_score"] = jamb.get("AGGREGATE") |
---|
408 | da["jamb_first_cos"] = jamb.get("COURSE1") |
---|
409 | da["jamb_second_cos"] = jamb.get("COURSE2") |
---|
410 | da["jamb_first_uni"] = jamb.get("UNIV1") |
---|
411 | da["jamb_second_uni"] = jamb.get("UNIV2") |
---|
412 | app = student.application |
---|
413 | app_doc = app.getContent() |
---|
414 | app_doc.edit(mapping=da) |
---|
415 | #wftool.doActionFor(app,'open',dest_container=app) |
---|
416 | app.manage_setLocalRoles(sid, ['Owner',]) |
---|
417 | student.getContent().createSubObjects() |
---|
418 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
419 | ###) |
---|
420 | |
---|
421 | |
---|
422 | security.declareProtected(View,"fixOwnership") |
---|
423 | def fixOwnership(self): |
---|
424 | """fix Ownership""" |
---|
425 | for s in self.portal_catalog(meta_type = 'Student'): |
---|
426 | student = s.getObject() |
---|
427 | sid = s.getId |
---|
428 | import pdb;pdb.set_trace() |
---|
429 | student.application.manage_setLocalRoles(sid, ['Owner',]) |
---|
430 | student.personal.manage_setLocalRoles(sid, ['Owner',]) |
---|
431 | |
---|
432 | security.declareProtected(View,"Title") |
---|
433 | def Title(self): |
---|
434 | """compose title""" |
---|
435 | return "Student Section" |
---|
436 | |
---|
437 | def generateStudentId(self,letter): ###( |
---|
438 | import random |
---|
439 | r = random |
---|
440 | if letter not in ('ABCDEFGIHKLMNOPQRSTUVWXY'): |
---|
441 | letter= r.choice('ABCDEFGHKLMNPQRSTUVWXY') |
---|
442 | students = self.portal_catalog(meta_type = "StudentsFolder")[-1] |
---|
443 | sid = "%c%d" % (letter,r.randint(99999,1000000)) |
---|
444 | while hasattr(students, sid): |
---|
445 | sid = "%c%d" % (letter,r.randint(99999,1000000)) |
---|
446 | return sid |
---|
447 | #return "%c%d" % (r.choice('ABCDEFGHKLMNPQRSTUVWXY'),r.randint(99999,1000000)) |
---|
448 | ###) |
---|
449 | |
---|
450 | InitializeClass(StudentsFolder) |
---|
451 | |
---|
452 | def addStudentsFolder(container, id, REQUEST=None, **kw): |
---|
453 | """Add a Student.""" |
---|
454 | ob = StudentsFolder(id, **kw) |
---|
455 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
456 | ###) |
---|
457 | |
---|
458 | class Student(CPSDocument): ###( |
---|
459 | """ |
---|
460 | WAeUP Student container for the various student data |
---|
461 | """ |
---|
462 | meta_type = 'Student' |
---|
463 | portal_type = meta_type |
---|
464 | security = ClassSecurityInfo() |
---|
465 | |
---|
466 | security.declareProtected(View,"Title") |
---|
467 | def Title(self): |
---|
468 | """compose title""" |
---|
469 | reg_nr = self.getId()[1:] |
---|
470 | data = getattr(self,'personal',None) |
---|
471 | if data: |
---|
472 | content = data.getContent() |
---|
473 | return "%s %s" % (content.firstname,content.lastname) |
---|
474 | data = getattr(self,'application',None) |
---|
475 | if data: |
---|
476 | content = data.getContent() |
---|
477 | return "%s" % (content.jamb_lastname) |
---|
478 | return self.title |
---|
479 | |
---|
480 | security.declarePrivate('makeStudentMember') ###( |
---|
481 | def makeStudentMember(self,sid,password='uNsEt'): |
---|
482 | """make the student a member""" |
---|
483 | membership = self.portal_membership |
---|
484 | membership.addMember(sid, |
---|
485 | password , |
---|
486 | roles=('Member', |
---|
487 | 'Student', |
---|
488 | ), |
---|
489 | domains='', |
---|
490 | properties = {'memberareaCreationFlag': False,},) |
---|
491 | member = membership.getMemberById(sid) |
---|
492 | self.portal_registration.afterAdd(member, sid, password, None) |
---|
493 | self.manage_setLocalRoles(sid, ['Owner',]) |
---|
494 | |
---|
495 | ###) |
---|
496 | |
---|
497 | security.declareProtected(View,'createSubObjects') ###( |
---|
498 | def createSubObjects(self): |
---|
499 | """make the student a member""" |
---|
500 | dp = {'Title': 'Personal Data'} |
---|
501 | app_doc = self.application.getContent() |
---|
502 | names = app_doc.jamb_lastname.split() |
---|
503 | if len(names) == 3: |
---|
504 | dp['firstname'] = names[0].capitalize() |
---|
505 | dp['middlename'] = names[1].capitalize() |
---|
506 | dp['lastname'] = names[2].capitalize() |
---|
507 | elif len(names) == 2: |
---|
508 | dp['firstname'] = names[0].capitalize() |
---|
509 | dp['lastname'] = names[1].capitalize() |
---|
510 | else: |
---|
511 | dp['lastname'] = app_doc.jamb_lastname |
---|
512 | dp['sex'] = app_doc.jamb_sex == 'F' |
---|
513 | dp['lga'] = "%s/%s" % (app_doc.jamb_state,app_doc.jamb_lga ) |
---|
514 | proxy = self.aq_parent |
---|
515 | proxy.invokeFactory('StudentPersonal','personal') |
---|
516 | per = proxy.personal |
---|
517 | per_doc = per.getContent() |
---|
518 | per_doc.edit(mapping = dp) |
---|
519 | per.manage_setLocalRoles(self.getId(), ['Owner',]) |
---|
520 | #self.portal_workflow.doActionFor(per,'open',dest_container=per) |
---|
521 | |
---|
522 | ###) |
---|
523 | |
---|
524 | InitializeClass(Student) |
---|
525 | |
---|
526 | def addStudent(container, id, REQUEST=None, **kw): |
---|
527 | """Add a Student.""" |
---|
528 | ob = Student(id, **kw) |
---|
529 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
530 | |
---|
531 | ###) |
---|
532 | |
---|
533 | class StudentAccommodation(CPSDocument): ###( |
---|
534 | """ |
---|
535 | WAeUP Student container for the various student data |
---|
536 | """ |
---|
537 | meta_type = 'StudentAccommodation' |
---|
538 | portal_type = meta_type |
---|
539 | security = ClassSecurityInfo() |
---|
540 | |
---|
541 | security.declareProtected(View,"Title") |
---|
542 | def Title(self): |
---|
543 | """compose title""" |
---|
544 | content = self.getContent() |
---|
545 | #return "Accommodation Data for %s %s" % (content.firstname,content.lastname) |
---|
546 | return "Accommodation Data for Session %s" % content.session |
---|
547 | |
---|
548 | |
---|
549 | InitializeClass(StudentAccommodation) |
---|
550 | |
---|
551 | def addStudentAccommodation(container, id, REQUEST=None, **kw): |
---|
552 | """Add a Students personal data.""" |
---|
553 | ob = StudentAccommodation(id, **kw) |
---|
554 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
555 | |
---|
556 | ###) |
---|
557 | |
---|
558 | class StudentPersonal(CPSDocument): ###( |
---|
559 | """ |
---|
560 | WAeUP Student container for the various student data |
---|
561 | """ |
---|
562 | meta_type = 'StudentPersonal' |
---|
563 | portal_type = meta_type |
---|
564 | security = ClassSecurityInfo() |
---|
565 | |
---|
566 | security.declareProtected(View,"Title") |
---|
567 | def Title(self): |
---|
568 | """compose title""" |
---|
569 | content = self.getContent() |
---|
570 | #return "Personal Data for %s %s" % (content.firstname,content.lastname) |
---|
571 | return "Personal Data" |
---|
572 | |
---|
573 | |
---|
574 | InitializeClass(StudentPersonal) |
---|
575 | |
---|
576 | def addStudentPersonal(container, id, REQUEST=None, **kw): |
---|
577 | """Add a Students personal data.""" |
---|
578 | ob = StudentPersonal(id, **kw) |
---|
579 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
580 | |
---|
581 | ###) |
---|
582 | |
---|
583 | class StudentClearance(CPSDocument): ###( |
---|
584 | """ |
---|
585 | WAeUP Student container for the various student data |
---|
586 | """ |
---|
587 | meta_type = 'StudentClearance' |
---|
588 | portal_type = meta_type |
---|
589 | security = ClassSecurityInfo() |
---|
590 | |
---|
591 | security.declareProtected(View,"Title") |
---|
592 | def Title(self): |
---|
593 | """compose title""" |
---|
594 | content = self.getContent() |
---|
595 | #return "Clearance Data for %s %s" % (content.firstname,content.lastname) |
---|
596 | return "Clearance Data" |
---|
597 | |
---|
598 | |
---|
599 | InitializeClass(StudentClearance) |
---|
600 | |
---|
601 | def addStudentClearance(container, id, REQUEST=None, **kw): |
---|
602 | """Add a Students personal data.""" |
---|
603 | ob = StudentClearance(id, **kw) |
---|
604 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
605 | |
---|
606 | ###) |
---|
607 | |
---|
608 | class StudentStudyLevel(CPSDocument): ###( |
---|
609 | """ |
---|
610 | WAeUP Student container for the various student data |
---|
611 | """ |
---|
612 | meta_type = 'StudentStudyLevel' |
---|
613 | portal_type = meta_type |
---|
614 | security = ClassSecurityInfo() |
---|
615 | |
---|
616 | security.declareProtected(View,"Title") |
---|
617 | def Title(self): |
---|
618 | """compose title""" |
---|
619 | return "Level %s" % self.aq_parent.getId() |
---|
620 | |
---|
621 | ## security.declarePublic("gpa") |
---|
622 | ## def gpa(self): |
---|
623 | ## """calculate the gpa""" |
---|
624 | ## sum = 0 |
---|
625 | ## course_count = 0 |
---|
626 | ## for sc in self.objectValues(): |
---|
627 | ## result = sc.getContent() |
---|
628 | ## if not result.grade: |
---|
629 | ## continue |
---|
630 | ## res = self.portal_catalog({'meta_type': 'Course', |
---|
631 | ## 'id': sc.aq_parent.id}) |
---|
632 | ## if len(res) != 1: |
---|
633 | ## continue |
---|
634 | ## course = res[0].getObject().getContent() |
---|
635 | ## sum += course.credits * ['F','E','D','C','B','A'].index(result.grade) |
---|
636 | ## course_count += 1 |
---|
637 | ## if course_count: |
---|
638 | ## return sum/course_count |
---|
639 | ## return 0.0 |
---|
640 | |
---|
641 | InitializeClass(StudentStudyLevel) |
---|
642 | |
---|
643 | def addStudentStudyLevel(container, id, REQUEST=None, **kw): |
---|
644 | """Add a Students personal data.""" |
---|
645 | ob = StudentStudyLevel(id, **kw) |
---|
646 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
647 | |
---|
648 | ###) |
---|
649 | |
---|
650 | class StudentStudyCourse(CPSDocument): ###( |
---|
651 | """ |
---|
652 | WAeUP Student container for the various student data |
---|
653 | """ |
---|
654 | meta_type = 'StudentStudyCourse' |
---|
655 | portal_type = meta_type |
---|
656 | security = ClassSecurityInfo() |
---|
657 | |
---|
658 | security.declareProtected(View,"Title") |
---|
659 | def Title(self): |
---|
660 | """compose title""" |
---|
661 | content = self.getContent() |
---|
662 | return "Study Course" |
---|
663 | |
---|
664 | |
---|
665 | InitializeClass(StudentStudyCourse) |
---|
666 | |
---|
667 | def addStudentStudyCourse(container, id, REQUEST=None, **kw): |
---|
668 | """Add a Students personal data.""" |
---|
669 | ob = StudentStudyCourse(id, **kw) |
---|
670 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
671 | |
---|
672 | ###) |
---|
673 | |
---|
674 | class StudentApplication(CPSDocument): ###( |
---|
675 | """ |
---|
676 | WAeUP Student container for the various student data |
---|
677 | """ |
---|
678 | meta_type = 'StudentApplication' |
---|
679 | portal_type = meta_type |
---|
680 | security = ClassSecurityInfo() |
---|
681 | |
---|
682 | security.declareProtected(View,"Title") |
---|
683 | def Title(self): |
---|
684 | """compose title""" |
---|
685 | return "Application Data" |
---|
686 | |
---|
687 | |
---|
688 | InitializeClass(StudentApplication) |
---|
689 | |
---|
690 | def addStudentApplication(container, id, REQUEST=None, **kw): |
---|
691 | """Add a Students eligibility data.""" |
---|
692 | ob = StudentApplication(id, **kw) |
---|
693 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
694 | |
---|
695 | ###) |
---|
696 | |
---|
697 | ##class StudentSemester(CPSDocument): ###( |
---|
698 | ## """ |
---|
699 | ## WAeUP StudentSemester containing the courses and students |
---|
700 | ## """ |
---|
701 | ## meta_type = 'StudentSemester' |
---|
702 | ## portal_type = meta_type |
---|
703 | ## security = ClassSecurityInfo() |
---|
704 | ## |
---|
705 | ##InitializeClass(StudentSemester) |
---|
706 | ## |
---|
707 | ##def addStudentSemester(container, id, REQUEST=None, **kw): |
---|
708 | ## """Add a StudentSemester.""" |
---|
709 | ## ob = StudentSemester(id, **kw) |
---|
710 | ## return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
711 | ## |
---|
712 | #####) |
---|
713 | |
---|
714 | class Semester(CPSDocument): ###( |
---|
715 | """ |
---|
716 | WAeUP Semester containing the courses and students |
---|
717 | """ |
---|
718 | meta_type = 'Semester' |
---|
719 | portal_type = meta_type |
---|
720 | security = ClassSecurityInfo() |
---|
721 | |
---|
722 | InitializeClass(Semester) |
---|
723 | |
---|
724 | def addSemester(container, id, REQUEST=None, **kw): |
---|
725 | """Add a Semester.""" |
---|
726 | ob = Semester(id, **kw) |
---|
727 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
728 | |
---|
729 | ###) |
---|
730 | |
---|
731 | class StudentCourseResult(CPSDocument): ###( |
---|
732 | """ |
---|
733 | WAeUP StudentCourseResult |
---|
734 | """ |
---|
735 | meta_type = 'StudentCourseResult' |
---|
736 | portal_type = meta_type |
---|
737 | security = ClassSecurityInfo() |
---|
738 | |
---|
739 | def getCourseEntry(self,cid): |
---|
740 | res = self.portal_catalog({'meta_type': "Course", |
---|
741 | 'id': cid}) |
---|
742 | if res: |
---|
743 | return res[-1] |
---|
744 | else: |
---|
745 | return None |
---|
746 | |
---|
747 | security.declareProtected(View,"Title") |
---|
748 | def Title(self): |
---|
749 | """compose title""" |
---|
750 | cid = self.aq_parent.getId() |
---|
751 | ce = self.getCourseEntry(cid) |
---|
752 | if ce: |
---|
753 | return "%s" % ce.Title |
---|
754 | return "No course with id %s" % cid |
---|
755 | |
---|
756 | InitializeClass(StudentCourseResult) |
---|
757 | |
---|
758 | def addStudentCourseResult(container, id, REQUEST=None, **kw): |
---|
759 | """Add a StudentCourseResult.""" |
---|
760 | ob = StudentCourseResult(id, **kw) |
---|
761 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
762 | ###) |
---|
763 | |
---|
764 | # Backward Compatibility StudyLevel |
---|
765 | |
---|
766 | from Products.WAeUP_SRP.Academics import StudyLevel |
---|
767 | |
---|
768 | from Products.WAeUP_SRP.Academics import addStudyLevel |
---|
769 | |
---|