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