1 | #-*- mode: python; mode: fold -*- |
---|
2 | # $Id: Students.py 1597 2007-03-19 21:59:41Z 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,os |
---|
20 | import Globals |
---|
21 | p_home = Globals.package_home(globals()) |
---|
22 | i_home = Globals.INSTANCE_HOME |
---|
23 | MAX_TRANS = 1000 |
---|
24 | from urllib import urlencode |
---|
25 | |
---|
26 | import DateTime |
---|
27 | # import PIL.Image |
---|
28 | from StringIO import StringIO |
---|
29 | |
---|
30 | def makeCertificateCode(code): ###( |
---|
31 | code = code.replace('.','') |
---|
32 | code = code.replace('(','') |
---|
33 | code = code.replace(')','') |
---|
34 | code = code.replace('/','') |
---|
35 | code = code.replace(' ','') |
---|
36 | code = code.replace('_','') |
---|
37 | return code |
---|
38 | |
---|
39 | ###) |
---|
40 | |
---|
41 | def response_write(response,s): |
---|
42 | response.setHeader('Content-type','text/html; charset=ISO-8859-15') |
---|
43 | while s.find('<') > -1: |
---|
44 | s = s.replace('<','<') |
---|
45 | while s.find('>') > -1: |
---|
46 | #from pdb import set_trace;set_trace() |
---|
47 | s = s.replace('>','>') |
---|
48 | response.write("%s<br>\n" % s) |
---|
49 | |
---|
50 | def getInt(s): ###( |
---|
51 | try: |
---|
52 | return int(s) |
---|
53 | except: |
---|
54 | return 0 |
---|
55 | |
---|
56 | def getFloat(s): |
---|
57 | try: |
---|
58 | return float(s) |
---|
59 | except: |
---|
60 | return 0.0 |
---|
61 | |
---|
62 | ###) |
---|
63 | |
---|
64 | def getStudentByRegNo(self,reg_no): ###( |
---|
65 | """search student by JAMB Reg No and return StudentFolder""" |
---|
66 | search = ZCatalog.searchResults(self.portal_catalog,{'meta_type': 'StudentApplication', |
---|
67 | 'SearchableText': reg_no, |
---|
68 | }) |
---|
69 | if len(search) < 1: |
---|
70 | return None |
---|
71 | return search[0].getObject().aq_parent |
---|
72 | |
---|
73 | ###) |
---|
74 | |
---|
75 | def checkJambNo(jnr): |
---|
76 | try: |
---|
77 | if len(jnr) != 10: |
---|
78 | return False |
---|
79 | except: |
---|
80 | return False |
---|
81 | try: |
---|
82 | int(jnr[:8]) |
---|
83 | return True |
---|
84 | except: |
---|
85 | return False |
---|
86 | |
---|
87 | class StudentsFolder(CPSDocument): ###( |
---|
88 | """ |
---|
89 | WAeUP container for the various WAeUP containers data |
---|
90 | """ |
---|
91 | meta_type = 'StudentsFolder' |
---|
92 | portal_type = meta_type |
---|
93 | security = ClassSecurityInfo() |
---|
94 | |
---|
95 | security.declareProtected(ModifyPortalContent,"createDEStudents")###( |
---|
96 | def createDEStudents(self): |
---|
97 | """load Fulltime Studentdata from CSV values""" |
---|
98 | import transaction |
---|
99 | import random |
---|
100 | #from pdb import set_trace |
---|
101 | wftool = self.portal_workflow |
---|
102 | students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() |
---|
103 | csv_d = {'jamb_reg_no': "RegNumber", |
---|
104 | 'jamb_lastname': "Name", |
---|
105 | 'session': "Session", |
---|
106 | 'pume_tot_score': "PUDE SCORE", |
---|
107 | ##'jamb_score': "JambScore", |
---|
108 | 'entry_mode': "EntryMode", |
---|
109 | 'jamb_sex': "Sex", |
---|
110 | 'jamb_state': "State", |
---|
111 | 'jamb_first_cos': "AdminCourse", |
---|
112 | 'faculty': "AdminFaculty", |
---|
113 | 'course_code': "AdmitCoscode", |
---|
114 | 'stud_status':"AdmitStatus", |
---|
115 | 'department': "AdmitDept", |
---|
116 | 'jamb_lga': "LGA", |
---|
117 | 'app_email': "email", |
---|
118 | 'app_mobile': "PhoneNumbers", |
---|
119 | } |
---|
120 | csv_fields = [f[1] for f in csv_d.items()] |
---|
121 | tr_count = 0 |
---|
122 | total = 0 |
---|
123 | #name = 'pume_results' |
---|
124 | name = 'DE_Admitted' |
---|
125 | no_import = [] |
---|
126 | s = ','.join(['"%s"' % fn for fn in csv_fields]) |
---|
127 | no_import.append('"Error",%s' % s) |
---|
128 | format = '"%(Error)s",' + ','.join(['"%%(%s)s"' % fn for fn in csv_fields]) |
---|
129 | no_certificate = "no certificate %s" % format |
---|
130 | open("%s/import/%s_not_imported.csv" % (i_home,name),"w").write('\n'.join(no_import)) |
---|
131 | logger = logging.getLogger('Students.StudentsFolder.createDEStudents') |
---|
132 | logger.info('Start loading from %s.csv' % name) |
---|
133 | l = self.portal_catalog({'meta_type': "Certificate"}) |
---|
134 | certs = {} |
---|
135 | cert_docs = {} |
---|
136 | for f in l: |
---|
137 | certs[f.getId] = f.getObject().getContent() |
---|
138 | try: |
---|
139 | result = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
140 | except: |
---|
141 | logger.error('Error reading %s.csv' % name) |
---|
142 | return |
---|
143 | for jamb in result: |
---|
144 | jamb['Error'] = "Processing" |
---|
145 | logger.info(format % jamb) |
---|
146 | jamb_reg_no = jamb.get(csv_d['jamb_reg_no']) |
---|
147 | res = self.portal_catalog({'portal_type': "StudentApplication", |
---|
148 | 'SearchableText': jamb_reg_no }) |
---|
149 | if res: |
---|
150 | em = 'Student with RegNo %s already exists\n' % jamb_reg_no |
---|
151 | logger.info(em) |
---|
152 | jamb['Error'] = "Student exists" |
---|
153 | no_import.append(format % jamb) |
---|
154 | continue |
---|
155 | cert_id = makeCertificateCode(jamb.get(csv_d['course_code'])) |
---|
156 | if cert_id not in certs.keys(): |
---|
157 | em = 'No Certificate with ID %s \n' % cert_id |
---|
158 | logger.info(em) |
---|
159 | jamb['Error'] = "No Certificate %s" % cert_id |
---|
160 | no_import.append( format % jamb) |
---|
161 | continue |
---|
162 | jamb_reg_no =jamb.get(csv_d['jamb_reg_no']) |
---|
163 | cert_doc = certs[cert_id] |
---|
164 | catalog_entry = {} |
---|
165 | catalog_entry['jamb_reg_no'] = jamb_reg_no |
---|
166 | jamb_name = jamb.get(csv_d['jamb_lastname']) |
---|
167 | jamb_name.replace('>','') |
---|
168 | jamb_name.replace('<','') |
---|
169 | names = jamb_name.split() |
---|
170 | letter = names[-1][0].upper() |
---|
171 | sid = self.generateStudentId(letter) |
---|
172 | not_created = True |
---|
173 | while not_created: |
---|
174 | try: |
---|
175 | students_folder.invokeFactory('Student', sid) |
---|
176 | not_created = False |
---|
177 | except BadRequest: |
---|
178 | sid = self.generateStudentId(letter) |
---|
179 | catalog_entry['id'] = sid |
---|
180 | tr_count += 1 |
---|
181 | logger.info('%(total)s+%(tr_count)s: Creating Student with ID %(sid)s REG-NO %(jamb_reg_no)s ' % vars()) |
---|
182 | student = getattr(self,sid) |
---|
183 | student.manage_setLocalRoles(sid, ['Owner',]) |
---|
184 | student.invokeFactory('StudentPume','pume') |
---|
185 | dp = {'Title': 'Pume Data'} |
---|
186 | student.invokeFactory('StudentApplication','application') |
---|
187 | da = {'Title': 'Application Data'} |
---|
188 | da["jamb_lastname"] = jamb_name |
---|
189 | da_fields = ('jamb_reg_no', |
---|
190 | 'jamb_sex', |
---|
191 | 'entry_mode', |
---|
192 | #'jamb_score', |
---|
193 | 'jamb_first_cos', |
---|
194 | 'jamb_sex', |
---|
195 | 'jamb_state', |
---|
196 | 'jamb_lga', |
---|
197 | 'app_email', |
---|
198 | 'app_mobile', |
---|
199 | ) |
---|
200 | for f in da_fields: |
---|
201 | da[f] = jamb.get(csv_d[f]) |
---|
202 | catalog_entry['email'] = jamb.get(csv_d['app_email']) |
---|
203 | app = student.application |
---|
204 | app_doc = app.getContent() |
---|
205 | picture ="%s/import/pictures/%s.jpg" % (i_home,jamb_reg_no) |
---|
206 | #import pdb;pdb.set_trace() |
---|
207 | if os.path.exists(picture): |
---|
208 | file = open(picture) |
---|
209 | if False: |
---|
210 | img = PIL.Image.open(file) |
---|
211 | img.thumbnail((150,200), |
---|
212 | resample=PIL.Image.ANTIALIAS) |
---|
213 | # We now need a buffer to write to. It can't be the same |
---|
214 | # as the inbuffer as the PNG writer will write over itself. |
---|
215 | outfile = StringIO() |
---|
216 | img.save(outfile, format=img.format) |
---|
217 | else: |
---|
218 | outfile = file.read() |
---|
219 | app_doc.manage_addFile('passport', |
---|
220 | file=outfile, |
---|
221 | title="%s.jpg" % jamb_reg_no) |
---|
222 | app.getContent().edit(mapping=da) |
---|
223 | app.manage_setLocalRoles(sid, ['Owner',]) |
---|
224 | #wftool.doActionFor(app,'close') |
---|
225 | dp_fields = ( |
---|
226 | #'pume_eng_score', |
---|
227 | #'pume_gen_score', |
---|
228 | 'pume_tot_score', |
---|
229 | ) |
---|
230 | dp['pume_tot_score'] = jamb.get(csv_d['pume_tot_score']) or "No Option Shaded" |
---|
231 | pume = student.pume |
---|
232 | pume.getContent().edit(mapping=dp) |
---|
233 | #wftool.doActionFor(pume,'close') |
---|
234 | pume.manage_setLocalRoles(sid, ['Owner',]) |
---|
235 | #student.getContent().createSubObjects() |
---|
236 | dp = {} |
---|
237 | if len(names) == 3: |
---|
238 | dp['firstname'] = names[0].capitalize() |
---|
239 | dp['middlename'] = names[1].capitalize() |
---|
240 | dp['lastname'] = names[2].capitalize() |
---|
241 | elif len(names) == 2: |
---|
242 | dp['firstname'] = names[0].capitalize() |
---|
243 | dp['middlename'] = '' |
---|
244 | dp['lastname'] = names[1].capitalize() |
---|
245 | else: |
---|
246 | dp['firstname'] = '' |
---|
247 | dp['middlename'] = '' |
---|
248 | dp['lastname'] = jamb_name |
---|
249 | dp['sex'] = jamb.get(csv_d['jamb_sex']) == 'F' |
---|
250 | catalog_entry['sex'] = dp['sex'] |
---|
251 | catalog_entry['name'] = "%(firstname)s %(middlename)s %(lastname)s" % dp |
---|
252 | student.invokeFactory('StudentPersonal','personal') |
---|
253 | per = student.personal |
---|
254 | per_doc = per.getContent() |
---|
255 | per_doc.edit(mapping = dp) |
---|
256 | per.manage_setLocalRoles(sid, ['Owner',]) |
---|
257 | if jamb.get(csv_d['stud_status']) == "Admitted": |
---|
258 | wftool.doActionFor(student,'pume_pass') |
---|
259 | wftool.doActionFor(student,'admit') |
---|
260 | else: |
---|
261 | wftool.doActionFor(student,'pume_fail') |
---|
262 | wftool.doActionFor(student,'reject_admission') |
---|
263 | continue |
---|
264 | # |
---|
265 | # Clearance |
---|
266 | # |
---|
267 | student.invokeFactory('StudentClearance','clearance') |
---|
268 | #wftool.doActionFor(student.clearance,'open') |
---|
269 | dp = {'Title': 'Clearance/Eligibility Record'} |
---|
270 | student.clearance.manage_setLocalRoles(sid, ['Owner',]) |
---|
271 | # |
---|
272 | # Study Course |
---|
273 | # |
---|
274 | student.invokeFactory('StudentStudyCourse','study_course') |
---|
275 | study_course = student.study_course |
---|
276 | dsc = {} |
---|
277 | #from_certificate = ['title', |
---|
278 | # 'max_elect', |
---|
279 | # 'max_pass', |
---|
280 | # 'n_core', |
---|
281 | # 'nr_years', |
---|
282 | # 'probation_credits', |
---|
283 | # 'promotion_credits', |
---|
284 | # 'start_level', |
---|
285 | # ] |
---|
286 | #for f in from_certificate: |
---|
287 | # dsc[f] = getattr(cert_doc,f) |
---|
288 | #dsc['faculty'] = jamb.get(csv_d['faculty']) |
---|
289 | #dsc['department'] = jamb.get(csv_d['department']) |
---|
290 | catalog_entry['faculty'] = jamb.get(csv_d['faculty']) |
---|
291 | catalog_entry['department'] = jamb.get(csv_d['department']) |
---|
292 | catalog_entry['course'] = cert_id |
---|
293 | #catalog_entry['level'] = getattr(cert_doc,'start_level') |
---|
294 | catalog_entry['level'] = '200' |
---|
295 | dsc['study_course'] = cert_id |
---|
296 | dsc['current_level'] = '200' |
---|
297 | #dsc['entry_session'] = jamb.get(csv_d['session']) |
---|
298 | study_course.getContent().edit(mapping=dsc) |
---|
299 | self.students_catalog.addRecord(**catalog_entry) |
---|
300 | if tr_count > 10: |
---|
301 | if len(no_import) > 1: |
---|
302 | open("%s/import/%s_not_imported.csv" % (i_home,name),"a").write( |
---|
303 | '\n'.join(no_import)+'\n') |
---|
304 | no_import = [] |
---|
305 | em = '%d transactions commited\n' % tr_count |
---|
306 | transaction.commit() |
---|
307 | logger.info(em) |
---|
308 | total += tr_count |
---|
309 | tr_count = 0 |
---|
310 | open("%s/import/%s_not_imported.csv" % (i_home,name),"a").write( |
---|
311 | '\n'.join(no_import)) |
---|
312 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
313 | ###) |
---|
314 | |
---|
315 | security.declareProtected(ModifyPortalContent,"createNewStudents")###( |
---|
316 | def createNewStudents(self): |
---|
317 | """load Fulltime Studentdata from CSV values""" |
---|
318 | import transaction |
---|
319 | import random |
---|
320 | #from pdb import set_trace |
---|
321 | wftool = self.portal_workflow |
---|
322 | students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() |
---|
323 | csv_d = {'jamb_reg_no': "RegNumber", |
---|
324 | 'jamb_lastname': "Name", |
---|
325 | 'session': "Session", |
---|
326 | 'pume_tot_score': "PUME SCORE", |
---|
327 | 'jamb_score': "JambScore", |
---|
328 | 'jamb_sex': "Sex", |
---|
329 | 'jamb_state': "State", |
---|
330 | ## 'jamb_first_cos': "AdminCourse", |
---|
331 | 'faculty': "AdminFaculty", |
---|
332 | 'course_code': "AdmitCoscode", |
---|
333 | 'stud_status':"AdmitStatus", |
---|
334 | 'department': "AdmitDept", |
---|
335 | 'jamb_lga': "LGA", |
---|
336 | 'app_email': "email", |
---|
337 | 'app_mobile': "PhoneNumbers", |
---|
338 | } |
---|
339 | csv_fields = [f[1] for f in csv_d.items()] |
---|
340 | tr_count = 0 |
---|
341 | total = 0 |
---|
342 | #name = 'pume_results' |
---|
343 | name = 'Admitted' |
---|
344 | no_import = [] |
---|
345 | s = ','.join(['"%s"' % fn for fn in csv_fields]) |
---|
346 | no_import.append('"Error",%s' % s) |
---|
347 | format = '"%(Error)s",' + ','.join(['"%%(%s)s"' % fn for fn in csv_fields]) |
---|
348 | no_certificate = "no certificate %s" % format |
---|
349 | open("%s/import/%s_not_imported.csv" % (i_home,name),"w").write('\n'.join(no_import)) |
---|
350 | logger = logging.getLogger('Students.StudentsFolder.createNewStudents') |
---|
351 | logger.info('Start loading from %s.csv' % name) |
---|
352 | l = self.portal_catalog({'meta_type': "Certificate"}) |
---|
353 | certs = {} |
---|
354 | cert_docs = {} |
---|
355 | for f in l: |
---|
356 | certs[f.getId] = f.getObject().getContent() |
---|
357 | try: |
---|
358 | result = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
359 | except: |
---|
360 | logger.error('Error reading %s.csv' % name) |
---|
361 | return |
---|
362 | for jamb in result: |
---|
363 | jamb['Error'] = "Processing " |
---|
364 | logger.info(format % jamb) |
---|
365 | jamb_reg_no = jamb.get(csv_d['jamb_reg_no']) |
---|
366 | res = self.portal_catalog({'portal_type': "StudentApplication", |
---|
367 | 'SearchableText': jamb_reg_no }) |
---|
368 | if res: |
---|
369 | em = 'Student with RegNo %s already exists\n' % jamb_reg_no |
---|
370 | logger.info(em) |
---|
371 | jamb['Error'] = "Student exists" |
---|
372 | no_import.append(format % jamb) |
---|
373 | continue |
---|
374 | cert_id = makeCertificateCode(jamb.get(csv_d['course_code'])) |
---|
375 | if cert_id not in certs.keys(): |
---|
376 | em = 'No Certificate with ID %s \n' % cert_id |
---|
377 | logger.info(em) |
---|
378 | jamb['Error'] = "No Certificate %s" % cert_id |
---|
379 | no_import.append( format % jamb) |
---|
380 | continue |
---|
381 | res = self.portal_pumeresults(jamb_reg_no = jamb_reg_no) |
---|
382 | if len(res) == 1: |
---|
383 | self.portal_pumeresults.modifyRecord(jamb_reg_no = jamb_reg_no, |
---|
384 | status = jamb.get(csv_d['stud_status']), |
---|
385 | ) |
---|
386 | jamb_reg_no =jamb.get(csv_d['jamb_reg_no']) |
---|
387 | cert_doc = certs[cert_id] |
---|
388 | catalog_entry = {} |
---|
389 | catalog_entry['jamb_reg_no'] = jamb_reg_no |
---|
390 | jamb_name = jamb.get(csv_d['jamb_lastname']) |
---|
391 | jamb_name.replace('>','') |
---|
392 | jamb_name.replace('<','') |
---|
393 | names = jamb_name.split() |
---|
394 | letter = names[-1][0].upper() |
---|
395 | sid = self.generateStudentId(letter) |
---|
396 | not_created = True |
---|
397 | while not_created: |
---|
398 | try: |
---|
399 | students_folder.invokeFactory('Student', sid) |
---|
400 | not_created = False |
---|
401 | except BadRequest: |
---|
402 | sid = self.generateStudentId(letter) |
---|
403 | catalog_entry['id'] = sid |
---|
404 | tr_count += 1 |
---|
405 | logger.info('%(total)s+%(tr_count)s: Creating Student with ID %(sid)s REG-NO %(jamb_reg_no)s ' % vars()) |
---|
406 | student = getattr(self,sid) |
---|
407 | student.manage_setLocalRoles(sid, ['Owner',]) |
---|
408 | student.invokeFactory('StudentPume','pume') |
---|
409 | dp = {'Title': 'Pume Data'} |
---|
410 | student.invokeFactory('StudentApplication','application') |
---|
411 | da = {'Title': 'Application Data'} |
---|
412 | da["jamb_lastname"] = jamb_name |
---|
413 | da_fields = ('jamb_reg_no', |
---|
414 | 'jamb_sex', |
---|
415 | #'jamb_state', |
---|
416 | 'jamb_score', |
---|
417 | ## 'jamb_first_cos', |
---|
418 | 'jamb_sex', |
---|
419 | 'jamb_state', |
---|
420 | 'jamb_lga', |
---|
421 | 'app_email', |
---|
422 | 'app_mobile', |
---|
423 | ) |
---|
424 | for f in da_fields: |
---|
425 | da[f] = jamb.get(csv_d[f]) |
---|
426 | catalog_entry['email'] = jamb.get(csv_d['app_email']) |
---|
427 | app = student.application |
---|
428 | app_doc = app.getContent() |
---|
429 | picture ="%s/import/pictures/%s.jpg" % (i_home,jamb_reg_no) |
---|
430 | #import pdb;pdb.set_trace() |
---|
431 | if os.path.exists(picture): |
---|
432 | file = open(picture) |
---|
433 | if False: |
---|
434 | img = PIL.Image.open(file) |
---|
435 | img.thumbnail((150,200), |
---|
436 | resample=PIL.Image.ANTIALIAS) |
---|
437 | # We now need a buffer to write to. It can't be the same |
---|
438 | # as the inbuffer as the PNG writer will write over itself. |
---|
439 | outfile = StringIO() |
---|
440 | img.save(outfile, format=img.format) |
---|
441 | else: |
---|
442 | outfile = file.read() |
---|
443 | app_doc.manage_addFile('passport', |
---|
444 | file=outfile, |
---|
445 | title="%s.jpg" % jamb_reg_no) |
---|
446 | app.getContent().edit(mapping=da) |
---|
447 | app.manage_setLocalRoles(sid, ['Owner',]) |
---|
448 | #wftool.doActionFor(app,'close') |
---|
449 | dp_fields = ( |
---|
450 | #'pume_eng_score', |
---|
451 | #'pume_gen_score', |
---|
452 | 'pume_tot_score', |
---|
453 | ) |
---|
454 | dp['pume_tot_score'] = jamb.get(csv_d['pume_tot_score']) or "No Option Shaded" |
---|
455 | pume = student.pume |
---|
456 | pume.getContent().edit(mapping=dp) |
---|
457 | #wftool.doActionFor(pume,'close') |
---|
458 | pume.manage_setLocalRoles(sid, ['Owner',]) |
---|
459 | #student.getContent().createSubObjects() |
---|
460 | dp = {} |
---|
461 | if len(names) == 3: |
---|
462 | dp['firstname'] = names[0].capitalize() |
---|
463 | dp['middlename'] = names[1].capitalize() |
---|
464 | dp['lastname'] = names[2].capitalize() |
---|
465 | elif len(names) == 2: |
---|
466 | dp['firstname'] = names[0].capitalize() |
---|
467 | dp['middlename'] = '' |
---|
468 | dp['lastname'] = names[1].capitalize() |
---|
469 | else: |
---|
470 | dp['firstname'] = '' |
---|
471 | dp['middlename'] = '' |
---|
472 | dp['lastname'] = jamb_name |
---|
473 | dp['sex'] = jamb.get(csv_d['jamb_sex']) == 'F' |
---|
474 | catalog_entry['sex'] = dp['sex'] |
---|
475 | catalog_entry['name'] = "%(firstname)s %(middlename)s %(lastname)s" % dp |
---|
476 | student.invokeFactory('StudentPersonal','personal') |
---|
477 | per = student.personal |
---|
478 | per_doc = per.getContent() |
---|
479 | per_doc.edit(mapping = dp) |
---|
480 | per.manage_setLocalRoles(sid, ['Owner',]) |
---|
481 | if jamb.get(csv_d['stud_status']) == "Admitted": |
---|
482 | wftool.doActionFor(student,'pume_pass') |
---|
483 | wftool.doActionFor(student,'admit') |
---|
484 | else: |
---|
485 | wftool.doActionFor(student,'pume_fail') |
---|
486 | wftool.doActionFor(student,'reject_admission') |
---|
487 | continue |
---|
488 | # |
---|
489 | # Clearance |
---|
490 | # |
---|
491 | student.invokeFactory('StudentClearance','clearance') |
---|
492 | #wftool.doActionFor(student.clearance,'open') |
---|
493 | dp = {'Title': 'Clearance/Eligibility Record'} |
---|
494 | student.clearance.manage_setLocalRoles(sid, ['Owner',]) |
---|
495 | # |
---|
496 | # Study Course |
---|
497 | # |
---|
498 | student.invokeFactory('StudentStudyCourse','study_course') |
---|
499 | study_course = student.study_course |
---|
500 | dsc = {} |
---|
501 | #from_certificate = ['title', |
---|
502 | # 'max_elect', |
---|
503 | # 'max_pass', |
---|
504 | # 'n_core', |
---|
505 | # 'nr_years', |
---|
506 | # 'probation_credits', |
---|
507 | # 'promotion_credits', |
---|
508 | # 'start_level', |
---|
509 | # ] |
---|
510 | #for f in from_certificate: |
---|
511 | # dsc[f] = getattr(cert_doc,f) |
---|
512 | #dsc['faculty'] = jamb.get(csv_d['faculty']) |
---|
513 | #dsc['department'] = jamb.get(csv_d['department']) |
---|
514 | catalog_entry['faculty'] = jamb.get(csv_d['faculty']) |
---|
515 | catalog_entry['department'] = jamb.get(csv_d['department']) |
---|
516 | catalog_entry['course'] = cert_id |
---|
517 | #catalog_entry['level'] = getattr(cert_doc,'start_level') |
---|
518 | catalog_entry['level'] = '100' |
---|
519 | dsc['study_course'] = cert_id |
---|
520 | dsc['entry_level'] = '100' |
---|
521 | #dsc['entry_session'] = jamb.get(csv_d['session']) |
---|
522 | study_course.getContent().edit(mapping=dsc) |
---|
523 | self.students_catalog.addRecord(**catalog_entry) |
---|
524 | if tr_count > 10: |
---|
525 | if len(no_import) > 0: |
---|
526 | open("%s/import/%s_not_imported.csv" % (i_home,name),"a").write( |
---|
527 | '\n'.join(no_import) + "\n") |
---|
528 | no_import = [] |
---|
529 | em = '%d transactions commited\n' % tr_count |
---|
530 | transaction.commit() |
---|
531 | logger.info(em) |
---|
532 | total += tr_count |
---|
533 | tr_count = 0 |
---|
534 | open("%s/import/%s_not_imported.csv" % (i_home,name),"a").write( |
---|
535 | '\n'.join(no_import)) |
---|
536 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
537 | ###) |
---|
538 | |
---|
539 | security.declareProtected(ModifyPortalContent,"importReturningStudents")###( |
---|
540 | def importReturningStudents(self): |
---|
541 | """load Returning Studentdata from CSV values""" |
---|
542 | import transaction |
---|
543 | import random |
---|
544 | #from pdb import set_trace |
---|
545 | wftool = self.portal_workflow |
---|
546 | current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") |
---|
547 | #students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() |
---|
548 | students_folder = self.portal_url().getPortalObject().campus.students |
---|
549 | tr_count = 1 |
---|
550 | total = 0 |
---|
551 | #name = 'pume_results' |
---|
552 | name = 'Returning' |
---|
553 | table = self.returning_import |
---|
554 | no_import = [] |
---|
555 | imported = [] |
---|
556 | logger = logging.getLogger('Students.StudentsFolder.importReturningStudents') |
---|
557 | try: |
---|
558 | returning = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
559 | except: |
---|
560 | logger.error('Error reading %s.csv' % name) |
---|
561 | return |
---|
562 | l = self.portal_catalog({'meta_type': "Certificate"}) |
---|
563 | certs = {} |
---|
564 | cert_docs = {} |
---|
565 | for f in l: |
---|
566 | certs[f.getId] = f.getObject().getContent() |
---|
567 | start = True |
---|
568 | res = table() |
---|
569 | regs = [] |
---|
570 | if len(res) > 0: |
---|
571 | regs = [s.matric_no for s in res] |
---|
572 | #import pdb;pdb.set_trace() |
---|
573 | for student in returning: |
---|
574 | if start: |
---|
575 | start = False |
---|
576 | logger.info('Start loading from %s.csv' % name) |
---|
577 | s = ','.join(['"%s"' % fn for fn in student.keys()]) |
---|
578 | imported.append(s) |
---|
579 | no_import.append('%s,"Error"' % s) |
---|
580 | format = ','.join(['"%%(%s)s"' % fn for fn in student.keys()]) |
---|
581 | format_error = format + ',"%(Error)s"' |
---|
582 | no_certificate = "no certificate %s" % format |
---|
583 | student['matric_no'] = matric_no = student.get('matric_no').upper() |
---|
584 | student['Mode_of_Entry'] = entry_mode = student.get('Mode of Entry').upper() |
---|
585 | student['Permanent_Address'] = perm_address = student.get('Permanent Address') |
---|
586 | if matric_no == '': |
---|
587 | student['Error'] = "Empty matric_no" |
---|
588 | no_import.append( format_error % student) |
---|
589 | continue |
---|
590 | if matric_no in regs or self.returning_import(matric_no = matric_no): |
---|
591 | student['Error'] = "Duplicate" |
---|
592 | no_import.append( format_error % student) |
---|
593 | continue |
---|
594 | cert_id = makeCertificateCode(student.get('Coursemajorcode')) |
---|
595 | if cert_id not in certs.keys(): |
---|
596 | student['Error'] = "No Certificate %s" % cert_id |
---|
597 | no_import.append( format_error % student) |
---|
598 | continue |
---|
599 | try: |
---|
600 | table.addRecord(**student) |
---|
601 | except ValueError: |
---|
602 | student['Error'] = "Duplicate" |
---|
603 | no_import.append( format_error % student) |
---|
604 | continue |
---|
605 | regs.append(student.get('matric_no')) |
---|
606 | imported.append(format % student) |
---|
607 | tr_count += 1 |
---|
608 | if tr_count > 1000: |
---|
609 | if len(no_import) > 0: |
---|
610 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
---|
611 | '\n'.join(no_import) + '\n') |
---|
612 | no_import = [] |
---|
613 | open("%s/import/%simported%s.csv" % (i_home,name,current),"a").write( |
---|
614 | '\n'.join(no_import) + "\n") |
---|
615 | imported = [] |
---|
616 | em = '%d transactions commited total %s\n' % (tr_count,total) |
---|
617 | transaction.commit() |
---|
618 | regs = [] |
---|
619 | logger.info(em) |
---|
620 | total += tr_count |
---|
621 | tr_count = 0 |
---|
622 | open("%s/import/%simported%s.csv" % (i_home,name,current),"a").write( |
---|
623 | '\n'.join(imported)) |
---|
624 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
---|
625 | '\n'.join(no_import)) |
---|
626 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
627 | ###) |
---|
628 | |
---|
629 | security.declareProtected(ModifyPortalContent,"fixVerdicts")###( |
---|
630 | def fixVerdicts(self,csv_file=None): |
---|
631 | """fix wrong uploaded verdicts""" |
---|
632 | import transaction |
---|
633 | import random |
---|
634 | wftool = self.portal_workflow |
---|
635 | current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") |
---|
636 | students_folder = self.portal_url.getPortalObject().campus.students |
---|
637 | tr_count = 1 |
---|
638 | total = 0 |
---|
639 | if csv_file is None: |
---|
640 | name = 'Verdicts' |
---|
641 | else: |
---|
642 | name = csv_file |
---|
643 | st_cat = self.students_catalog |
---|
644 | no_import = [] |
---|
645 | verdicts_voc = self.portal_vocabularies.verdicts |
---|
646 | rverdicts = {} |
---|
647 | for k,v in verdicts_voc.items(): |
---|
648 | rverdicts[v.upper()] = k |
---|
649 | rverdicts['STUDENT ON PROBATION'] = 'C' |
---|
650 | logger = logging.getLogger('Students.StudentsFolder.fixVerdicts') |
---|
651 | try: |
---|
652 | verdicts = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
653 | except: |
---|
654 | logger.error('Error reading %s.csv' % name) |
---|
655 | return |
---|
656 | start = True |
---|
657 | #import pdb;pdb.set_trace() |
---|
658 | for verdict in verdicts: |
---|
659 | if start: |
---|
660 | start = False |
---|
661 | logger.info('Start loading from %s.csv' % name) |
---|
662 | s = ','.join(['"%s"' % fn for fn in verdict.keys()]) |
---|
663 | no_import.append('%s,"Error"' % s) |
---|
664 | format = ','.join(['"%%(%s)s"' % fn for fn in verdict.keys()]) |
---|
665 | format_error = format + ',"%(Error)s"' |
---|
666 | matric_no = verdict.get('MAT NO') |
---|
667 | if not matric_no: |
---|
668 | continue |
---|
669 | matric_no = matric_no.upper() |
---|
670 | if matric_no == '': |
---|
671 | continue |
---|
672 | verdict_code = rverdicts.get(verdict.get('CATEGORY'),None) |
---|
673 | if verdict_code is None: |
---|
674 | continue |
---|
675 | sres = st_cat(matric_no = matric_no) |
---|
676 | if sres: |
---|
677 | student_id = sres[0].id |
---|
678 | student_obj = getattr(students_folder,student_id,None) |
---|
679 | if student_obj: |
---|
680 | study_course = getattr(student_obj,'study_course',None) |
---|
681 | if study_course is None: |
---|
682 | verdict['Error'] = "Student did not yet log in" |
---|
683 | no_import.append( format_error % verdict) |
---|
684 | continue |
---|
685 | st_cat.modifyRecord(id = student_id, |
---|
686 | verdict=verdict_code) |
---|
687 | |
---|
688 | dsc = {} |
---|
689 | dsc['current_verdict'] = verdict_code |
---|
690 | study_course.getContent().edit(mapping=dsc) |
---|
691 | else: |
---|
692 | verdict['Error'] = "Not found in students_catalog" |
---|
693 | no_import.append( format_error % verdict) |
---|
694 | continue |
---|
695 | tr_count += 1 |
---|
696 | if tr_count > 1000: |
---|
697 | if len(no_import) > 0: |
---|
698 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
---|
699 | '\n'.join(no_import) + '\n') |
---|
700 | no_import = [] |
---|
701 | em = '%d transactions commited total %s\n' % (tr_count,total) |
---|
702 | transaction.commit() |
---|
703 | regs = [] |
---|
704 | logger.info(em) |
---|
705 | total += tr_count |
---|
706 | tr_count = 0 |
---|
707 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
---|
708 | '\n'.join(no_import)) |
---|
709 | total += tr_count |
---|
710 | em = '%d total transactions commited' % (total) |
---|
711 | logger.info(em) |
---|
712 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
713 | ###) |
---|
714 | |
---|
715 | security.declareProtected(ModifyPortalContent,"fixAllNames")###( |
---|
716 | def fixAllNames(self): |
---|
717 | "fix all students names" |
---|
718 | import transaction |
---|
719 | response = self.REQUEST.RESPONSE |
---|
720 | logger = logging.getLogger('fixAllNames') |
---|
721 | logger.info('Start') |
---|
722 | students = self.portal_catalog(portal_type='Student') |
---|
723 | count = 0 |
---|
724 | total = 0 |
---|
725 | for student in students: |
---|
726 | scat_res = self.students_catalog(id = student.getId) |
---|
727 | if not scat_res: |
---|
728 | self.students_catalog.addRecord(id = student.getId) |
---|
729 | scat_res = self.students_catalog(id = student.getId) |
---|
730 | student_entry = scat_res[0] |
---|
731 | old_new = self.fixName(student,student_entry) |
---|
732 | count += 1 |
---|
733 | response_write(response,"%d) %s: %s" % (count + total,student_entry.id,old_new)) |
---|
734 | if count > 2000: |
---|
735 | transaction.commit() |
---|
736 | logger.info("%d transactions commited" % count) |
---|
737 | total += count |
---|
738 | count = 0 |
---|
739 | ###) |
---|
740 | |
---|
741 | security.declareProtected(ModifyPortalContent,"fixName")###( |
---|
742 | def fixName(self,student_brain, student_entry): |
---|
743 | "fix the name of a student" |
---|
744 | fix = "first" |
---|
745 | if student_entry.get('name_fixed',None) == fix: |
---|
746 | return "Name already fixed" |
---|
747 | student_id = student_entry.id |
---|
748 | new_student = student_entry.jamb_reg_no.startswith('6') |
---|
749 | student_obj = student_brain.getObject() |
---|
750 | personal = getattr(student_obj,'personal',None) |
---|
751 | invalid = '' |
---|
752 | if personal is None: |
---|
753 | return '"%s", "Returning: %s","%s"' % (invalid,student_entry.name,"not logged in") |
---|
754 | per_doc = personal.getContent() |
---|
755 | old_first = per_doc.firstname |
---|
756 | old_middle = per_doc.middlename |
---|
757 | old_last = per_doc.lastname |
---|
758 | new_first = '' |
---|
759 | new_middle = '' |
---|
760 | new_last = '' |
---|
761 | if new_student: |
---|
762 | if not old_first and not old_middle and old_last: |
---|
763 | new_names = [n.capitalize() for n in old_last.split()] |
---|
764 | if len(new_names) > 3: |
---|
765 | old_first = new_names[0] |
---|
766 | old_last = new_names[1] |
---|
767 | old_middle = ' '.join(new_names[2:]) |
---|
768 | elif len(new_names) == 3: |
---|
769 | old_first = new_names[0] |
---|
770 | old_last = new_names[1] |
---|
771 | old_middle = new_names[2] |
---|
772 | elif len(new_names) == 2: |
---|
773 | old_first = new_names[0] |
---|
774 | old_last = new_names[1] |
---|
775 | old_middle = '' |
---|
776 | elif len(new_names) == 1: |
---|
777 | old_last = new_names[0] |
---|
778 | old_first = '' |
---|
779 | old_middle = '' |
---|
780 | if old_last: |
---|
781 | new_first = old_last |
---|
782 | if old_middle: |
---|
783 | new_middle = old_middle |
---|
784 | if old_first: |
---|
785 | new_last = old_first |
---|
786 | |
---|
787 | if old_first.find('<') != -1 or\ |
---|
788 | old_first.find('>') != -1 or\ |
---|
789 | old_middle.find('<') != -1 or\ |
---|
790 | old_middle.find('>') != -1 or\ |
---|
791 | old_last.find('<') != -1 or\ |
---|
792 | old_last.find('>') != -1: |
---|
793 | invalid = "invalid characters" |
---|
794 | else: |
---|
795 | if old_first and old_middle and old_last: |
---|
796 | new_first = old_first.capitalize() |
---|
797 | new_middle = old_middle.capitalize() |
---|
798 | new_last = old_last.capitalize() |
---|
799 | elif old_first and not old_middle and old_last: |
---|
800 | new_names = [n.capitalize() for n in old_first.split()] |
---|
801 | if len(new_names) > 1: |
---|
802 | new_first = new_names[0] |
---|
803 | new_middle = ' '.join(new_names[1:]) |
---|
804 | else: |
---|
805 | new_first = old_first.capitalize() |
---|
806 | new_middle = '' |
---|
807 | new_last = old_last.capitalize() |
---|
808 | elif not old_first and not old_middle and old_last: |
---|
809 | new_first = '' |
---|
810 | new_middle = '' |
---|
811 | new_last = old_last.capitalize() |
---|
812 | else: |
---|
813 | new_first = '' |
---|
814 | new_middle = '' |
---|
815 | new_last = '' |
---|
816 | name = "%(new_last)s %(new_first)s %(new_middle)s" % vars() |
---|
817 | if new_student: |
---|
818 | text = "New" |
---|
819 | else: |
---|
820 | text = "Returning" |
---|
821 | old_new = '"%s", "%s: %s","%s"' % (invalid,text, |
---|
822 | student_entry.name, |
---|
823 | name) |
---|
824 | if not invalid: |
---|
825 | self.students_catalog.modifyRecord(id = student_id, |
---|
826 | name_fixed = fix, |
---|
827 | name = name) |
---|
828 | per_doc.edit(mapping = {'firstname' : new_first, |
---|
829 | 'middlename' : new_middle, |
---|
830 | 'lastname' : new_last, |
---|
831 | }) |
---|
832 | return old_new |
---|
833 | ###) |
---|
834 | |
---|
835 | security.declareProtected(ModifyPortalContent,"fixAllEntryModeForReturning")###( |
---|
836 | def fixAllEntryModeForReturning(self): |
---|
837 | "read all Returning*.csv" |
---|
838 | ipath = "%s/import/" % i_home |
---|
839 | names = os.listdir(ipath) |
---|
840 | for name in names: |
---|
841 | head,tail = os.path.splitext(name) |
---|
842 | if head.startswith('Returning')\ |
---|
843 | and tail == '.csv'\ |
---|
844 | and name.find('imported') < 0: |
---|
845 | self.fixEntryModeForReturning(csv_file=head) |
---|
846 | ###) |
---|
847 | |
---|
848 | security.declareProtected(ModifyPortalContent,"fixEntryModeForReturning")###( |
---|
849 | def fixEntryModeForReturning(self,csv_file=None): |
---|
850 | """load Returning Studentdata from CSV values""" |
---|
851 | import transaction |
---|
852 | import random |
---|
853 | wftool = self.portal_workflow |
---|
854 | current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") |
---|
855 | students_folder = self.portal_url.getPortalObject().campus.students |
---|
856 | tr_count = 1 |
---|
857 | total = 0 |
---|
858 | if csv_file is None: |
---|
859 | name = 'Returning' |
---|
860 | else: |
---|
861 | name = csv_file |
---|
862 | table = self.returning_import |
---|
863 | st_cat = self.students_catalog |
---|
864 | no_import = [] |
---|
865 | logger = logging.getLogger('Students.StudentsFolder.fixEntryModeForReturning') |
---|
866 | try: |
---|
867 | returning = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
868 | except: |
---|
869 | logger.error('Error reading %s.csv' % name) |
---|
870 | return |
---|
871 | start = True |
---|
872 | for student in returning: |
---|
873 | if start: |
---|
874 | start = False |
---|
875 | logger.info('Start loading from %s.csv' % name) |
---|
876 | s = ','.join(['"%s"' % fn for fn in student.keys()]) |
---|
877 | no_import.append('%s,"Error"' % s) |
---|
878 | format = ','.join(['"%%(%s)s"' % fn for fn in student.keys()]) |
---|
879 | format_error = format + ',"%(Error)s"' |
---|
880 | matric_no = student.get('matric_no') |
---|
881 | if not matric_no: |
---|
882 | continue |
---|
883 | matric_no = matric_no.upper() |
---|
884 | student['matric_no'] = matric_no |
---|
885 | if matric_no == '': |
---|
886 | continue |
---|
887 | if not table(matric_no = matric_no): |
---|
888 | student['Error'] = "Not imported yet" |
---|
889 | no_import.append( format_error % student) |
---|
890 | continue |
---|
891 | student_id = None |
---|
892 | app = None |
---|
893 | per = None |
---|
894 | if st_cat(matric_no = matric_no): |
---|
895 | student_id = st_cat(matric_no = matric_no)[0].id |
---|
896 | student_obj = getattr(students_folder,student_id,None) |
---|
897 | if student_obj: |
---|
898 | app = getattr(student_obj,'application',None) |
---|
899 | if app is not None: |
---|
900 | app_doc = app.getContent() |
---|
901 | per = getattr(student_obj,'personal',None) |
---|
902 | if per is not None: |
---|
903 | per_doc = per.getContent() |
---|
904 | student['Mode_of_Entry'] = entry_mode = student.get('Mode of Entry').upper() |
---|
905 | student['Permanent_Address'] = perm_address = student.get('Permanent Address') |
---|
906 | #import pdb;pdb.set_trace() |
---|
907 | if not entry_mode: |
---|
908 | student['Error'] = "'Mode of Entry' empty" |
---|
909 | no_import.append( format_error % student) |
---|
910 | continue |
---|
911 | try: |
---|
912 | table.modifyRecord(matric_no = matric_no, |
---|
913 | Mode_of_Entry = entry_mode, |
---|
914 | Permanent_Address = perm_address) |
---|
915 | except KeyError: |
---|
916 | student['Error'] = "Not found in returning_import" |
---|
917 | no_import.append( format_error % student) |
---|
918 | continue |
---|
919 | if student_id is not None: |
---|
920 | try: |
---|
921 | st_cat.modifyRecord(id = student_id, |
---|
922 | entry_mode=entry_mode) |
---|
923 | except KeyError: |
---|
924 | student['Error'] = "Not found in students_catalog" |
---|
925 | no_import.append( format_error % student) |
---|
926 | continue |
---|
927 | if app is not None: |
---|
928 | da = {} |
---|
929 | da['entry_mode'] = entry_mode |
---|
930 | app_doc.edit(mapping=da) |
---|
931 | if per is not None: |
---|
932 | dp = {} |
---|
933 | dp['perm_address'] = perm_address |
---|
934 | per_doc.edit(mapping=dp) |
---|
935 | tr_count += 1 |
---|
936 | if tr_count > 1000: |
---|
937 | if len(no_import) > 0: |
---|
938 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
---|
939 | '\n'.join(no_import) + '\n') |
---|
940 | no_import = [] |
---|
941 | em = '%d transactions commited total %s\n' % (tr_count,total) |
---|
942 | transaction.commit() |
---|
943 | regs = [] |
---|
944 | logger.info(em) |
---|
945 | total += tr_count |
---|
946 | tr_count = 0 |
---|
947 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
---|
948 | '\n'.join(no_import)) |
---|
949 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
950 | ###) |
---|
951 | |
---|
952 | security.declareProtected(ModifyPortalContent,"updateReturningStudents")###( |
---|
953 | def updateReturningStudents(self): |
---|
954 | """load and overwrite Returning Student Data from CSV values""" |
---|
955 | import transaction |
---|
956 | import random |
---|
957 | #from pdb import set_trace |
---|
958 | wftool = self.portal_workflow |
---|
959 | current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") |
---|
960 | students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() |
---|
961 | tr_count = 1 |
---|
962 | total = 0 |
---|
963 | #name = 'pume_results' |
---|
964 | name = 'Returning_update' |
---|
965 | table = self.returning_import |
---|
966 | no_import = [] |
---|
967 | imported = [] |
---|
968 | logger = logging.getLogger('Students.StudentsFolder.updateReturningStudents') |
---|
969 | try: |
---|
970 | returning = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
971 | except: |
---|
972 | logger.error('Error reading %s.csv' % name) |
---|
973 | return |
---|
974 | l = self.portal_catalog({'meta_type': "Certificate"}) |
---|
975 | certs = {} |
---|
976 | cert_docs = {} |
---|
977 | for f in l: |
---|
978 | certs[f.getId] = f.getObject().getContent() |
---|
979 | start = True |
---|
980 | res = table() |
---|
981 | regs = [] |
---|
982 | if len(res) > 0: |
---|
983 | regs = [s.matric_no for s in res] |
---|
984 | for student in returning: |
---|
985 | if start: |
---|
986 | start = False |
---|
987 | logger.info('Start loading from %s.csv' % name) |
---|
988 | s = ','.join(['"%s"' % fn for fn in student.keys()]) |
---|
989 | imported.append(s) |
---|
990 | no_import.append('%s,"Error"' % s) |
---|
991 | format = ','.join(['"%%(%s)s"' % fn for fn in student.keys()]) |
---|
992 | format_error = format + ',"%(Error)s"' |
---|
993 | no_certificate = "no certificate %s" % format |
---|
994 | matric_no = student.get('matric_no').upper() |
---|
995 | student['matric_no'] = matric_no |
---|
996 | if matric_no == '': |
---|
997 | student['Error'] = "Empty matric_no" |
---|
998 | no_import.append( format_error % student) |
---|
999 | continue |
---|
1000 | # if matric_no in regs or self.returning_import(matric_no = matric_no): |
---|
1001 | # student['Error'] = "Duplicate" |
---|
1002 | # no_import.append( format_error % student) |
---|
1003 | # continue |
---|
1004 | # cert_id = makeCertificateCode(student.get('Coursemajorcode')) |
---|
1005 | # if cert_id not in certs.keys(): |
---|
1006 | # student['Error'] = "No Certificate %s" % cert_id |
---|
1007 | # no_import.append( format_error % student) |
---|
1008 | # continue |
---|
1009 | try: |
---|
1010 | table.modifyRecord(**student) |
---|
1011 | except KeyError: |
---|
1012 | #import pdb;pdb.set_trace() |
---|
1013 | student['Error'] = "no Student found to update" |
---|
1014 | no_import.append( format_error % student) |
---|
1015 | continue |
---|
1016 | #s = self.students_catalog(matric_no=matric_no) |
---|
1017 | #if s: |
---|
1018 | # level = "%s" % (int(student.get('Level')) + 100) |
---|
1019 | # self.students_catalog.modifyRecord(id = s[0].id, |
---|
1020 | # level=level) |
---|
1021 | |
---|
1022 | regs.append(student.get('matric_no')) |
---|
1023 | imported.append(format % student) |
---|
1024 | tr_count += 1 |
---|
1025 | if tr_count > 1000: |
---|
1026 | if len(no_import) > 0: |
---|
1027 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
---|
1028 | '\n'.join(no_import) + '\n') |
---|
1029 | no_import = [] |
---|
1030 | open("%s/import/%simported%s.csv" % (i_home,name,current),"a").write( |
---|
1031 | '\n'.join(no_import) + "\n") |
---|
1032 | imported = [] |
---|
1033 | em = '%d transactions commited total %s\n' % (tr_count,total) |
---|
1034 | transaction.commit() |
---|
1035 | regs = [] |
---|
1036 | logger.info(em) |
---|
1037 | total += tr_count |
---|
1038 | tr_count = 0 |
---|
1039 | open("%s/import/%simported%s.csv" % (i_home,name,current),"a").write( |
---|
1040 | '\n'.join(imported)) |
---|
1041 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
---|
1042 | '\n'.join(no_import)) |
---|
1043 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
1044 | ###) |
---|
1045 | |
---|
1046 | security.declareProtected(ModifyPortalContent,"importResults")###( |
---|
1047 | def importResults(self): |
---|
1048 | """load Returning Students Results from CSV""" |
---|
1049 | import transaction |
---|
1050 | import random |
---|
1051 | #from pdb import set_trace |
---|
1052 | wftool = self.portal_workflow |
---|
1053 | current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") |
---|
1054 | students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() |
---|
1055 | tr_count = 1 |
---|
1056 | total = 0 |
---|
1057 | #name = 'pume_results' |
---|
1058 | name = 'Results' |
---|
1059 | table = self.results_import |
---|
1060 | no_import = [] |
---|
1061 | imported = [] |
---|
1062 | logger = logging.getLogger('Students.StudentsFolder.importResults') |
---|
1063 | try: |
---|
1064 | results = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
1065 | except: |
---|
1066 | logger.error('Error reading %s.csv' % name) |
---|
1067 | return |
---|
1068 | l = self.portal_catalog({'meta_type': "Course"}) |
---|
1069 | courses = [f.getId for f in l] |
---|
1070 | start = True |
---|
1071 | res = table() |
---|
1072 | regs = [] |
---|
1073 | if len(res) > 0: |
---|
1074 | regs = [s.key for s in res] |
---|
1075 | no_course = [] |
---|
1076 | no_course_list = [] |
---|
1077 | course_count = 0 |
---|
1078 | for result in results: |
---|
1079 | if start: |
---|
1080 | start = False |
---|
1081 | logger.info('Start loading from %s.csv' % name) |
---|
1082 | s = ','.join(['"%s"' % fn for fn in result.keys()]) |
---|
1083 | imported.append(s) |
---|
1084 | no_import.append('%s,"Error"' % s) |
---|
1085 | format = ','.join(['"%%(%s)s"' % fn for fn in result.keys()]) |
---|
1086 | format_error = format + ',"%(Error)s"' |
---|
1087 | no_certificate = "no certificate %s" % format |
---|
1088 | course_id = result.get('CosCode') |
---|
1089 | if not course_id: |
---|
1090 | course_id = 'N/A' |
---|
1091 | result['CosCode'] = course_id |
---|
1092 | matric_no = result.get('matric_no').upper() |
---|
1093 | result['matric_no'] = matric_no |
---|
1094 | key = matric_no+course_id |
---|
1095 | if matric_no == '': |
---|
1096 | result['Error'] = "Empty matric_no" |
---|
1097 | no_import.append( format_error % result) |
---|
1098 | continue |
---|
1099 | if key in regs or self.results_import(key = key): |
---|
1100 | result['Error'] = "Duplicate" |
---|
1101 | no_import.append( format_error % result) |
---|
1102 | continue |
---|
1103 | if course_id not in courses: |
---|
1104 | if course_id not in no_course: |
---|
1105 | course_count +=1 |
---|
1106 | no_course.append(course_id) |
---|
1107 | no_course_list.append('"%s"' % course_id) |
---|
1108 | #result['Error'] = "No Course" |
---|
1109 | #logger.info(format_error % result) |
---|
1110 | result['key'] = key |
---|
1111 | try: |
---|
1112 | table.addRecord(**result) |
---|
1113 | except ValueError: |
---|
1114 | #import pdb;pdb.set_trace() |
---|
1115 | result['Error'] = "Duplicate" |
---|
1116 | no_import.append( format_error % result) |
---|
1117 | continue |
---|
1118 | regs.append(key) |
---|
1119 | imported.append(format % result) |
---|
1120 | tr_count += 1 |
---|
1121 | if tr_count > 1000: |
---|
1122 | if len(no_import) > 0: |
---|
1123 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
---|
1124 | '\n'.join(no_import)+'\n') |
---|
1125 | no_import = [] |
---|
1126 | open("%s/import/%simported%s.csv" % (i_home,name,current),"a").write( |
---|
1127 | '\n'.join(imported) + '\n') |
---|
1128 | imported = [] |
---|
1129 | if no_course_list: |
---|
1130 | open("%s/import/%sno_courses%s.csv" % (i_home,name,current),"a").write( |
---|
1131 | '\n'.join(no_course_list) + '\n') |
---|
1132 | no_course_list = [] |
---|
1133 | em = '%d transactions commited total %s\n courses not found %s' % (tr_count,total,course_count) |
---|
1134 | transaction.commit() |
---|
1135 | logger.info(em) |
---|
1136 | regs = [] |
---|
1137 | total += tr_count |
---|
1138 | tr_count = 0 |
---|
1139 | open("%s/import/%simported%s.csv" % (i_home,name,current),"a").write( |
---|
1140 | '\n'.join(imported)) |
---|
1141 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
---|
1142 | '\n'.join(no_import)) |
---|
1143 | if no_course_list: |
---|
1144 | open("%s/import/%sno_courses%s.csv" % (i_home,name,current),"a").write( |
---|
1145 | '\n'.join(no_course_list)) |
---|
1146 | em = '%d transactions commited total %s\n courses not found %s' % (tr_count,total,course_count) |
---|
1147 | logger.info(em) |
---|
1148 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
1149 | ###) |
---|
1150 | |
---|
1151 | security.declareProtected(ModifyPortalContent,"updateStudyCourse")###( |
---|
1152 | def updateStudyCourse(self): |
---|
1153 | """update StudyCourse from CSV values""" |
---|
1154 | import transaction |
---|
1155 | import random |
---|
1156 | from pdb import set_trace |
---|
1157 | wftool = self.portal_workflow |
---|
1158 | students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() |
---|
1159 | csv_d = {'jamb_reg_no': "RegNumber", |
---|
1160 | 'jamb_lastname': "Name", |
---|
1161 | 'session': "Session", |
---|
1162 | 'pume_tot_score': "PUME SCORE", |
---|
1163 | 'jamb_score': "JambScore", |
---|
1164 | 'jamb_sex': "Sex", |
---|
1165 | 'jamb_state': "State", |
---|
1166 | ## 'jamb_first_cos': "AdminCourse", |
---|
1167 | 'faculty': "AdminFaculty", |
---|
1168 | 'course_code': "AdmitCoscode", |
---|
1169 | 'stud_status':"AdmitStatus", |
---|
1170 | 'department': "AdmitDept", |
---|
1171 | 'jamb_lga': "LGA", |
---|
1172 | 'app_email': "email", |
---|
1173 | 'app_mobile': "PhoneNumbers", |
---|
1174 | } |
---|
1175 | csv_fields = [f[1] for f in csv_d.items()] |
---|
1176 | tr_count = 0 |
---|
1177 | total = 0 |
---|
1178 | #name = 'pume_results' |
---|
1179 | name = 'StudyCourseChange' |
---|
1180 | no_import = [] |
---|
1181 | s = ','.join(['"%s"' % fn for fn in csv_fields]) |
---|
1182 | no_import.append('"Error",%s' % s) |
---|
1183 | format = '"%(Error)s",' + ','.join(['"%%(%s)s"' % fn for fn in csv_fields]) |
---|
1184 | no_certificate = "no certificate %s" % format |
---|
1185 | open("%s/import/%s_not_imported.csv" % (i_home,name),"w").write( |
---|
1186 | '\n'.join(no_import)) |
---|
1187 | logger = logging.getLogger('Students.StudentsFolder.updateStudyCourse') |
---|
1188 | logger.info('Start loading from %s.csv' % name) |
---|
1189 | l = self.portal_catalog({'meta_type': "Certificate"}) |
---|
1190 | try: |
---|
1191 | result = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
1192 | except: |
---|
1193 | logger.error('Error reading %s.csv' % name) |
---|
1194 | return |
---|
1195 | for jamb in result: |
---|
1196 | jamb['Error'] = "Processing " |
---|
1197 | logger.info(format % jamb) |
---|
1198 | jamb_reg_no = jamb.get(csv_d['jamb_reg_no']) |
---|
1199 | res = self.portal_catalog({'portal_type': "StudentApplication", |
---|
1200 | 'SearchableText': jamb_reg_no }) |
---|
1201 | if not res: |
---|
1202 | em = 'Student with jamb_reg_no %s does not exists\n' % jamb_reg_no |
---|
1203 | logger.info(em) |
---|
1204 | jamb['Error'] = "Student does not exist" |
---|
1205 | no_import.append(format % jamb) |
---|
1206 | continue |
---|
1207 | sid = res[0].getPath().split('/')[-2] |
---|
1208 | cert_id = makeCertificateCode(jamb.get(csv_d['course_code'])) |
---|
1209 | res = self.portal_catalog(portal_type = "Certificate", id = cert_id) |
---|
1210 | if not res: |
---|
1211 | em = 'No Certificate with ID %s \n' % cert_id |
---|
1212 | logger.info(em) |
---|
1213 | jamb['Error'] = "No Certificate %s" % cert_id |
---|
1214 | no_import.append( format % jamb) |
---|
1215 | continue |
---|
1216 | cert_brain = res[0] |
---|
1217 | catalog_entry = {} |
---|
1218 | student = getattr(self,sid) |
---|
1219 | # |
---|
1220 | # Study Course |
---|
1221 | # |
---|
1222 | study_course = student.study_course |
---|
1223 | dsc = {} |
---|
1224 | cert_pl = cert_brain.getPath().split('/') |
---|
1225 | catalog_entry['id'] = sid |
---|
1226 | catalog_entry['faculty'] = cert_pl[-4] |
---|
1227 | catalog_entry['department'] = cert_pl[-3] |
---|
1228 | catalog_entry['course'] = cert_id |
---|
1229 | dsc['study_course'] = cert_id |
---|
1230 | study_course.getContent().edit(mapping=dsc) |
---|
1231 | self.students_catalog.modifyRecord(**catalog_entry) |
---|
1232 | if tr_count > 10: |
---|
1233 | if len(no_import) > 1: |
---|
1234 | open("%s/import/%s_not_imported.csv" % (i_home,name),"w+").write( |
---|
1235 | '\n'.join(no_import)) |
---|
1236 | no_import = [] |
---|
1237 | em = '%d transactions commited\n' % tr_count |
---|
1238 | transaction.commit() |
---|
1239 | logger.info(em) |
---|
1240 | total += tr_count |
---|
1241 | tr_count = 0 |
---|
1242 | tr_count += 1 |
---|
1243 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
1244 | ###) |
---|
1245 | |
---|
1246 | security.declareProtected(View,"fixOwnership") ###( |
---|
1247 | def fixOwnership(self): |
---|
1248 | """fix Ownership""" |
---|
1249 | for s in self.portal_catalog(meta_type = 'Student'): |
---|
1250 | student = s.getObject() |
---|
1251 | sid = s.getId |
---|
1252 | import pdb;pdb.set_trace() |
---|
1253 | student.application.manage_setLocalRoles(sid, ['Owner',]) |
---|
1254 | student.personal.manage_setLocalRoles(sid, ['Owner',]) |
---|
1255 | ###) |
---|
1256 | |
---|
1257 | security.declareProtected(View,"Title") ###( |
---|
1258 | def Title(self): |
---|
1259 | """compose title""" |
---|
1260 | return "Student Section" |
---|
1261 | ###) |
---|
1262 | |
---|
1263 | def generateStudentId(self,letter): ###( |
---|
1264 | import random |
---|
1265 | r = random |
---|
1266 | if letter not in ('ABCDEFGIHKLMNOPQRSTUVWXY'): |
---|
1267 | letter= r.choice('ABCDEFGHKLMNPQRSTUVWXY') |
---|
1268 | students = self.portal_catalog(meta_type = "StudentsFolder")[-1] |
---|
1269 | sid = "%c%d" % (letter,r.randint(99999,1000000)) |
---|
1270 | while hasattr(students, sid): |
---|
1271 | sid = "%c%d" % (letter,r.randint(99999,1000000)) |
---|
1272 | return sid |
---|
1273 | #return "%c%d" % (r.choice('ABCDEFGHKLMNPQRSTUVWXY'),r.randint(99999,1000000)) |
---|
1274 | ###) |
---|
1275 | |
---|
1276 | InitializeClass(StudentsFolder) |
---|
1277 | |
---|
1278 | def addStudentsFolder(container, id, REQUEST=None, **kw): ###( |
---|
1279 | """Add a Student.""" |
---|
1280 | ob = StudentsFolder(id, **kw) |
---|
1281 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
1282 | ###) |
---|
1283 | |
---|
1284 | ###) |
---|
1285 | |
---|
1286 | |
---|
1287 | class Student(CPSDocument): ###( |
---|
1288 | """ |
---|
1289 | WAeUP Student container for the various student data |
---|
1290 | """ |
---|
1291 | meta_type = 'Student' |
---|
1292 | portal_type = meta_type |
---|
1293 | security = ClassSecurityInfo() |
---|
1294 | |
---|
1295 | security.declareProtected(View,"Title") |
---|
1296 | def Title(self): |
---|
1297 | """compose title""" |
---|
1298 | reg_nr = self.getId()[1:] |
---|
1299 | data = getattr(self,'personal',None) |
---|
1300 | if data: |
---|
1301 | content = data.getContent() |
---|
1302 | return "%s %s %s" % (content.firstname,content.middlename,content.lastname) |
---|
1303 | data = getattr(self,'application',None) |
---|
1304 | if data: |
---|
1305 | content = data.getContent() |
---|
1306 | return "%s" % (content.jamb_lastname) |
---|
1307 | return self.title |
---|
1308 | |
---|
1309 | security.declarePrivate('makeStudentMember') ###( |
---|
1310 | def makeStudentMember(self,sid,password='uNsEt'): |
---|
1311 | """make the student a member""" |
---|
1312 | membership = self.portal_membership |
---|
1313 | membership.addMember(sid, |
---|
1314 | password , |
---|
1315 | roles=('Member', |
---|
1316 | 'Student', |
---|
1317 | ), |
---|
1318 | domains='', |
---|
1319 | properties = {'memberareaCreationFlag': False, |
---|
1320 | 'homeless': True},) |
---|
1321 | member = membership.getMemberById(sid) |
---|
1322 | self.portal_registration.afterAdd(member, sid, password, None) |
---|
1323 | self.manage_setLocalRoles(sid, ['Owner',]) |
---|
1324 | |
---|
1325 | ###) |
---|
1326 | |
---|
1327 | security.declareProtected(View,'createSubObjects') ###( |
---|
1328 | def createSubObjects(self): |
---|
1329 | """make the student a member""" |
---|
1330 | dp = {'Title': 'Personal Data'} |
---|
1331 | app_doc = self.application.getContent() |
---|
1332 | names = app_doc.jamb_lastname.split() |
---|
1333 | if len(names) == 3: |
---|
1334 | dp['firstname'] = names[0].capitalize() |
---|
1335 | dp['middlename'] = names[1].capitalize() |
---|
1336 | dp['lastname'] = names[2].capitalize() |
---|
1337 | elif len(names) == 2: |
---|
1338 | dp['firstname'] = names[0].capitalize() |
---|
1339 | dp['lastname'] = names[1].capitalize() |
---|
1340 | else: |
---|
1341 | dp['lastname'] = app_doc.jamb_lastname |
---|
1342 | dp['sex'] = app_doc.jamb_sex == 'F' |
---|
1343 | dp['lga'] = "%s/%s" % (app_doc.jamb_state,app_doc.jamb_lga ) |
---|
1344 | proxy = self.aq_parent |
---|
1345 | proxy.invokeFactory('StudentPersonal','personal') |
---|
1346 | per = proxy.personal |
---|
1347 | per_doc = per.getContent() |
---|
1348 | per_doc.edit(mapping = dp) |
---|
1349 | per.manage_setLocalRoles(proxy.getId(), ['Owner',]) |
---|
1350 | #self.portal_workflow.doActionFor(per,'open',dest_container=per) |
---|
1351 | |
---|
1352 | ###) |
---|
1353 | |
---|
1354 | InitializeClass(Student) |
---|
1355 | |
---|
1356 | def addStudent(container, id, REQUEST=None, **kw): |
---|
1357 | """Add a Student.""" |
---|
1358 | ob = Student(id, **kw) |
---|
1359 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
1360 | |
---|
1361 | ###) |
---|
1362 | |
---|
1363 | class StudentAccommodation(CPSDocument): ###( |
---|
1364 | """ |
---|
1365 | WAeUP Student container for the various student data |
---|
1366 | """ |
---|
1367 | meta_type = 'StudentAccommodation' |
---|
1368 | portal_type = meta_type |
---|
1369 | security = ClassSecurityInfo() |
---|
1370 | |
---|
1371 | security.declareProtected(View,"Title") |
---|
1372 | def Title(self): |
---|
1373 | """compose title""" |
---|
1374 | content = self.getContent() |
---|
1375 | #return "Accommodation Data for %s %s" % (content.firstname,content.lastname) |
---|
1376 | return "Accommodation Data for Session %s" % content.session |
---|
1377 | |
---|
1378 | |
---|
1379 | InitializeClass(StudentAccommodation) |
---|
1380 | |
---|
1381 | def addStudentAccommodation(container, id, REQUEST=None, **kw): |
---|
1382 | """Add a Students personal data.""" |
---|
1383 | ob = StudentAccommodation(id, **kw) |
---|
1384 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
1385 | |
---|
1386 | ###) |
---|
1387 | |
---|
1388 | class StudentPersonal(CPSDocument): ###( |
---|
1389 | """ |
---|
1390 | WAeUP Student container for the various student data |
---|
1391 | """ |
---|
1392 | meta_type = 'StudentPersonal' |
---|
1393 | portal_type = meta_type |
---|
1394 | security = ClassSecurityInfo() |
---|
1395 | |
---|
1396 | security.declareProtected(View,"Title") |
---|
1397 | def Title(self): |
---|
1398 | """compose title""" |
---|
1399 | content = self.getContent() |
---|
1400 | #return "Personal Data for %s %s" % (content.firstname,content.lastname) |
---|
1401 | return "Personal Data" |
---|
1402 | |
---|
1403 | |
---|
1404 | InitializeClass(StudentPersonal) |
---|
1405 | |
---|
1406 | def addStudentPersonal(container, id, REQUEST=None, **kw): |
---|
1407 | """Add a Students personal data.""" |
---|
1408 | ob = StudentPersonal(id, **kw) |
---|
1409 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
1410 | |
---|
1411 | ###) |
---|
1412 | |
---|
1413 | class StudentClearance(CPSDocument): ###( |
---|
1414 | """ |
---|
1415 | WAeUP Student container for the various student data |
---|
1416 | """ |
---|
1417 | meta_type = 'StudentClearance' |
---|
1418 | portal_type = meta_type |
---|
1419 | security = ClassSecurityInfo() |
---|
1420 | |
---|
1421 | security.declareProtected(View,"Title") |
---|
1422 | def Title(self): |
---|
1423 | """compose title""" |
---|
1424 | content = self.getContent() |
---|
1425 | #return "Clearance/Eligibility Record for %s %s" % (content.firstname,content.lastname) |
---|
1426 | return "Clearance/Eligibility Record" |
---|
1427 | |
---|
1428 | |
---|
1429 | InitializeClass(StudentClearance) |
---|
1430 | |
---|
1431 | def addStudentClearance(container, id, REQUEST=None, **kw): |
---|
1432 | """Add a Students personal data.""" |
---|
1433 | ob = StudentClearance(id, **kw) |
---|
1434 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
1435 | |
---|
1436 | ###) |
---|
1437 | |
---|
1438 | class StudentStudyLevel(CPSDocument): ###( |
---|
1439 | """ |
---|
1440 | WAeUP Student container for the various student data |
---|
1441 | """ |
---|
1442 | meta_type = 'StudentStudyLevel' |
---|
1443 | portal_type = meta_type |
---|
1444 | security = ClassSecurityInfo() |
---|
1445 | |
---|
1446 | security.declareProtected(View,"Title") |
---|
1447 | def Title(self): |
---|
1448 | """compose title""" |
---|
1449 | return "Level %s" % self.aq_parent.getId() |
---|
1450 | |
---|
1451 | ## security.declarePublic("gpa") |
---|
1452 | ## def gpa(self): |
---|
1453 | ## """calculate the gpa""" |
---|
1454 | ## sum = 0 |
---|
1455 | ## course_count = 0 |
---|
1456 | ## for sc in self.objectValues(): |
---|
1457 | ## result = sc.getContent() |
---|
1458 | ## if not result.grade: |
---|
1459 | ## continue |
---|
1460 | ## res = self.portal_catalog({'meta_type': 'Course', |
---|
1461 | ## 'id': sc.aq_parent.id}) |
---|
1462 | ## if len(res) != 1: |
---|
1463 | ## continue |
---|
1464 | ## course = res[0].getObject().getContent() |
---|
1465 | ## sum += course.credits * ['F','E','D','C','B','A'].index(result.grade) |
---|
1466 | ## course_count += 1 |
---|
1467 | ## if course_count: |
---|
1468 | ## return sum/course_count |
---|
1469 | ## return 0.0 |
---|
1470 | |
---|
1471 | InitializeClass(StudentStudyLevel) |
---|
1472 | |
---|
1473 | def addStudentStudyLevel(container, id, REQUEST=None, **kw): |
---|
1474 | """Add a Students personal data.""" |
---|
1475 | ob = StudentStudyLevel(id, **kw) |
---|
1476 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
1477 | |
---|
1478 | ###) |
---|
1479 | |
---|
1480 | class StudentStudyCourse(CPSDocument): ###( |
---|
1481 | """ |
---|
1482 | WAeUP Student container for the various student data |
---|
1483 | """ |
---|
1484 | meta_type = 'StudentStudyCourse' |
---|
1485 | portal_type = meta_type |
---|
1486 | security = ClassSecurityInfo() |
---|
1487 | |
---|
1488 | security.declareProtected(View,"Title") |
---|
1489 | def Title(self): |
---|
1490 | """compose title""" |
---|
1491 | content = self.getContent() |
---|
1492 | return "Study Course" |
---|
1493 | |
---|
1494 | |
---|
1495 | InitializeClass(StudentStudyCourse) |
---|
1496 | |
---|
1497 | def addStudentStudyCourse(container, id, REQUEST=None, **kw): |
---|
1498 | """Add a Students personal data.""" |
---|
1499 | ob = StudentStudyCourse(id, **kw) |
---|
1500 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
1501 | |
---|
1502 | ###) |
---|
1503 | |
---|
1504 | class StudentApplication(CPSDocument): ###( |
---|
1505 | """ |
---|
1506 | WAeUP Student container for the various student data |
---|
1507 | """ |
---|
1508 | meta_type = 'StudentApplication' |
---|
1509 | portal_type = meta_type |
---|
1510 | security = ClassSecurityInfo() |
---|
1511 | |
---|
1512 | security.declareProtected(View,"Title") |
---|
1513 | def Title(self): |
---|
1514 | """compose title""" |
---|
1515 | return "Application Data" |
---|
1516 | |
---|
1517 | |
---|
1518 | InitializeClass(StudentApplication) |
---|
1519 | |
---|
1520 | def addStudentApplication(container, id, REQUEST=None, **kw): |
---|
1521 | """Add a Students eligibility data.""" |
---|
1522 | ob = StudentApplication(id, **kw) |
---|
1523 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
1524 | ###) |
---|
1525 | |
---|
1526 | class StudentPume(CPSDocument): ###( |
---|
1527 | """ |
---|
1528 | WAeUP Student container for the various student data |
---|
1529 | """ |
---|
1530 | meta_type = 'StudentPume' |
---|
1531 | portal_type = meta_type |
---|
1532 | security = ClassSecurityInfo() |
---|
1533 | |
---|
1534 | security.declareProtected(View,"Title") |
---|
1535 | def Title(self): |
---|
1536 | """compose title""" |
---|
1537 | return "PUME Results" |
---|
1538 | |
---|
1539 | |
---|
1540 | InitializeClass(StudentPume) |
---|
1541 | |
---|
1542 | def addStudentPume(container, id, REQUEST=None, **kw): |
---|
1543 | """Add a Students PUME data.""" |
---|
1544 | ob = StudentPume(id, **kw) |
---|
1545 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
1546 | ###) |
---|
1547 | |
---|
1548 | ##class StudentSemester(CPSDocument): ###( |
---|
1549 | ## """ |
---|
1550 | ## WAeUP StudentSemester containing the courses and students |
---|
1551 | ## """ |
---|
1552 | ## meta_type = 'StudentSemester' |
---|
1553 | ## portal_type = meta_type |
---|
1554 | ## security = ClassSecurityInfo() |
---|
1555 | ## |
---|
1556 | ##InitializeClass(StudentSemester) |
---|
1557 | ## |
---|
1558 | ##def addStudentSemester(container, id, REQUEST=None, **kw): |
---|
1559 | ## """Add a StudentSemester.""" |
---|
1560 | ## ob = StudentSemester(id, **kw) |
---|
1561 | ## return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
1562 | ## |
---|
1563 | #####) |
---|
1564 | |
---|
1565 | ##class Semester(CPSDocument): ###( |
---|
1566 | ## """ |
---|
1567 | ## WAeUP Semester containing the courses and students |
---|
1568 | ## """ |
---|
1569 | ## meta_type = 'Semester' |
---|
1570 | ## portal_type = meta_type |
---|
1571 | ## security = ClassSecurityInfo() |
---|
1572 | ## |
---|
1573 | ##InitializeClass(Semester) |
---|
1574 | ## |
---|
1575 | ##def addSemester(container, id, REQUEST=None, **kw): |
---|
1576 | ## """Add a Semester.""" |
---|
1577 | ## ob = Semester(id, **kw) |
---|
1578 | ## return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
1579 | ## |
---|
1580 | #####) |
---|
1581 | |
---|
1582 | class StudentCourseResult(CPSDocument): ###( |
---|
1583 | """ |
---|
1584 | WAeUP StudentCourseResult |
---|
1585 | """ |
---|
1586 | meta_type = 'StudentCourseResult' |
---|
1587 | portal_type = meta_type |
---|
1588 | security = ClassSecurityInfo() |
---|
1589 | |
---|
1590 | def getCourseEntry(self,cid): |
---|
1591 | res = self.portal_catalog({'meta_type': "Course", |
---|
1592 | 'id': cid}) |
---|
1593 | if res: |
---|
1594 | return res[-1] |
---|
1595 | else: |
---|
1596 | return None |
---|
1597 | |
---|
1598 | security.declareProtected(View,"Title") |
---|
1599 | def Title(self): |
---|
1600 | """compose title""" |
---|
1601 | cid = self.aq_parent.getId() |
---|
1602 | ce = self.getCourseEntry(cid) |
---|
1603 | if ce: |
---|
1604 | return "%s" % ce.Title |
---|
1605 | return "No course with id %s" % cid |
---|
1606 | |
---|
1607 | InitializeClass(StudentCourseResult) |
---|
1608 | |
---|
1609 | def addStudentCourseResult(container, id, REQUEST=None, **kw): |
---|
1610 | """Add a StudentCourseResult.""" |
---|
1611 | ob = StudentCourseResult(id, **kw) |
---|
1612 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
1613 | ###) |
---|
1614 | |
---|
1615 | # Backward Compatibility StudyLevel |
---|
1616 | |
---|
1617 | from Products.WAeUP_SRP.Academics import StudyLevel |
---|
1618 | |
---|
1619 | from Products.WAeUP_SRP.Academics import addStudyLevel |
---|
1620 | |
---|