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