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