1 | #-*- mode: python; mode: fold -*- |
---|
2 | # $Id: Students.py 1611 2007-03-20 18:26:23Z 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) > 1: |
---|
765 | old_first = new_names[0] |
---|
766 | old_last = new_names[-1] |
---|
767 | old_middle = ' '.join(new_names[1:-1]) |
---|
768 | else: |
---|
769 | old_last = new_names[0] |
---|
770 | old_first = '' |
---|
771 | old_middle = '' |
---|
772 | if old_first: |
---|
773 | new_first = old_first |
---|
774 | if old_middle: |
---|
775 | new_middle = old_middle |
---|
776 | if old_last: |
---|
777 | new_last = old_last |
---|
778 | if old_first.find('<') != -1 or\ |
---|
779 | old_first.find('>') != -1 or\ |
---|
780 | old_middle.find('<') != -1 or\ |
---|
781 | old_middle.find('>') != -1 or\ |
---|
782 | old_last.find('<') != -1 or\ |
---|
783 | old_last.find('>') != -1: |
---|
784 | invalid = "invalid characters" |
---|
785 | else: |
---|
786 | new_first = old_first |
---|
787 | if new_first.strip() == '-': |
---|
788 | new_first = '' |
---|
789 | new_middle = old_middle |
---|
790 | if new_middle.strip() == '-': |
---|
791 | new_middle = '' |
---|
792 | new_last = old_last |
---|
793 | if new_last.strip() == '-': |
---|
794 | new_last = '' |
---|
795 | name = "%(new_first)s %(new_middle)s %(new_last)s" % vars() |
---|
796 | if new_student: |
---|
797 | text = "New" |
---|
798 | else: |
---|
799 | text = "Returning" |
---|
800 | old_new = '"%s","%s","%s","%s"' % (invalid,text, |
---|
801 | student_entry.name, |
---|
802 | name) |
---|
803 | if not invalid: |
---|
804 | self.students_catalog.modifyRecord(id = student_id, |
---|
805 | name_fixed = fix, |
---|
806 | name = name) |
---|
807 | per_doc.edit(mapping = {'firstname' : new_first, |
---|
808 | 'middlename' : new_middle, |
---|
809 | 'lastname' : new_last, |
---|
810 | }) |
---|
811 | return old_new |
---|
812 | ###) |
---|
813 | |
---|
814 | security.declareProtected(ModifyPortalContent,"fixAllEntryModeForReturning")###( |
---|
815 | def fixAllEntryModeForReturning(self): |
---|
816 | "read all Returning*.csv" |
---|
817 | ipath = "%s/import/" % i_home |
---|
818 | names = os.listdir(ipath) |
---|
819 | for name in names: |
---|
820 | head,tail = os.path.splitext(name) |
---|
821 | if head.startswith('Returning')\ |
---|
822 | and tail == '.csv'\ |
---|
823 | and name.find('imported') < 0: |
---|
824 | self.fixEntryModeForReturning(csv_file=head) |
---|
825 | ###) |
---|
826 | |
---|
827 | security.declareProtected(ModifyPortalContent,"fixEntryModeForReturning")###( |
---|
828 | def fixEntryModeForReturning(self,csv_file=None): |
---|
829 | """load Returning Studentdata from CSV values""" |
---|
830 | import transaction |
---|
831 | import random |
---|
832 | wftool = self.portal_workflow |
---|
833 | current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") |
---|
834 | students_folder = self.portal_url.getPortalObject().campus.students |
---|
835 | tr_count = 1 |
---|
836 | total = 0 |
---|
837 | if csv_file is None: |
---|
838 | name = 'Returning' |
---|
839 | else: |
---|
840 | name = csv_file |
---|
841 | table = self.returning_import |
---|
842 | st_cat = self.students_catalog |
---|
843 | no_import = [] |
---|
844 | logger = logging.getLogger('Students.StudentsFolder.fixEntryModeForReturning') |
---|
845 | try: |
---|
846 | returning = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
847 | except: |
---|
848 | logger.error('Error reading %s.csv' % name) |
---|
849 | return |
---|
850 | start = True |
---|
851 | for student in returning: |
---|
852 | if start: |
---|
853 | start = False |
---|
854 | logger.info('Start loading from %s.csv' % name) |
---|
855 | s = ','.join(['"%s"' % fn for fn in student.keys()]) |
---|
856 | no_import.append('%s,"Error"' % s) |
---|
857 | format = ','.join(['"%%(%s)s"' % fn for fn in student.keys()]) |
---|
858 | format_error = format + ',"%(Error)s"' |
---|
859 | matric_no = student.get('matric_no') |
---|
860 | if not matric_no: |
---|
861 | continue |
---|
862 | matric_no = matric_no.upper() |
---|
863 | student['matric_no'] = matric_no |
---|
864 | if matric_no == '': |
---|
865 | continue |
---|
866 | if not table(matric_no = matric_no): |
---|
867 | student['Error'] = "Not imported yet" |
---|
868 | no_import.append( format_error % student) |
---|
869 | continue |
---|
870 | student_id = None |
---|
871 | app = None |
---|
872 | per = None |
---|
873 | if st_cat(matric_no = matric_no): |
---|
874 | student_id = st_cat(matric_no = matric_no)[0].id |
---|
875 | student_obj = getattr(students_folder,student_id,None) |
---|
876 | if student_obj: |
---|
877 | app = getattr(student_obj,'application',None) |
---|
878 | if app is not None: |
---|
879 | app_doc = app.getContent() |
---|
880 | per = getattr(student_obj,'personal',None) |
---|
881 | if per is not None: |
---|
882 | per_doc = per.getContent() |
---|
883 | student['Mode_of_Entry'] = entry_mode = student.get('Mode of Entry').upper() |
---|
884 | student['Permanent_Address'] = perm_address = student.get('Permanent Address') |
---|
885 | #import pdb;pdb.set_trace() |
---|
886 | if not entry_mode: |
---|
887 | student['Error'] = "'Mode of Entry' empty" |
---|
888 | no_import.append( format_error % student) |
---|
889 | continue |
---|
890 | try: |
---|
891 | table.modifyRecord(matric_no = matric_no, |
---|
892 | Mode_of_Entry = entry_mode, |
---|
893 | Permanent_Address = perm_address) |
---|
894 | except KeyError: |
---|
895 | student['Error'] = "Not found in returning_import" |
---|
896 | no_import.append( format_error % student) |
---|
897 | continue |
---|
898 | if student_id is not None: |
---|
899 | try: |
---|
900 | st_cat.modifyRecord(id = student_id, |
---|
901 | entry_mode=entry_mode) |
---|
902 | except KeyError: |
---|
903 | student['Error'] = "Not found in students_catalog" |
---|
904 | no_import.append( format_error % student) |
---|
905 | continue |
---|
906 | if app is not None: |
---|
907 | da = {} |
---|
908 | da['entry_mode'] = entry_mode |
---|
909 | app_doc.edit(mapping=da) |
---|
910 | if per is not None: |
---|
911 | dp = {} |
---|
912 | dp['perm_address'] = perm_address |
---|
913 | per_doc.edit(mapping=dp) |
---|
914 | tr_count += 1 |
---|
915 | if tr_count > 1000: |
---|
916 | if len(no_import) > 0: |
---|
917 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
---|
918 | '\n'.join(no_import) + '\n') |
---|
919 | no_import = [] |
---|
920 | em = '%d transactions commited total %s\n' % (tr_count,total) |
---|
921 | transaction.commit() |
---|
922 | regs = [] |
---|
923 | logger.info(em) |
---|
924 | total += tr_count |
---|
925 | tr_count = 0 |
---|
926 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
---|
927 | '\n'.join(no_import)) |
---|
928 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
929 | ###) |
---|
930 | |
---|
931 | security.declareProtected(ModifyPortalContent,"updateReturningStudents")###( |
---|
932 | def updateReturningStudents(self): |
---|
933 | """load and overwrite Returning Student Data from CSV values""" |
---|
934 | import transaction |
---|
935 | import random |
---|
936 | #from pdb import set_trace |
---|
937 | wftool = self.portal_workflow |
---|
938 | current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") |
---|
939 | students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() |
---|
940 | tr_count = 1 |
---|
941 | total = 0 |
---|
942 | #name = 'pume_results' |
---|
943 | name = 'Returning_update' |
---|
944 | table = self.returning_import |
---|
945 | no_import = [] |
---|
946 | imported = [] |
---|
947 | logger = logging.getLogger('Students.StudentsFolder.updateReturningStudents') |
---|
948 | try: |
---|
949 | returning = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
950 | except: |
---|
951 | logger.error('Error reading %s.csv' % name) |
---|
952 | return |
---|
953 | l = self.portal_catalog({'meta_type': "Certificate"}) |
---|
954 | certs = {} |
---|
955 | cert_docs = {} |
---|
956 | for f in l: |
---|
957 | certs[f.getId] = f.getObject().getContent() |
---|
958 | start = True |
---|
959 | res = table() |
---|
960 | regs = [] |
---|
961 | if len(res) > 0: |
---|
962 | regs = [s.matric_no for s in res] |
---|
963 | for student in returning: |
---|
964 | if start: |
---|
965 | start = False |
---|
966 | logger.info('Start loading from %s.csv' % name) |
---|
967 | s = ','.join(['"%s"' % fn for fn in student.keys()]) |
---|
968 | imported.append(s) |
---|
969 | no_import.append('%s,"Error"' % s) |
---|
970 | format = ','.join(['"%%(%s)s"' % fn for fn in student.keys()]) |
---|
971 | format_error = format + ',"%(Error)s"' |
---|
972 | no_certificate = "no certificate %s" % format |
---|
973 | matric_no = student.get('matric_no').upper() |
---|
974 | student['matric_no'] = matric_no |
---|
975 | if matric_no == '': |
---|
976 | student['Error'] = "Empty matric_no" |
---|
977 | no_import.append( format_error % student) |
---|
978 | continue |
---|
979 | # if matric_no in regs or self.returning_import(matric_no = matric_no): |
---|
980 | # student['Error'] = "Duplicate" |
---|
981 | # no_import.append( format_error % student) |
---|
982 | # continue |
---|
983 | # cert_id = makeCertificateCode(student.get('Coursemajorcode')) |
---|
984 | # if cert_id not in certs.keys(): |
---|
985 | # student['Error'] = "No Certificate %s" % cert_id |
---|
986 | # no_import.append( format_error % student) |
---|
987 | # continue |
---|
988 | try: |
---|
989 | table.modifyRecord(**student) |
---|
990 | except KeyError: |
---|
991 | #import pdb;pdb.set_trace() |
---|
992 | student['Error'] = "no Student found to update" |
---|
993 | no_import.append( format_error % student) |
---|
994 | continue |
---|
995 | #s = self.students_catalog(matric_no=matric_no) |
---|
996 | #if s: |
---|
997 | # level = "%s" % (int(student.get('Level')) + 100) |
---|
998 | # self.students_catalog.modifyRecord(id = s[0].id, |
---|
999 | # level=level) |
---|
1000 | |
---|
1001 | regs.append(student.get('matric_no')) |
---|
1002 | imported.append(format % student) |
---|
1003 | tr_count += 1 |
---|
1004 | if tr_count > 1000: |
---|
1005 | if len(no_import) > 0: |
---|
1006 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
---|
1007 | '\n'.join(no_import) + '\n') |
---|
1008 | no_import = [] |
---|
1009 | open("%s/import/%simported%s.csv" % (i_home,name,current),"a").write( |
---|
1010 | '\n'.join(no_import) + "\n") |
---|
1011 | imported = [] |
---|
1012 | em = '%d transactions commited total %s\n' % (tr_count,total) |
---|
1013 | transaction.commit() |
---|
1014 | regs = [] |
---|
1015 | logger.info(em) |
---|
1016 | total += tr_count |
---|
1017 | tr_count = 0 |
---|
1018 | open("%s/import/%simported%s.csv" % (i_home,name,current),"a").write( |
---|
1019 | '\n'.join(imported)) |
---|
1020 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
---|
1021 | '\n'.join(no_import)) |
---|
1022 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
1023 | ###) |
---|
1024 | |
---|
1025 | security.declareProtected(ModifyPortalContent,"importResults")###( |
---|
1026 | def importResults(self): |
---|
1027 | """load Returning Students Results from CSV""" |
---|
1028 | import transaction |
---|
1029 | import random |
---|
1030 | #from pdb import set_trace |
---|
1031 | wftool = self.portal_workflow |
---|
1032 | current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") |
---|
1033 | students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() |
---|
1034 | tr_count = 1 |
---|
1035 | total = 0 |
---|
1036 | #name = 'pume_results' |
---|
1037 | name = 'Results' |
---|
1038 | table = self.results_import |
---|
1039 | no_import = [] |
---|
1040 | imported = [] |
---|
1041 | logger = logging.getLogger('Students.StudentsFolder.importResults') |
---|
1042 | try: |
---|
1043 | results = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
1044 | except: |
---|
1045 | logger.error('Error reading %s.csv' % name) |
---|
1046 | return |
---|
1047 | l = self.portal_catalog({'meta_type': "Course"}) |
---|
1048 | courses = [f.getId for f in l] |
---|
1049 | start = True |
---|
1050 | res = table() |
---|
1051 | regs = [] |
---|
1052 | if len(res) > 0: |
---|
1053 | regs = [s.key for s in res] |
---|
1054 | no_course = [] |
---|
1055 | no_course_list = [] |
---|
1056 | course_count = 0 |
---|
1057 | for result in results: |
---|
1058 | if start: |
---|
1059 | start = False |
---|
1060 | logger.info('Start loading from %s.csv' % name) |
---|
1061 | s = ','.join(['"%s"' % fn for fn in result.keys()]) |
---|
1062 | imported.append(s) |
---|
1063 | no_import.append('%s,"Error"' % s) |
---|
1064 | format = ','.join(['"%%(%s)s"' % fn for fn in result.keys()]) |
---|
1065 | format_error = format + ',"%(Error)s"' |
---|
1066 | no_certificate = "no certificate %s" % format |
---|
1067 | course_id = result.get('CosCode') |
---|
1068 | if not course_id: |
---|
1069 | course_id = 'N/A' |
---|
1070 | result['CosCode'] = course_id |
---|
1071 | matric_no = result.get('matric_no').upper() |
---|
1072 | result['matric_no'] = matric_no |
---|
1073 | key = matric_no+course_id |
---|
1074 | if matric_no == '': |
---|
1075 | result['Error'] = "Empty matric_no" |
---|
1076 | no_import.append( format_error % result) |
---|
1077 | continue |
---|
1078 | if key in regs or self.results_import(key = key): |
---|
1079 | result['Error'] = "Duplicate" |
---|
1080 | no_import.append( format_error % result) |
---|
1081 | continue |
---|
1082 | if course_id not in courses: |
---|
1083 | if course_id not in no_course: |
---|
1084 | course_count +=1 |
---|
1085 | no_course.append(course_id) |
---|
1086 | no_course_list.append('"%s"' % course_id) |
---|
1087 | #result['Error'] = "No Course" |
---|
1088 | #logger.info(format_error % result) |
---|
1089 | result['key'] = key |
---|
1090 | try: |
---|
1091 | table.addRecord(**result) |
---|
1092 | except ValueError: |
---|
1093 | #import pdb;pdb.set_trace() |
---|
1094 | result['Error'] = "Duplicate" |
---|
1095 | no_import.append( format_error % result) |
---|
1096 | continue |
---|
1097 | regs.append(key) |
---|
1098 | imported.append(format % result) |
---|
1099 | tr_count += 1 |
---|
1100 | if tr_count > 1000: |
---|
1101 | if len(no_import) > 0: |
---|
1102 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
---|
1103 | '\n'.join(no_import)+'\n') |
---|
1104 | no_import = [] |
---|
1105 | open("%s/import/%simported%s.csv" % (i_home,name,current),"a").write( |
---|
1106 | '\n'.join(imported) + '\n') |
---|
1107 | imported = [] |
---|
1108 | if no_course_list: |
---|
1109 | open("%s/import/%sno_courses%s.csv" % (i_home,name,current),"a").write( |
---|
1110 | '\n'.join(no_course_list) + '\n') |
---|
1111 | no_course_list = [] |
---|
1112 | em = '%d transactions commited total %s\n courses not found %s' % (tr_count,total,course_count) |
---|
1113 | transaction.commit() |
---|
1114 | logger.info(em) |
---|
1115 | regs = [] |
---|
1116 | total += tr_count |
---|
1117 | tr_count = 0 |
---|
1118 | open("%s/import/%simported%s.csv" % (i_home,name,current),"a").write( |
---|
1119 | '\n'.join(imported)) |
---|
1120 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
---|
1121 | '\n'.join(no_import)) |
---|
1122 | if no_course_list: |
---|
1123 | open("%s/import/%sno_courses%s.csv" % (i_home,name,current),"a").write( |
---|
1124 | '\n'.join(no_course_list)) |
---|
1125 | em = '%d transactions commited total %s\n courses not found %s' % (tr_count,total,course_count) |
---|
1126 | logger.info(em) |
---|
1127 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
1128 | ###) |
---|
1129 | |
---|
1130 | security.declareProtected(ModifyPortalContent,"updateStudyCourse")###( |
---|
1131 | def updateStudyCourse(self): |
---|
1132 | """update StudyCourse from CSV values""" |
---|
1133 | import transaction |
---|
1134 | import random |
---|
1135 | from pdb import set_trace |
---|
1136 | wftool = self.portal_workflow |
---|
1137 | students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() |
---|
1138 | csv_d = {'jamb_reg_no': "RegNumber", |
---|
1139 | 'jamb_lastname': "Name", |
---|
1140 | 'session': "Session", |
---|
1141 | 'pume_tot_score': "PUME SCORE", |
---|
1142 | 'jamb_score': "JambScore", |
---|
1143 | 'jamb_sex': "Sex", |
---|
1144 | 'jamb_state': "State", |
---|
1145 | ## 'jamb_first_cos': "AdminCourse", |
---|
1146 | 'faculty': "AdminFaculty", |
---|
1147 | 'course_code': "AdmitCoscode", |
---|
1148 | 'stud_status':"AdmitStatus", |
---|
1149 | 'department': "AdmitDept", |
---|
1150 | 'jamb_lga': "LGA", |
---|
1151 | 'app_email': "email", |
---|
1152 | 'app_mobile': "PhoneNumbers", |
---|
1153 | } |
---|
1154 | csv_fields = [f[1] for f in csv_d.items()] |
---|
1155 | tr_count = 0 |
---|
1156 | total = 0 |
---|
1157 | #name = 'pume_results' |
---|
1158 | name = 'StudyCourseChange' |
---|
1159 | no_import = [] |
---|
1160 | s = ','.join(['"%s"' % fn for fn in csv_fields]) |
---|
1161 | no_import.append('"Error",%s' % s) |
---|
1162 | format = '"%(Error)s",' + ','.join(['"%%(%s)s"' % fn for fn in csv_fields]) |
---|
1163 | no_certificate = "no certificate %s" % format |
---|
1164 | open("%s/import/%s_not_imported.csv" % (i_home,name),"w").write( |
---|
1165 | '\n'.join(no_import)) |
---|
1166 | logger = logging.getLogger('Students.StudentsFolder.updateStudyCourse') |
---|
1167 | logger.info('Start loading from %s.csv' % name) |
---|
1168 | l = self.portal_catalog({'meta_type': "Certificate"}) |
---|
1169 | try: |
---|
1170 | result = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
1171 | except: |
---|
1172 | logger.error('Error reading %s.csv' % name) |
---|
1173 | return |
---|
1174 | for jamb in result: |
---|
1175 | jamb['Error'] = "Processing " |
---|
1176 | logger.info(format % jamb) |
---|
1177 | jamb_reg_no = jamb.get(csv_d['jamb_reg_no']) |
---|
1178 | res = self.portal_catalog({'portal_type': "StudentApplication", |
---|
1179 | 'SearchableText': jamb_reg_no }) |
---|
1180 | if not res: |
---|
1181 | em = 'Student with jamb_reg_no %s does not exists\n' % jamb_reg_no |
---|
1182 | logger.info(em) |
---|
1183 | jamb['Error'] = "Student does not exist" |
---|
1184 | no_import.append(format % jamb) |
---|
1185 | continue |
---|
1186 | sid = res[0].getPath().split('/')[-2] |
---|
1187 | cert_id = makeCertificateCode(jamb.get(csv_d['course_code'])) |
---|
1188 | res = self.portal_catalog(portal_type = "Certificate", id = cert_id) |
---|
1189 | if not res: |
---|
1190 | em = 'No Certificate with ID %s \n' % cert_id |
---|
1191 | logger.info(em) |
---|
1192 | jamb['Error'] = "No Certificate %s" % cert_id |
---|
1193 | no_import.append( format % jamb) |
---|
1194 | continue |
---|
1195 | cert_brain = res[0] |
---|
1196 | catalog_entry = {} |
---|
1197 | student = getattr(self,sid) |
---|
1198 | # |
---|
1199 | # Study Course |
---|
1200 | # |
---|
1201 | study_course = student.study_course |
---|
1202 | dsc = {} |
---|
1203 | cert_pl = cert_brain.getPath().split('/') |
---|
1204 | catalog_entry['id'] = sid |
---|
1205 | catalog_entry['faculty'] = cert_pl[-4] |
---|
1206 | catalog_entry['department'] = cert_pl[-3] |
---|
1207 | catalog_entry['course'] = cert_id |
---|
1208 | dsc['study_course'] = cert_id |
---|
1209 | study_course.getContent().edit(mapping=dsc) |
---|
1210 | self.students_catalog.modifyRecord(**catalog_entry) |
---|
1211 | if tr_count > 10: |
---|
1212 | if len(no_import) > 1: |
---|
1213 | open("%s/import/%s_not_imported.csv" % (i_home,name),"w+").write( |
---|
1214 | '\n'.join(no_import)) |
---|
1215 | no_import = [] |
---|
1216 | em = '%d transactions commited\n' % tr_count |
---|
1217 | transaction.commit() |
---|
1218 | logger.info(em) |
---|
1219 | total += tr_count |
---|
1220 | tr_count = 0 |
---|
1221 | tr_count += 1 |
---|
1222 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
1223 | ###) |
---|
1224 | |
---|
1225 | security.declareProtected(View,"fixOwnership") ###( |
---|
1226 | def fixOwnership(self): |
---|
1227 | """fix Ownership""" |
---|
1228 | for s in self.portal_catalog(meta_type = 'Student'): |
---|
1229 | student = s.getObject() |
---|
1230 | sid = s.getId |
---|
1231 | import pdb;pdb.set_trace() |
---|
1232 | student.application.manage_setLocalRoles(sid, ['Owner',]) |
---|
1233 | student.personal.manage_setLocalRoles(sid, ['Owner',]) |
---|
1234 | ###) |
---|
1235 | |
---|
1236 | security.declareProtected(View,"Title") ###( |
---|
1237 | def Title(self): |
---|
1238 | """compose title""" |
---|
1239 | return "Student Section" |
---|
1240 | ###) |
---|
1241 | |
---|
1242 | def generateStudentId(self,letter): ###( |
---|
1243 | import random |
---|
1244 | r = random |
---|
1245 | if letter not in ('ABCDEFGIHKLMNOPQRSTUVWXY'): |
---|
1246 | letter= r.choice('ABCDEFGHKLMNPQRSTUVWXY') |
---|
1247 | students = self.portal_catalog(meta_type = "StudentsFolder")[-1] |
---|
1248 | sid = "%c%d" % (letter,r.randint(99999,1000000)) |
---|
1249 | while hasattr(students, sid): |
---|
1250 | sid = "%c%d" % (letter,r.randint(99999,1000000)) |
---|
1251 | return sid |
---|
1252 | #return "%c%d" % (r.choice('ABCDEFGHKLMNPQRSTUVWXY'),r.randint(99999,1000000)) |
---|
1253 | ###) |
---|
1254 | |
---|
1255 | InitializeClass(StudentsFolder) |
---|
1256 | |
---|
1257 | def addStudentsFolder(container, id, REQUEST=None, **kw): ###( |
---|
1258 | """Add a Student.""" |
---|
1259 | ob = StudentsFolder(id, **kw) |
---|
1260 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
1261 | ###) |
---|
1262 | |
---|
1263 | ###) |
---|
1264 | |
---|
1265 | |
---|
1266 | class Student(CPSDocument): ###( |
---|
1267 | """ |
---|
1268 | WAeUP Student container for the various student data |
---|
1269 | """ |
---|
1270 | meta_type = 'Student' |
---|
1271 | portal_type = meta_type |
---|
1272 | security = ClassSecurityInfo() |
---|
1273 | |
---|
1274 | security.declareProtected(View,"Title") |
---|
1275 | def Title(self): |
---|
1276 | """compose title""" |
---|
1277 | reg_nr = self.getId()[1:] |
---|
1278 | data = getattr(self,'personal',None) |
---|
1279 | if data: |
---|
1280 | content = data.getContent() |
---|
1281 | return "%s %s %s" % (content.firstname,content.middlename,content.lastname) |
---|
1282 | data = getattr(self,'application',None) |
---|
1283 | if data: |
---|
1284 | content = data.getContent() |
---|
1285 | return "%s" % (content.jamb_lastname) |
---|
1286 | return self.title |
---|
1287 | |
---|
1288 | security.declarePrivate('makeStudentMember') ###( |
---|
1289 | def makeStudentMember(self,sid,password='uNsEt'): |
---|
1290 | """make the student a member""" |
---|
1291 | membership = self.portal_membership |
---|
1292 | membership.addMember(sid, |
---|
1293 | password , |
---|
1294 | roles=('Member', |
---|
1295 | 'Student', |
---|
1296 | ), |
---|
1297 | domains='', |
---|
1298 | properties = {'memberareaCreationFlag': False, |
---|
1299 | 'homeless': True},) |
---|
1300 | member = membership.getMemberById(sid) |
---|
1301 | self.portal_registration.afterAdd(member, sid, password, None) |
---|
1302 | self.manage_setLocalRoles(sid, ['Owner',]) |
---|
1303 | |
---|
1304 | ###) |
---|
1305 | |
---|
1306 | security.declareProtected(View,'createSubObjects') ###( |
---|
1307 | def createSubObjects(self): |
---|
1308 | """make the student a member""" |
---|
1309 | dp = {'Title': 'Personal Data'} |
---|
1310 | app_doc = self.application.getContent() |
---|
1311 | names = app_doc.jamb_lastname.split() |
---|
1312 | if len(names) == 3: |
---|
1313 | dp['firstname'] = names[0].capitalize() |
---|
1314 | dp['middlename'] = names[1].capitalize() |
---|
1315 | dp['lastname'] = names[2].capitalize() |
---|
1316 | elif len(names) == 2: |
---|
1317 | dp['firstname'] = names[0].capitalize() |
---|
1318 | dp['lastname'] = names[1].capitalize() |
---|
1319 | else: |
---|
1320 | dp['lastname'] = app_doc.jamb_lastname |
---|
1321 | dp['sex'] = app_doc.jamb_sex == 'F' |
---|
1322 | dp['lga'] = "%s/%s" % (app_doc.jamb_state,app_doc.jamb_lga ) |
---|
1323 | proxy = self.aq_parent |
---|
1324 | proxy.invokeFactory('StudentPersonal','personal') |
---|
1325 | per = proxy.personal |
---|
1326 | per_doc = per.getContent() |
---|
1327 | per_doc.edit(mapping = dp) |
---|
1328 | per.manage_setLocalRoles(proxy.getId(), ['Owner',]) |
---|
1329 | #self.portal_workflow.doActionFor(per,'open',dest_container=per) |
---|
1330 | |
---|
1331 | ###) |
---|
1332 | |
---|
1333 | InitializeClass(Student) |
---|
1334 | |
---|
1335 | def addStudent(container, id, REQUEST=None, **kw): |
---|
1336 | """Add a Student.""" |
---|
1337 | ob = Student(id, **kw) |
---|
1338 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
1339 | |
---|
1340 | ###) |
---|
1341 | |
---|
1342 | class StudentAccommodation(CPSDocument): ###( |
---|
1343 | """ |
---|
1344 | WAeUP Student container for the various student data |
---|
1345 | """ |
---|
1346 | meta_type = 'StudentAccommodation' |
---|
1347 | portal_type = meta_type |
---|
1348 | security = ClassSecurityInfo() |
---|
1349 | |
---|
1350 | security.declareProtected(View,"Title") |
---|
1351 | def Title(self): |
---|
1352 | """compose title""" |
---|
1353 | content = self.getContent() |
---|
1354 | #return "Accommodation Data for %s %s" % (content.firstname,content.lastname) |
---|
1355 | return "Accommodation Data for Session %s" % content.session |
---|
1356 | |
---|
1357 | |
---|
1358 | InitializeClass(StudentAccommodation) |
---|
1359 | |
---|
1360 | def addStudentAccommodation(container, id, REQUEST=None, **kw): |
---|
1361 | """Add a Students personal data.""" |
---|
1362 | ob = StudentAccommodation(id, **kw) |
---|
1363 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
1364 | |
---|
1365 | ###) |
---|
1366 | |
---|
1367 | class StudentPersonal(CPSDocument): ###( |
---|
1368 | """ |
---|
1369 | WAeUP Student container for the various student data |
---|
1370 | """ |
---|
1371 | meta_type = 'StudentPersonal' |
---|
1372 | portal_type = meta_type |
---|
1373 | security = ClassSecurityInfo() |
---|
1374 | |
---|
1375 | security.declareProtected(View,"Title") |
---|
1376 | def Title(self): |
---|
1377 | """compose title""" |
---|
1378 | content = self.getContent() |
---|
1379 | #return "Personal Data for %s %s" % (content.firstname,content.lastname) |
---|
1380 | return "Personal Data" |
---|
1381 | |
---|
1382 | |
---|
1383 | InitializeClass(StudentPersonal) |
---|
1384 | |
---|
1385 | def addStudentPersonal(container, id, REQUEST=None, **kw): |
---|
1386 | """Add a Students personal data.""" |
---|
1387 | ob = StudentPersonal(id, **kw) |
---|
1388 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
1389 | |
---|
1390 | ###) |
---|
1391 | |
---|
1392 | class StudentClearance(CPSDocument): ###( |
---|
1393 | """ |
---|
1394 | WAeUP Student container for the various student data |
---|
1395 | """ |
---|
1396 | meta_type = 'StudentClearance' |
---|
1397 | portal_type = meta_type |
---|
1398 | security = ClassSecurityInfo() |
---|
1399 | |
---|
1400 | security.declareProtected(View,"Title") |
---|
1401 | def Title(self): |
---|
1402 | """compose title""" |
---|
1403 | content = self.getContent() |
---|
1404 | #return "Clearance/Eligibility Record for %s %s" % (content.firstname,content.lastname) |
---|
1405 | return "Clearance/Eligibility Record" |
---|
1406 | |
---|
1407 | |
---|
1408 | InitializeClass(StudentClearance) |
---|
1409 | |
---|
1410 | def addStudentClearance(container, id, REQUEST=None, **kw): |
---|
1411 | """Add a Students personal data.""" |
---|
1412 | ob = StudentClearance(id, **kw) |
---|
1413 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
1414 | |
---|
1415 | ###) |
---|
1416 | |
---|
1417 | class StudentStudyLevel(CPSDocument): ###( |
---|
1418 | """ |
---|
1419 | WAeUP Student container for the various student data |
---|
1420 | """ |
---|
1421 | meta_type = 'StudentStudyLevel' |
---|
1422 | portal_type = meta_type |
---|
1423 | security = ClassSecurityInfo() |
---|
1424 | |
---|
1425 | security.declareProtected(View,"Title") |
---|
1426 | def Title(self): |
---|
1427 | """compose title""" |
---|
1428 | return "Level %s" % self.aq_parent.getId() |
---|
1429 | |
---|
1430 | ## security.declarePublic("gpa") |
---|
1431 | ## def gpa(self): |
---|
1432 | ## """calculate the gpa""" |
---|
1433 | ## sum = 0 |
---|
1434 | ## course_count = 0 |
---|
1435 | ## for sc in self.objectValues(): |
---|
1436 | ## result = sc.getContent() |
---|
1437 | ## if not result.grade: |
---|
1438 | ## continue |
---|
1439 | ## res = self.portal_catalog({'meta_type': 'Course', |
---|
1440 | ## 'id': sc.aq_parent.id}) |
---|
1441 | ## if len(res) != 1: |
---|
1442 | ## continue |
---|
1443 | ## course = res[0].getObject().getContent() |
---|
1444 | ## sum += course.credits * ['F','E','D','C','B','A'].index(result.grade) |
---|
1445 | ## course_count += 1 |
---|
1446 | ## if course_count: |
---|
1447 | ## return sum/course_count |
---|
1448 | ## return 0.0 |
---|
1449 | |
---|
1450 | InitializeClass(StudentStudyLevel) |
---|
1451 | |
---|
1452 | def addStudentStudyLevel(container, id, REQUEST=None, **kw): |
---|
1453 | """Add a Students personal data.""" |
---|
1454 | ob = StudentStudyLevel(id, **kw) |
---|
1455 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
1456 | |
---|
1457 | ###) |
---|
1458 | |
---|
1459 | class StudentStudyCourse(CPSDocument): ###( |
---|
1460 | """ |
---|
1461 | WAeUP Student container for the various student data |
---|
1462 | """ |
---|
1463 | meta_type = 'StudentStudyCourse' |
---|
1464 | portal_type = meta_type |
---|
1465 | security = ClassSecurityInfo() |
---|
1466 | |
---|
1467 | security.declareProtected(View,"Title") |
---|
1468 | def Title(self): |
---|
1469 | """compose title""" |
---|
1470 | content = self.getContent() |
---|
1471 | return "Study Course" |
---|
1472 | |
---|
1473 | |
---|
1474 | InitializeClass(StudentStudyCourse) |
---|
1475 | |
---|
1476 | def addStudentStudyCourse(container, id, REQUEST=None, **kw): |
---|
1477 | """Add a Students personal data.""" |
---|
1478 | ob = StudentStudyCourse(id, **kw) |
---|
1479 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
1480 | |
---|
1481 | ###) |
---|
1482 | |
---|
1483 | class StudentApplication(CPSDocument): ###( |
---|
1484 | """ |
---|
1485 | WAeUP Student container for the various student data |
---|
1486 | """ |
---|
1487 | meta_type = 'StudentApplication' |
---|
1488 | portal_type = meta_type |
---|
1489 | security = ClassSecurityInfo() |
---|
1490 | |
---|
1491 | security.declareProtected(View,"Title") |
---|
1492 | def Title(self): |
---|
1493 | """compose title""" |
---|
1494 | return "Application Data" |
---|
1495 | |
---|
1496 | |
---|
1497 | InitializeClass(StudentApplication) |
---|
1498 | |
---|
1499 | def addStudentApplication(container, id, REQUEST=None, **kw): |
---|
1500 | """Add a Students eligibility data.""" |
---|
1501 | ob = StudentApplication(id, **kw) |
---|
1502 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
1503 | ###) |
---|
1504 | |
---|
1505 | class StudentPume(CPSDocument): ###( |
---|
1506 | """ |
---|
1507 | WAeUP Student container for the various student data |
---|
1508 | """ |
---|
1509 | meta_type = 'StudentPume' |
---|
1510 | portal_type = meta_type |
---|
1511 | security = ClassSecurityInfo() |
---|
1512 | |
---|
1513 | security.declareProtected(View,"Title") |
---|
1514 | def Title(self): |
---|
1515 | """compose title""" |
---|
1516 | return "PUME Results" |
---|
1517 | |
---|
1518 | |
---|
1519 | InitializeClass(StudentPume) |
---|
1520 | |
---|
1521 | def addStudentPume(container, id, REQUEST=None, **kw): |
---|
1522 | """Add a Students PUME data.""" |
---|
1523 | ob = StudentPume(id, **kw) |
---|
1524 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
1525 | ###) |
---|
1526 | |
---|
1527 | ##class StudentSemester(CPSDocument): ###( |
---|
1528 | ## """ |
---|
1529 | ## WAeUP StudentSemester containing the courses and students |
---|
1530 | ## """ |
---|
1531 | ## meta_type = 'StudentSemester' |
---|
1532 | ## portal_type = meta_type |
---|
1533 | ## security = ClassSecurityInfo() |
---|
1534 | ## |
---|
1535 | ##InitializeClass(StudentSemester) |
---|
1536 | ## |
---|
1537 | ##def addStudentSemester(container, id, REQUEST=None, **kw): |
---|
1538 | ## """Add a StudentSemester.""" |
---|
1539 | ## ob = StudentSemester(id, **kw) |
---|
1540 | ## return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
1541 | ## |
---|
1542 | #####) |
---|
1543 | |
---|
1544 | ##class Semester(CPSDocument): ###( |
---|
1545 | ## """ |
---|
1546 | ## WAeUP Semester containing the courses and students |
---|
1547 | ## """ |
---|
1548 | ## meta_type = 'Semester' |
---|
1549 | ## portal_type = meta_type |
---|
1550 | ## security = ClassSecurityInfo() |
---|
1551 | ## |
---|
1552 | ##InitializeClass(Semester) |
---|
1553 | ## |
---|
1554 | ##def addSemester(container, id, REQUEST=None, **kw): |
---|
1555 | ## """Add a Semester.""" |
---|
1556 | ## ob = Semester(id, **kw) |
---|
1557 | ## return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
1558 | ## |
---|
1559 | #####) |
---|
1560 | |
---|
1561 | class StudentCourseResult(CPSDocument): ###( |
---|
1562 | """ |
---|
1563 | WAeUP StudentCourseResult |
---|
1564 | """ |
---|
1565 | meta_type = 'StudentCourseResult' |
---|
1566 | portal_type = meta_type |
---|
1567 | security = ClassSecurityInfo() |
---|
1568 | |
---|
1569 | def getCourseEntry(self,cid): |
---|
1570 | res = self.portal_catalog({'meta_type': "Course", |
---|
1571 | 'id': cid}) |
---|
1572 | if res: |
---|
1573 | return res[-1] |
---|
1574 | else: |
---|
1575 | return None |
---|
1576 | |
---|
1577 | security.declareProtected(View,"Title") |
---|
1578 | def Title(self): |
---|
1579 | """compose title""" |
---|
1580 | cid = self.aq_parent.getId() |
---|
1581 | ce = self.getCourseEntry(cid) |
---|
1582 | if ce: |
---|
1583 | return "%s" % ce.Title |
---|
1584 | return "No course with id %s" % cid |
---|
1585 | |
---|
1586 | InitializeClass(StudentCourseResult) |
---|
1587 | |
---|
1588 | def addStudentCourseResult(container, id, REQUEST=None, **kw): |
---|
1589 | """Add a StudentCourseResult.""" |
---|
1590 | ob = StudentCourseResult(id, **kw) |
---|
1591 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
1592 | ###) |
---|
1593 | |
---|
1594 | # Backward Compatibility StudyLevel |
---|
1595 | |
---|
1596 | from Products.WAeUP_SRP.Academics import StudyLevel |
---|
1597 | |
---|
1598 | from Products.WAeUP_SRP.Academics import addStudyLevel |
---|
1599 | |
---|