[57] | 1 | #-*- mode: python; mode: fold -*- |
---|
[200] | 2 | # $Id: Students.py 766 2006-10-27 16:35:27Z joachim $ |
---|
[708] | 3 | from string import Template |
---|
[45] | 4 | from Globals import InitializeClass |
---|
| 5 | from AccessControl import ClassSecurityInfo |
---|
[164] | 6 | from AccessControl.SecurityManagement import newSecurityManager |
---|
[429] | 7 | from zExceptions import BadRequest |
---|
[502] | 8 | from Products.ZCatalog.ZCatalog import ZCatalog |
---|
[47] | 9 | from Products.CMFCore.utils import UniqueObject, getToolByName |
---|
[45] | 10 | from Products.CMFCore.permissions import View |
---|
| 11 | from Products.CMFCore.permissions import ModifyPortalContent |
---|
[154] | 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 |
---|
[164] | 16 | from Products.CPSCore.CPSMembershipTool import CPSUnrestrictedUser |
---|
[361] | 17 | from Products.WAeUP_SRP.Academics import makeCertificateCode |
---|
[362] | 18 | import logging |
---|
| 19 | import csv,re |
---|
| 20 | import Globals |
---|
| 21 | p_home = Globals.package_home(globals()) |
---|
| 22 | i_home = Globals.INSTANCE_HOME |
---|
[398] | 23 | MAX_TRANS = 1000 |
---|
[154] | 24 | |
---|
[723] | 25 | def getInt(s): |
---|
| 26 | try: |
---|
| 27 | return int(s) |
---|
| 28 | except: |
---|
| 29 | return 0 |
---|
[422] | 30 | |
---|
[725] | 31 | def getFloat(s): |
---|
| 32 | try: |
---|
| 33 | return float(s) |
---|
| 34 | except: |
---|
| 35 | return 0.0 |
---|
| 36 | |
---|
[714] | 37 | def getStudentByRegNo(self,reg_no): ###( |
---|
[502] | 38 | """search student by JAMB Reg No and return StudentFolder""" |
---|
| 39 | search = ZCatalog.searchResults(self.portal_catalog,{'meta_type': 'StudentApplication', |
---|
[606] | 40 | 'SearchableText': reg_no, |
---|
[502] | 41 | }) |
---|
| 42 | if len(search) < 1: |
---|
| 43 | return None |
---|
| 44 | return search[0].getObject().aq_parent |
---|
| 45 | |
---|
[714] | 46 | ###) |
---|
| 47 | |
---|
[361] | 48 | class StudentsFolder(CPSDocument): ###( |
---|
| 49 | """ |
---|
| 50 | WAeUP container for the various WAeUP containers data |
---|
| 51 | """ |
---|
[362] | 52 | meta_type = 'StudentsFolder' |
---|
[361] | 53 | portal_type = meta_type |
---|
| 54 | security = ClassSecurityInfo() |
---|
[154] | 55 | |
---|
[361] | 56 | security.declareProtected(ModifyPortalContent,"loadFullTimeStudentsFromCSV")###( |
---|
| 57 | def loadFullTimeStudentsFromCSV(self): |
---|
| 58 | """load Fulltime Studentdata from CSV values""" |
---|
[398] | 59 | import transaction |
---|
[708] | 60 | import random |
---|
[398] | 61 | tr_count = 0 |
---|
[361] | 62 | name = 'short_full_time' |
---|
| 63 | no_import = False |
---|
[395] | 64 | if not no_import: |
---|
| 65 | no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w") |
---|
| 66 | 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') |
---|
[361] | 67 | logger = logging.getLogger('%s_import' % name) |
---|
| 68 | logger.info('Start loading from %s.csv' % name) |
---|
[708] | 69 | pwlist = [] |
---|
| 70 | pwlist.append('"student_id","firstname","middlename","lastname","matric_no","jamb_reg_no","access_code"') |
---|
| 71 | pwl_template = Template('"$student_id","$firstname","$middlename","$lastname","$matric_no","$jamb_reg_no","$access_code"') |
---|
[361] | 72 | students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() |
---|
| 73 | try: |
---|
| 74 | students = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
| 75 | except: |
---|
| 76 | logger.error('Error reading %s.csv' % name) |
---|
| 77 | return |
---|
[422] | 78 | l = self.portal_catalog({'meta_type': "StudentClearance",}) |
---|
| 79 | matrics = [] |
---|
[361] | 80 | for s in l: |
---|
[422] | 81 | matrics.append(s.getObject().getContent().matric_no) |
---|
[423] | 82 | print matrics |
---|
[361] | 83 | l = self.portal_catalog({'meta_type': "Certificate"}) |
---|
| 84 | certs = {} |
---|
| 85 | for c in l: |
---|
[727] | 86 | ca,ac,fa,dep_id,co,certcode = c.relative_path.split('/') |
---|
| 87 | cid = "%(dep_id)s_%(certcode)s" % vars() |
---|
| 88 | certs[cid] = c.getObject() |
---|
[361] | 89 | for student in students: |
---|
[393] | 90 | 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) |
---|
[361] | 91 | sid = student.get('MatricNo') |
---|
[396] | 92 | if sid == "": |
---|
| 93 | em = 'Empty MatricNo\n' |
---|
| 94 | logger.info(em) |
---|
| 95 | no_import.write(em) |
---|
| 96 | 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) |
---|
| 97 | continue |
---|
[361] | 98 | certcode = makeCertificateCode(student.get('CourseMajor')) |
---|
[727] | 99 | dep_id = student.get('Dept') |
---|
| 100 | fac_id = student.get('Faculty') |
---|
| 101 | cid = "%(dep_id)s_%(certcode)s" % vars() |
---|
| 102 | if cid not in certs.keys(): |
---|
[393] | 103 | em = 'Certificate with ID %s %s not found\n' % (certcode, student.get('CourseMajor')) |
---|
[361] | 104 | logger.info(em) |
---|
[393] | 105 | no_import.write(em) |
---|
| 106 | 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) |
---|
[361] | 107 | continue |
---|
[727] | 108 | certificate_doc = certs[cid].getContent() |
---|
[395] | 109 | level = student.get('StudentLevel') |
---|
[426] | 110 | try: |
---|
[395] | 111 | int(level) |
---|
| 112 | except: |
---|
| 113 | em = 'Student with ID %(MatricNo)s StudentLevel is empty\n' % student |
---|
| 114 | logger.info(em) |
---|
| 115 | no_import.write(em) |
---|
| 116 | 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) |
---|
| 117 | continue |
---|
[422] | 118 | matric_no = student.get('MatricNo') |
---|
| 119 | if matric_no not in matrics: |
---|
| 120 | matrics.append(matric_no) |
---|
[714] | 121 | sid = self.generateStudentId(student.get('Lastname')[0]) |
---|
[361] | 122 | #self.log('Creating Faculty %(id)s = %(Title)s' % faculty) |
---|
[714] | 123 | students_folder.invokeFactory('Student', sid) |
---|
[426] | 124 | logger.info('%(tr_count)s: Creating Student with ID %(sid)s Matric_no %(matric_no)s ' % vars()) |
---|
[714] | 125 | student_obj = getattr(self,sid) |
---|
[708] | 126 | access_code = "%d" % random.randint(1000000000,9999999999) |
---|
[746] | 127 | student_obj.getContent().makeStudentMember(sid,access_code,) |
---|
[708] | 128 | pwl_dict = {'student_id': sid,'access_code':access_code} |
---|
[714] | 129 | student_obj.invokeFactory('StudentApplication','application') |
---|
| 130 | application = student_obj.application |
---|
[472] | 131 | da = {'Title': 'Application Data'} |
---|
[714] | 132 | student_obj.invokeFactory('StudentPersonal','personal') |
---|
[446] | 133 | da['jamb_reg_no'] = student.get('EntryRegNo') |
---|
[714] | 134 | personal = student_obj.personal |
---|
[708] | 135 | dp = {'Title': 'Personal Data'} |
---|
[714] | 136 | student_obj.invokeFactory('StudentClearance','clearance') |
---|
| 137 | clearance = student_obj.clearance |
---|
[422] | 138 | dc = {'Title': 'Clearance Data'} |
---|
| 139 | dc['matric_no'] = matric_no |
---|
[714] | 140 | state = student.get('State') |
---|
| 141 | lga = student.get('LGA') |
---|
| 142 | if state and lga: |
---|
| 143 | lga = state + ' / ' + lga |
---|
| 144 | else: |
---|
| 145 | lga = "None" |
---|
[427] | 146 | dc['lga'] = lga |
---|
[422] | 147 | dc['nationality'] = student.get('Nationality') |
---|
| 148 | dc['email'] = student.get('Emailaddress') |
---|
[708] | 149 | dp['firstname'] = student.get('FirstName') |
---|
| 150 | dp['middlename'] = student.get('MiddleName') |
---|
| 151 | dp['lastname'] = student.get('Lastname') |
---|
| 152 | dp['former_surname'] = student.get('FormerSurname') |
---|
| 153 | dp['sex'] = student.get('Sex') == 'F' |
---|
| 154 | dp['perm_address'] = student.get('PermanentAddress') |
---|
| 155 | dp['perm_city'] = student.get('PermanentAddressCity') |
---|
| 156 | dp['campus_address'] = student.get('CampusAddress') |
---|
| 157 | dp['phone'] = student.get('PhoneNumber') |
---|
[714] | 158 | application.getContent().edit(mapping=da) |
---|
| 159 | personal.getContent().edit(mapping=dp) |
---|
| 160 | clearance.getContent().edit(mapping=dc) |
---|
[362] | 161 | # |
---|
| 162 | # Study Course |
---|
| 163 | # |
---|
[714] | 164 | student_obj.invokeFactory('StudentStudyCourse','study_course') |
---|
| 165 | studycourse = student_obj.study_course |
---|
[708] | 166 | dsc = {} |
---|
[727] | 167 | from_certificate = ['title', |
---|
| 168 | 'max_elect', |
---|
| 169 | 'max_pass', |
---|
| 170 | 'n_core', |
---|
| 171 | 'nr_years', |
---|
| 172 | 'probation_credits', |
---|
| 173 | 'promotion_credits', |
---|
| 174 | 'start_level', |
---|
| 175 | ] |
---|
| 176 | for f in from_certificate: |
---|
| 177 | dsc[f] = getattr(certificate_doc,f) |
---|
| 178 | dsc['faculty'] = fac_id |
---|
| 179 | dsc['department'] = dep_id |
---|
[708] | 180 | dsc['study_course'] = certcode |
---|
[454] | 181 | css = student.get('CurrentSession') or '2004-2005' |
---|
| 182 | cs = int(css.split('-')[0]) - 2000 |
---|
[714] | 183 | cl = int(student.get('StudentLevel') or '100')/100 |
---|
[708] | 184 | dsc['entry_session'] = "200%s" % (cs - cl) |
---|
| 185 | dsc['clr_ac_pin'] = access_code |
---|
[714] | 186 | studycourse.getContent().edit(mapping=dsc) |
---|
[364] | 187 | # |
---|
| 188 | # Level |
---|
| 189 | # |
---|
[723] | 190 | ## l = getattr(studycourse,level,None) |
---|
| 191 | ## if 0 and l is None: |
---|
| 192 | ## #self.log('Creating Department %(DeptCode)s = %(Description)s' % dep) |
---|
| 193 | ## logger.info('Creating Level %(StudentLevel)s for %(fullname)s' % student) |
---|
| 194 | ## studycourse.invokeFactory('StudentStudyLevel', level) |
---|
| 195 | ## l = getattr(studycourse, level) |
---|
| 196 | ## certificate = certs[certcode] |
---|
| 197 | ## cert_level = getattr(certificate,level,None) |
---|
| 198 | ## if cert_level is None: |
---|
| 199 | ## logger.info('Level %(level)s not in %(certcode)s' % vars()) |
---|
| 200 | ## l.getContent().edit(mapping={'Title': "Level %s" % level}) |
---|
[361] | 201 | else: |
---|
[393] | 202 | em = 'Student with ID %(MatricNo)s %(fullname)s already exists\n' % student |
---|
[361] | 203 | logger.info(em) |
---|
[393] | 204 | no_import.write(em) |
---|
| 205 | 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) |
---|
[714] | 206 | continue |
---|
[398] | 207 | if tr_count > MAX_TRANS: |
---|
[422] | 208 | transaction.commit() |
---|
| 209 | em = 'Transaction commited\n' % student |
---|
[398] | 210 | logger.info(em) |
---|
| 211 | tr_count = 0 |
---|
| 212 | tr_count += 1 |
---|
[708] | 213 | pwl_dict.update(dc) |
---|
| 214 | pwl_dict.update(da) |
---|
| 215 | pwl_dict.update(dp) |
---|
[714] | 216 | wftool = self.portal_workflow |
---|
[708] | 217 | pwlist.append(pwl_template.substitute(pwl_dict)) |
---|
[714] | 218 | wftool.doActionFor(student_obj,'clear_and_validate') |
---|
[742] | 219 | student_obj.manage_setLocalRoles(sid, ['Owner',]) |
---|
[714] | 220 | wftool.doActionFor(application,'close') |
---|
[742] | 221 | application.manage_setLocalRoles(sid, ['Owner',]) |
---|
[714] | 222 | wftool.doActionFor(clearance,'close') |
---|
[742] | 223 | clearance.manage_setLocalRoles(sid, ['Owner',]) |
---|
[714] | 224 | wftool.doActionFor(personal,'close') |
---|
[742] | 225 | personal.manage_setLocalRoles(sid, ['Owner',]) |
---|
[727] | 226 | wftool.doActionFor(studycourse,'close_for_edit') |
---|
[742] | 227 | studycourse.manage_setLocalRoles(sid, ['Owner',]) |
---|
[714] | 228 | open("%s/import/pwlist-%s.csv" % (i_home,name),"w+").write('\n'.join(pwlist)) |
---|
[423] | 229 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
[361] | 230 | ###) |
---|
[382] | 231 | |
---|
[742] | 232 | security.declareProtected(ModifyPortalContent,"loadPumeResultsFromCSV")###( |
---|
| 233 | def loadPumeResultsFromCSV(self): |
---|
| 234 | """load Fulltime Studentdata from CSV values""" |
---|
| 235 | import transaction |
---|
| 236 | import random |
---|
[763] | 237 | wftool = self.portal_workflow |
---|
[757] | 238 | students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() |
---|
| 239 | csv_d = {'jamb_reg_no': "Matnumber", |
---|
| 240 | 'jamb_lastname': "Surname", |
---|
| 241 | 'pume_options': "Options", |
---|
| 242 | 'session': "Session", |
---|
| 243 | 'days': "Days", |
---|
| 244 | 'response': "Responce", |
---|
| 245 | 'wrong': "Wrong", |
---|
| 246 | 'pume_eng_score': "EngScore", |
---|
[764] | 247 | 'pume_gen_score': "GenScore", |
---|
| 248 | 'pume_tot_score': "Right", |
---|
[757] | 249 | 'batch': "Batch", |
---|
| 250 | 'serial': "SerialNo", |
---|
| 251 | 'jamb_score': "JambScore", |
---|
| 252 | 'omitted':"Omitted", |
---|
| 253 | 'search_key': "SearchKey", |
---|
| 254 | 'jamb_sex': "Sex", |
---|
| 255 | 'fac1': "Fac1", |
---|
| 256 | 'fac2': "Fac2", |
---|
| 257 | 'jamb_first_cos': "CourseofStudy", |
---|
| 258 | 'stud_status':"StudStatus", |
---|
| 259 | 'registered': "Registered", |
---|
| 260 | 'jamb_state': "State", |
---|
| 261 | 'eng_fail': "EngFail", |
---|
| 262 | 'gen_fail': "GenFail", |
---|
| 263 | 'un_ans_eng': "UnAnsEng", |
---|
| 264 | 'un_ans_eng': "UnAnsGen", |
---|
| 265 | 'total_ans': "TotalUnAns", |
---|
| 266 | 'dept': "Dept", |
---|
| 267 | 'jamb_second_cos': "Course2", |
---|
| 268 | 'jamb_third_cos': "course3", |
---|
| 269 | } |
---|
| 270 | csv_fields = [f[1] for f in csv_d.items()] |
---|
[742] | 271 | tr_count = 0 |
---|
| 272 | name = 'pume_results' |
---|
[757] | 273 | no_import = [] |
---|
| 274 | s = ','.join(['"(%s)"' % fn for fn in csv_fields]) |
---|
| 275 | no_import.append('%s\n' % s) |
---|
[742] | 276 | logger = logging.getLogger('%s_import' % name) |
---|
| 277 | logger.info('Start loading from %s.csv' % name) |
---|
| 278 | try: |
---|
[757] | 279 | result = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
[742] | 280 | except: |
---|
| 281 | logger.error('Error reading %s.csv' % name) |
---|
| 282 | return |
---|
[757] | 283 | for jamb in result: |
---|
| 284 | format = ','.join(['"%%(%s)s"' % fn for fn in csv_fields]) |
---|
| 285 | processing = "processing %s" % format |
---|
| 286 | logger.info(processing % jamb) |
---|
| 287 | jamb_reg_no = jamb.get(csv_d['jamb_reg_no']) |
---|
[763] | 288 | #import pdb;pdb.set_trace() |
---|
| 289 | res = self.portal_catalog({'portal_type': "StudentApplication", |
---|
[757] | 290 | 'jamb_reg_no': jamb_reg_no }) |
---|
| 291 | if res: |
---|
| 292 | em = 'Student with REG-NO %s already exists\n' % jamb_reg_no |
---|
[742] | 293 | logger.info(em) |
---|
[757] | 294 | no_import.append(em) |
---|
| 295 | no_import.append(format % jamb) |
---|
[742] | 296 | continue |
---|
[757] | 297 | jamb_name = jamb.get(csv_d['jamb_lastname']) |
---|
| 298 | jamb_name.replace('>','') |
---|
| 299 | names = jamb_name.split() |
---|
| 300 | letter = names[-1][0].upper() |
---|
| 301 | sid = self.generateStudentId(letter) |
---|
| 302 | not_created = True |
---|
| 303 | while not_created: |
---|
| 304 | try: |
---|
| 305 | students_folder.invokeFactory('Student', sid) |
---|
| 306 | not_created = False |
---|
| 307 | except BadRequest: |
---|
| 308 | sid = self.generateStudentId(letter) |
---|
| 309 | logger.info('%(tr_count)s: Creating Student with ID %(sid)s REG-NO %(jamb_reg_no)s ' % vars()) |
---|
| 310 | student = getattr(self,sid) |
---|
| 311 | student.manage_setLocalRoles(sid, ['Owner',]) |
---|
[766] | 312 | student.invokeFactory('StudentClearance','clearance') |
---|
| 313 | wftool.doActionFor(student.clearance,'open') |
---|
| 314 | dp = {'Title': 'Clearance Data'} |
---|
| 315 | student.clearance.manage_setLocalRoles(sid, ['Owner',]) |
---|
[763] | 316 | student.invokeFactory('StudentPume','pume') |
---|
| 317 | dp = {'Title': 'Pume Data'} |
---|
[757] | 318 | student.invokeFactory('StudentApplication','application') |
---|
| 319 | da = {'Title': 'Application Data'} |
---|
| 320 | da["jamb_lastname"] = jamb_name |
---|
| 321 | da_fields = ('jamb_reg_no', |
---|
| 322 | 'jamb_sex', |
---|
| 323 | 'jamb_state', |
---|
| 324 | 'jamb_score', |
---|
| 325 | 'jamb_first_cos', |
---|
| 326 | 'jamb_sex', |
---|
| 327 | 'jamb_state', |
---|
| 328 | 'jamb_first_cos', |
---|
| 329 | 'jamb_second_cos', |
---|
| 330 | ) |
---|
[763] | 331 | for f in da_fields: |
---|
| 332 | da[f] = jamb.get(csv_d[f]) |
---|
[757] | 333 | app = student.application |
---|
[763] | 334 | app.getContent().edit(mapping=da) |
---|
[757] | 335 | app.manage_setLocalRoles(sid, ['Owner',]) |
---|
[763] | 336 | dp_fields = ( |
---|
| 337 | 'pume_eng_score', |
---|
[764] | 338 | 'pume_gen_score', |
---|
[763] | 339 | 'pume_tot_score', |
---|
| 340 | ) |
---|
| 341 | for f in dp_fields: |
---|
[765] | 342 | dp[f] = jamb.get(csv_d[f]) |
---|
| 343 | pume = student.pume |
---|
| 344 | pume.getContent().edit(mapping=dp) |
---|
[763] | 345 | wftool.doActionFor(pume,'close',dest_container=app) |
---|
| 346 | pume.manage_setLocalRoles(sid, ['Owner',]) |
---|
[757] | 347 | student.getContent().createSubObjects() |
---|
[766] | 348 | wftool.doActionFor(student,'admit',dest_container=student) |
---|
[757] | 349 | if len(no_import) > 1: |
---|
| 350 | open("%s/import/%s_not_imported.csv" % (i_home,name),"w").write( |
---|
| 351 | '\n'.join(no_import)) |
---|
[742] | 352 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
| 353 | ###) |
---|
| 354 | |
---|
[398] | 355 | security.declareProtected(ModifyPortalContent,"loadFullTimeStudentsResultsFromCSV") ###( |
---|
[396] | 356 | def loadFullTimeStudentsResultsFromCSV(self): |
---|
| 357 | """load Fulltime Studentdata from CSV values""" |
---|
| 358 | #return |
---|
[723] | 359 | level_wf_actions = {} |
---|
| 360 | level_wf_actions["SUCCESSFUL STUDENT"] = "pass_A" |
---|
| 361 | level_wf_actions["STUDENT WITH CARRYOVER COURSES"] = "pass_B" |
---|
[727] | 362 | level_wf_actions["STUDENT FOR PROBATION"] = "probate_C" |
---|
| 363 | level_wf_actions["STUDENT ON PROBATION/TRANSFER"] = "reject_D" |
---|
[398] | 364 | import transaction |
---|
[723] | 365 | wftool = self.portal_workflow |
---|
[398] | 366 | tr_count = 0 |
---|
| 367 | name = 'short_full_time_results_2004_2005' |
---|
[396] | 368 | no_import = False |
---|
| 369 | if not no_import: |
---|
| 370 | no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w") |
---|
| 371 | no_import.write('"Matnumber","CosCode","Ansbook","CosStuatus","Session","Mat_Cos","Score","CarryLevel","Grade","Weight","Semster","Verdict","Level","id","GPA"\n') |
---|
| 372 | logger = logging.getLogger('%s_import' % name) |
---|
| 373 | logger.info('Start loading from %s.csv' % name) |
---|
| 374 | students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() |
---|
| 375 | try: |
---|
| 376 | results = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
| 377 | except: |
---|
| 378 | logger.error('Error reading %s.csv' % name) |
---|
| 379 | return |
---|
[398] | 380 | l = self.portal_catalog({'meta_type': "Course"}) |
---|
| 381 | courses = {} |
---|
| 382 | for c in l: |
---|
| 383 | courses[c.id] = c.getObject() |
---|
[723] | 384 | level_changed = False |
---|
| 385 | student_changed = False |
---|
| 386 | sid = '' |
---|
| 387 | #import pdb;pdb.set_trace() |
---|
[396] | 388 | for result in results: |
---|
[723] | 389 | temp_sid = result.get('Matnumber') |
---|
| 390 | if temp_sid != sid: |
---|
| 391 | student_changed = True |
---|
| 392 | res = self.portal_catalog({'meta_type': "StudentClearance", |
---|
| 393 | 'SearchableText': temp_sid }) |
---|
| 394 | if not res: |
---|
| 395 | em = 'Student with ID %(Matnumber)s not found\n' % result |
---|
| 396 | logger.info(em) |
---|
| 397 | no_import.write(em) |
---|
| 398 | 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) |
---|
| 399 | continue |
---|
| 400 | elif len(res) > 1: |
---|
| 401 | em = 'More than one Student with ID %(Matnumber)s found\n' % result |
---|
| 402 | logger.info(em) |
---|
| 403 | no_import.write(em) |
---|
| 404 | 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) |
---|
| 405 | continue |
---|
| 406 | sid = temp_sid |
---|
| 407 | sf = res[0].getObject().aq_parent |
---|
| 408 | sc = getattr(sf,'study_course') |
---|
| 409 | level = '' |
---|
| 410 | else: |
---|
| 411 | student_changed = False |
---|
[398] | 412 | course = result.get('CosCode') |
---|
| 413 | if course not in courses.keys(): |
---|
| 414 | em = 'Course with ID %(CosCode)s not found\n' % result |
---|
[396] | 415 | logger.info(em) |
---|
| 416 | no_import.write(em) |
---|
[398] | 417 | 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) |
---|
[396] | 418 | continue |
---|
[727] | 419 | course_doc = courses[course].getContent() |
---|
[723] | 420 | temp_level = result.get('Level') |
---|
[742] | 421 | student_id = sf.getId() |
---|
| 422 | result['StudentId'] = student_id |
---|
[723] | 423 | if temp_level != level: |
---|
| 424 | try: |
---|
| 425 | int(temp_level) |
---|
| 426 | except: |
---|
| 427 | em = 'Result with ID %(Matnumber)s Course %(CosCode)s Level is empty\n' % result |
---|
| 428 | logger.info(em) |
---|
| 429 | no_import.write(em) |
---|
| 430 | 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) |
---|
| 431 | continue |
---|
[727] | 432 | level_changed = True |
---|
| 433 | if 'dlev' in vars().keys(): |
---|
[723] | 434 | wftool.doActionFor(l,level_wf_actions[dlev['verdict']]) |
---|
| 435 | level = temp_level |
---|
| 436 | l = getattr(sc,level,None) |
---|
| 437 | if l is None: |
---|
| 438 | logger.info('Creating Level %(Level)s for %(StudentId)s %(Matnumber)s' % result) |
---|
| 439 | sc.invokeFactory('StudentStudyLevel', level) |
---|
| 440 | l = getattr(sc, level) |
---|
[742] | 441 | l.manage_setLocalRoles(student_id, ['Owner',]) |
---|
[723] | 442 | else: |
---|
| 443 | level_changed = False |
---|
| 444 | cr = getattr(l,course,None) |
---|
| 445 | if cr is None: |
---|
| 446 | logger.info('Creating Course %(CosCode)s for %(StudentId)s %(Matnumber)s in Level %(Level)s' % result) |
---|
| 447 | l.invokeFactory('StudentCourseResult',course) |
---|
| 448 | cr = getattr(l,course) |
---|
| 449 | dcr = {} |
---|
[727] | 450 | from_course = ['title', |
---|
| 451 | 'credits', |
---|
| 452 | 'passmark', |
---|
| 453 | ] |
---|
| 454 | for f in from_course: |
---|
| 455 | dcr[f] = getattr(course_doc,f) |
---|
[454] | 456 | dlev = {} |
---|
[723] | 457 | dcr['ansbook'] = result.get('Ansbook') |
---|
| 458 | dcr['semester'] = getInt(result.get('Semster')) |
---|
| 459 | dcr['status'] = result.get('CosStuatus') |
---|
| 460 | dcr['score'] = getInt(result.get('Score')) |
---|
[454] | 461 | dlev['session'] = result.get('Session') |
---|
[723] | 462 | dcr['carry_level'] = result.get('CarryLevel') |
---|
| 463 | dcr['grade'] = result.get('Grade') |
---|
[725] | 464 | dcr['weight'] = result.get('Weight') |
---|
[454] | 465 | dlev['verdict'] = result.get('Verdict') |
---|
[725] | 466 | dcr['import_id'] = result.get('id') |
---|
| 467 | gpa = result.get('GPA').replace(',','.') |
---|
| 468 | dlev['imported_gpa'] = getFloat(gpa) |
---|
[723] | 469 | cr.getContent().edit(mapping = dcr) |
---|
[742] | 470 | cr.manage_setLocalRoles(student_id, ['Owner',]) |
---|
[454] | 471 | l.getContent().edit(mapping = dlev) |
---|
[398] | 472 | if tr_count > MAX_TRANS: |
---|
| 473 | transaction.commit() |
---|
| 474 | tr_count = 0 |
---|
| 475 | tr_count += 1 |
---|
[723] | 476 | wftool.doActionFor(cr,'close') |
---|
| 477 | wftool.doActionFor(l,level_wf_actions[dlev['verdict']]) |
---|
[681] | 478 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
[426] | 479 | |
---|
[398] | 480 | ###) |
---|
[396] | 481 | |
---|
[457] | 482 | security.declareProtected(ModifyPortalContent,"loadJAMBFromCSV")###( |
---|
| 483 | def loadJAMBFromCSV(self): |
---|
| 484 | """load JAMB data from CSV values""" |
---|
| 485 | #return |
---|
| 486 | students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() |
---|
| 487 | import transaction |
---|
| 488 | tr_count = 0 |
---|
[572] | 489 | name = 'SampleJAMBDataII' |
---|
[511] | 490 | wftool = self.portal_workflow |
---|
[457] | 491 | no_import = False |
---|
| 492 | if not no_import: |
---|
| 493 | no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w") |
---|
| 494 | 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') |
---|
| 495 | logger = logging.getLogger('%s_import' % name) |
---|
| 496 | logger.info('Start loading from %s.csv' % name) |
---|
| 497 | try: |
---|
| 498 | result = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
| 499 | except: |
---|
| 500 | logger.error('Error reading %s.csv' % name) |
---|
| 501 | return |
---|
| 502 | for jamb in result: |
---|
| 503 | 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) |
---|
| 504 | jamb_reg_no = jamb.get('REG-NO') |
---|
[472] | 505 | res = self.portal_catalog({'meta_type': "StudentApplication", |
---|
[457] | 506 | 'jamb_reg_no': jamb_reg_no }) |
---|
| 507 | if res: |
---|
| 508 | em = 'Student with REG-NO %(REG-NO)s already exists\n' % jamb |
---|
| 509 | logger.info(em) |
---|
| 510 | no_import.write(em) |
---|
| 511 | 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) |
---|
| 512 | continue |
---|
[511] | 513 | jamb_name = jamb.get("NAME") |
---|
[584] | 514 | jamb_name.replace('>','') |
---|
[511] | 515 | names = jamb_name.split() |
---|
| 516 | letter = names[-1][0].upper() |
---|
[714] | 517 | sid = self.generateStudentId(letter) |
---|
[457] | 518 | not_created = True |
---|
| 519 | while not_created: |
---|
| 520 | try: |
---|
| 521 | students_folder.invokeFactory('Student', sid) |
---|
| 522 | not_created = False |
---|
| 523 | except BadRequest: |
---|
[714] | 524 | sid = self.generateStudentId(letter) |
---|
[457] | 525 | logger.info('%(tr_count)s: Creating Student with ID %(sid)s REG-NO %(jamb_reg_no)s ' % vars()) |
---|
[511] | 526 | student = getattr(self,sid) |
---|
[519] | 527 | student.manage_setLocalRoles(sid, ['Owner',]) |
---|
[511] | 528 | student.invokeFactory('StudentApplication','application') |
---|
[472] | 529 | da = {'Title': 'Application Data'} |
---|
[457] | 530 | da["jamb_reg_no"] = jamb.get("REG-NO") |
---|
[511] | 531 | da["jamb_lastname"] = jamb_name |
---|
[457] | 532 | da["jamb_sex"] = jamb.get("SEX") |
---|
| 533 | da["jamb_state"] = jamb.get("STATE") |
---|
| 534 | da["jamb_lga"] = jamb.get("LGA") |
---|
| 535 | da["jamb_score"] = jamb.get("AGGREGATE") |
---|
| 536 | da["jamb_first_cos"] = jamb.get("COURSE1") |
---|
| 537 | da["jamb_second_cos"] = jamb.get("COURSE2") |
---|
| 538 | da["jamb_first_uni"] = jamb.get("UNIV1") |
---|
| 539 | da["jamb_second_uni"] = jamb.get("UNIV2") |
---|
[511] | 540 | app = student.application |
---|
| 541 | app_doc = app.getContent() |
---|
| 542 | app_doc.edit(mapping=da) |
---|
[658] | 543 | #wftool.doActionFor(app,'open',dest_container=app) |
---|
[511] | 544 | app.manage_setLocalRoles(sid, ['Owner',]) |
---|
| 545 | student.getContent().createSubObjects() |
---|
[457] | 546 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
| 547 | ###) |
---|
[426] | 548 | |
---|
[472] | 549 | |
---|
[511] | 550 | security.declareProtected(View,"fixOwnership") |
---|
| 551 | def fixOwnership(self): |
---|
| 552 | """fix Ownership""" |
---|
| 553 | for s in self.portal_catalog(meta_type = 'Student'): |
---|
| 554 | student = s.getObject() |
---|
| 555 | sid = s.getId |
---|
| 556 | import pdb;pdb.set_trace() |
---|
| 557 | student.application.manage_setLocalRoles(sid, ['Owner',]) |
---|
| 558 | student.personal.manage_setLocalRoles(sid, ['Owner',]) |
---|
[603] | 559 | |
---|
[364] | 560 | security.declareProtected(View,"Title") |
---|
| 561 | def Title(self): |
---|
| 562 | """compose title""" |
---|
[382] | 563 | return "Student Section" |
---|
[361] | 564 | |
---|
[714] | 565 | def generateStudentId(self,letter): ###( |
---|
| 566 | import random |
---|
| 567 | r = random |
---|
| 568 | if letter not in ('ABCDEFGIHKLMNOPQRSTUVWXY'): |
---|
| 569 | letter= r.choice('ABCDEFGHKLMNPQRSTUVWXY') |
---|
| 570 | students = self.portal_catalog(meta_type = "StudentsFolder")[-1] |
---|
| 571 | sid = "%c%d" % (letter,r.randint(99999,1000000)) |
---|
| 572 | while hasattr(students, sid): |
---|
| 573 | sid = "%c%d" % (letter,r.randint(99999,1000000)) |
---|
[758] | 574 | return sid |
---|
[714] | 575 | #return "%c%d" % (r.choice('ABCDEFGHKLMNPQRSTUVWXY'),r.randint(99999,1000000)) |
---|
| 576 | ###) |
---|
| 577 | |
---|
[361] | 578 | InitializeClass(StudentsFolder) |
---|
| 579 | |
---|
| 580 | def addStudentsFolder(container, id, REQUEST=None, **kw): |
---|
| 581 | """Add a Student.""" |
---|
| 582 | ob = StudentsFolder(id, **kw) |
---|
| 583 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 584 | ###) |
---|
| 585 | |
---|
[57] | 586 | class Student(CPSDocument): ###( |
---|
| 587 | """ |
---|
[154] | 588 | WAeUP Student container for the various student data |
---|
[57] | 589 | """ |
---|
| 590 | meta_type = 'Student' |
---|
| 591 | portal_type = meta_type |
---|
| 592 | security = ClassSecurityInfo() |
---|
[154] | 593 | |
---|
[152] | 594 | security.declareProtected(View,"Title") |
---|
| 595 | def Title(self): |
---|
| 596 | """compose title""" |
---|
[153] | 597 | reg_nr = self.getId()[1:] |
---|
[362] | 598 | data = getattr(self,'personal',None) |
---|
[152] | 599 | if data: |
---|
| 600 | content = data.getContent() |
---|
| 601 | return "%s %s" % (content.firstname,content.lastname) |
---|
[472] | 602 | data = getattr(self,'application',None) |
---|
[464] | 603 | if data: |
---|
| 604 | content = data.getContent() |
---|
| 605 | return "%s" % (content.jamb_lastname) |
---|
[152] | 606 | return self.title |
---|
[154] | 607 | |
---|
[511] | 608 | security.declarePrivate('makeStudentMember') ###( |
---|
| 609 | def makeStudentMember(self,sid,password='uNsEt'): |
---|
| 610 | """make the student a member""" |
---|
| 611 | membership = self.portal_membership |
---|
[603] | 612 | membership.addMember(sid, |
---|
[511] | 613 | password , |
---|
| 614 | roles=('Member', |
---|
| 615 | 'Student', |
---|
[522] | 616 | ), |
---|
[511] | 617 | domains='', |
---|
[522] | 618 | properties = {'memberareaCreationFlag': False,},) |
---|
[511] | 619 | member = membership.getMemberById(sid) |
---|
| 620 | self.portal_registration.afterAdd(member, sid, password, None) |
---|
| 621 | self.manage_setLocalRoles(sid, ['Owner',]) |
---|
| 622 | |
---|
| 623 | ###) |
---|
| 624 | |
---|
[764] | 625 | security.declareProtected(View,'createSubObjects') ###( |
---|
| 626 | def createSubObjects(self): |
---|
| 627 | """make the student a member""" |
---|
| 628 | dp = {'Title': 'Personal Data'} |
---|
| 629 | app_doc = self.application.getContent() |
---|
| 630 | names = app_doc.jamb_lastname.split() |
---|
| 631 | if len(names) == 3: |
---|
| 632 | dp['firstname'] = names[0].capitalize() |
---|
| 633 | dp['middlename'] = names[1].capitalize() |
---|
| 634 | dp['lastname'] = names[2].capitalize() |
---|
| 635 | elif len(names) == 2: |
---|
| 636 | dp['firstname'] = names[0].capitalize() |
---|
| 637 | dp['lastname'] = names[1].capitalize() |
---|
| 638 | else: |
---|
| 639 | dp['lastname'] = app_doc.jamb_lastname |
---|
| 640 | dp['sex'] = app_doc.jamb_sex == 'F' |
---|
| 641 | dp['lga'] = "%s/%s" % (app_doc.jamb_state,app_doc.jamb_lga ) |
---|
| 642 | proxy = self.aq_parent |
---|
| 643 | proxy.invokeFactory('StudentPersonal','personal') |
---|
| 644 | per = proxy.personal |
---|
| 645 | per_doc = per.getContent() |
---|
| 646 | per_doc.edit(mapping = dp) |
---|
| 647 | per.manage_setLocalRoles(self.getId(), ['Owner',]) |
---|
| 648 | #self.portal_workflow.doActionFor(per,'open',dest_container=per) |
---|
[603] | 649 | |
---|
[511] | 650 | ###) |
---|
| 651 | |
---|
[57] | 652 | InitializeClass(Student) |
---|
| 653 | |
---|
| 654 | def addStudent(container, id, REQUEST=None, **kw): |
---|
| 655 | """Add a Student.""" |
---|
| 656 | ob = Student(id, **kw) |
---|
| 657 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 658 | |
---|
| 659 | ###) |
---|
[91] | 660 | |
---|
[639] | 661 | class StudentAccommodation(CPSDocument): ###( |
---|
| 662 | """ |
---|
| 663 | WAeUP Student container for the various student data |
---|
| 664 | """ |
---|
| 665 | meta_type = 'StudentAccommodation' |
---|
| 666 | portal_type = meta_type |
---|
| 667 | security = ClassSecurityInfo() |
---|
| 668 | |
---|
| 669 | security.declareProtected(View,"Title") |
---|
| 670 | def Title(self): |
---|
| 671 | """compose title""" |
---|
| 672 | content = self.getContent() |
---|
| 673 | #return "Accommodation Data for %s %s" % (content.firstname,content.lastname) |
---|
| 674 | return "Accommodation Data for Session %s" % content.session |
---|
| 675 | |
---|
| 676 | |
---|
| 677 | InitializeClass(StudentAccommodation) |
---|
| 678 | |
---|
| 679 | def addStudentAccommodation(container, id, REQUEST=None, **kw): |
---|
| 680 | """Add a Students personal data.""" |
---|
| 681 | ob = StudentAccommodation(id, **kw) |
---|
| 682 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 683 | |
---|
| 684 | ###) |
---|
| 685 | |
---|
[89] | 686 | class StudentPersonal(CPSDocument): ###( |
---|
| 687 | """ |
---|
[154] | 688 | WAeUP Student container for the various student data |
---|
[89] | 689 | """ |
---|
| 690 | meta_type = 'StudentPersonal' |
---|
| 691 | portal_type = meta_type |
---|
| 692 | security = ClassSecurityInfo() |
---|
[152] | 693 | |
---|
| 694 | security.declareProtected(View,"Title") |
---|
| 695 | def Title(self): |
---|
| 696 | """compose title""" |
---|
| 697 | content = self.getContent() |
---|
[364] | 698 | #return "Personal Data for %s %s" % (content.firstname,content.lastname) |
---|
| 699 | return "Personal Data" |
---|
[152] | 700 | |
---|
[154] | 701 | |
---|
[89] | 702 | InitializeClass(StudentPersonal) |
---|
| 703 | |
---|
| 704 | def addStudentPersonal(container, id, REQUEST=None, **kw): |
---|
| 705 | """Add a Students personal data.""" |
---|
| 706 | ob = StudentPersonal(id, **kw) |
---|
| 707 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 708 | |
---|
| 709 | ###) |
---|
| 710 | |
---|
[423] | 711 | class StudentClearance(CPSDocument): ###( |
---|
| 712 | """ |
---|
| 713 | WAeUP Student container for the various student data |
---|
| 714 | """ |
---|
| 715 | meta_type = 'StudentClearance' |
---|
| 716 | portal_type = meta_type |
---|
| 717 | security = ClassSecurityInfo() |
---|
| 718 | |
---|
| 719 | security.declareProtected(View,"Title") |
---|
| 720 | def Title(self): |
---|
| 721 | """compose title""" |
---|
| 722 | content = self.getContent() |
---|
| 723 | #return "Clearance Data for %s %s" % (content.firstname,content.lastname) |
---|
| 724 | return "Clearance Data" |
---|
| 725 | |
---|
| 726 | |
---|
| 727 | InitializeClass(StudentClearance) |
---|
| 728 | |
---|
| 729 | def addStudentClearance(container, id, REQUEST=None, **kw): |
---|
| 730 | """Add a Students personal data.""" |
---|
| 731 | ob = StudentClearance(id, **kw) |
---|
| 732 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 733 | |
---|
| 734 | ###) |
---|
| 735 | |
---|
[454] | 736 | class StudentStudyLevel(CPSDocument): ###( |
---|
| 737 | """ |
---|
| 738 | WAeUP Student container for the various student data |
---|
| 739 | """ |
---|
| 740 | meta_type = 'StudentStudyLevel' |
---|
| 741 | portal_type = meta_type |
---|
| 742 | security = ClassSecurityInfo() |
---|
| 743 | |
---|
| 744 | security.declareProtected(View,"Title") |
---|
| 745 | def Title(self): |
---|
| 746 | """compose title""" |
---|
| 747 | return "Level %s" % self.aq_parent.getId() |
---|
| 748 | |
---|
[723] | 749 | ## security.declarePublic("gpa") |
---|
| 750 | ## def gpa(self): |
---|
| 751 | ## """calculate the gpa""" |
---|
| 752 | ## sum = 0 |
---|
| 753 | ## course_count = 0 |
---|
| 754 | ## for sc in self.objectValues(): |
---|
| 755 | ## result = sc.getContent() |
---|
| 756 | ## if not result.grade: |
---|
| 757 | ## continue |
---|
| 758 | ## res = self.portal_catalog({'meta_type': 'Course', |
---|
| 759 | ## 'id': sc.aq_parent.id}) |
---|
| 760 | ## if len(res) != 1: |
---|
| 761 | ## continue |
---|
| 762 | ## course = res[0].getObject().getContent() |
---|
| 763 | ## sum += course.credits * ['F','E','D','C','B','A'].index(result.grade) |
---|
| 764 | ## course_count += 1 |
---|
| 765 | ## if course_count: |
---|
| 766 | ## return sum/course_count |
---|
| 767 | ## return 0.0 |
---|
[472] | 768 | |
---|
[454] | 769 | InitializeClass(StudentStudyLevel) |
---|
| 770 | |
---|
| 771 | def addStudentStudyLevel(container, id, REQUEST=None, **kw): |
---|
| 772 | """Add a Students personal data.""" |
---|
| 773 | ob = StudentStudyLevel(id, **kw) |
---|
| 774 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 775 | |
---|
| 776 | ###) |
---|
| 777 | |
---|
[362] | 778 | class StudentStudyCourse(CPSDocument): ###( |
---|
| 779 | """ |
---|
| 780 | WAeUP Student container for the various student data |
---|
| 781 | """ |
---|
| 782 | meta_type = 'StudentStudyCourse' |
---|
| 783 | portal_type = meta_type |
---|
| 784 | security = ClassSecurityInfo() |
---|
| 785 | |
---|
[364] | 786 | security.declareProtected(View,"Title") |
---|
| 787 | def Title(self): |
---|
| 788 | """compose title""" |
---|
| 789 | content = self.getContent() |
---|
[453] | 790 | return "Study Course" |
---|
[362] | 791 | |
---|
| 792 | |
---|
| 793 | InitializeClass(StudentStudyCourse) |
---|
| 794 | |
---|
| 795 | def addStudentStudyCourse(container, id, REQUEST=None, **kw): |
---|
| 796 | """Add a Students personal data.""" |
---|
| 797 | ob = StudentStudyCourse(id, **kw) |
---|
| 798 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 799 | |
---|
| 800 | ###) |
---|
| 801 | |
---|
[472] | 802 | class StudentApplication(CPSDocument): ###( |
---|
[179] | 803 | """ |
---|
| 804 | WAeUP Student container for the various student data |
---|
| 805 | """ |
---|
[472] | 806 | meta_type = 'StudentApplication' |
---|
[179] | 807 | portal_type = meta_type |
---|
| 808 | security = ClassSecurityInfo() |
---|
| 809 | |
---|
[181] | 810 | security.declareProtected(View,"Title") |
---|
| 811 | def Title(self): |
---|
| 812 | """compose title""" |
---|
[472] | 813 | return "Application Data" |
---|
[179] | 814 | |
---|
[181] | 815 | |
---|
[472] | 816 | InitializeClass(StudentApplication) |
---|
[179] | 817 | |
---|
[472] | 818 | def addStudentApplication(container, id, REQUEST=None, **kw): |
---|
[179] | 819 | """Add a Students eligibility data.""" |
---|
[472] | 820 | ob = StudentApplication(id, **kw) |
---|
[179] | 821 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
[763] | 822 | ###) |
---|
[179] | 823 | |
---|
[758] | 824 | |
---|
| 825 | class StudentPume(CPSDocument): ###( |
---|
| 826 | """ |
---|
| 827 | WAeUP Student container for the various student data |
---|
| 828 | """ |
---|
| 829 | meta_type = 'StudentPume' |
---|
| 830 | portal_type = meta_type |
---|
| 831 | security = ClassSecurityInfo() |
---|
| 832 | |
---|
| 833 | security.declareProtected(View,"Title") |
---|
| 834 | def Title(self): |
---|
| 835 | """compose title""" |
---|
| 836 | return "PUME Results" |
---|
| 837 | |
---|
| 838 | |
---|
| 839 | InitializeClass(StudentPume) |
---|
| 840 | |
---|
| 841 | def addStudentPume(container, id, REQUEST=None, **kw): |
---|
| 842 | """Add a Students PUME data.""" |
---|
| 843 | ob = StudentPume(id, **kw) |
---|
| 844 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
[179] | 845 | ###) |
---|
[181] | 846 | |
---|
[565] | 847 | ##class StudentSemester(CPSDocument): ###( |
---|
| 848 | ## """ |
---|
| 849 | ## WAeUP StudentSemester containing the courses and students |
---|
| 850 | ## """ |
---|
| 851 | ## meta_type = 'StudentSemester' |
---|
| 852 | ## portal_type = meta_type |
---|
| 853 | ## security = ClassSecurityInfo() |
---|
| 854 | ## |
---|
| 855 | ##InitializeClass(StudentSemester) |
---|
| 856 | ## |
---|
| 857 | ##def addStudentSemester(container, id, REQUEST=None, **kw): |
---|
| 858 | ## """Add a StudentSemester.""" |
---|
| 859 | ## ob = StudentSemester(id, **kw) |
---|
| 860 | ## return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 861 | ## |
---|
| 862 | #####) |
---|
[464] | 863 | |
---|
[758] | 864 | ##class Semester(CPSDocument): ###( |
---|
| 865 | ## """ |
---|
| 866 | ## WAeUP Semester containing the courses and students |
---|
| 867 | ## """ |
---|
| 868 | ## meta_type = 'Semester' |
---|
| 869 | ## portal_type = meta_type |
---|
| 870 | ## security = ClassSecurityInfo() |
---|
| 871 | ## |
---|
| 872 | ##InitializeClass(Semester) |
---|
| 873 | ## |
---|
| 874 | ##def addSemester(container, id, REQUEST=None, **kw): |
---|
| 875 | ## """Add a Semester.""" |
---|
| 876 | ## ob = Semester(id, **kw) |
---|
| 877 | ## return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 878 | ## |
---|
| 879 | #####) |
---|
[464] | 880 | |
---|
| 881 | class StudentCourseResult(CPSDocument): ###( |
---|
[89] | 882 | """ |
---|
[464] | 883 | WAeUP StudentCourseResult |
---|
[89] | 884 | """ |
---|
[464] | 885 | meta_type = 'StudentCourseResult' |
---|
[89] | 886 | portal_type = meta_type |
---|
| 887 | security = ClassSecurityInfo() |
---|
[472] | 888 | |
---|
[454] | 889 | def getCourseEntry(self,cid): |
---|
[723] | 890 | res = self.portal_catalog({'meta_type': "Course", |
---|
[454] | 891 | 'id': cid}) |
---|
| 892 | if res: |
---|
| 893 | return res[-1] |
---|
| 894 | else: |
---|
| 895 | return None |
---|
[154] | 896 | |
---|
[454] | 897 | security.declareProtected(View,"Title") |
---|
| 898 | def Title(self): |
---|
| 899 | """compose title""" |
---|
[723] | 900 | cid = self.aq_parent.getId() |
---|
[454] | 901 | ce = self.getCourseEntry(cid) |
---|
| 902 | if ce: |
---|
| 903 | return "%s" % ce.Title |
---|
| 904 | return "No course with id %s" % cid |
---|
[152] | 905 | |
---|
[464] | 906 | InitializeClass(StudentCourseResult) |
---|
[454] | 907 | |
---|
[464] | 908 | def addStudentCourseResult(container, id, REQUEST=None, **kw): |
---|
| 909 | """Add a StudentCourseResult.""" |
---|
| 910 | ob = StudentCourseResult(id, **kw) |
---|
[89] | 911 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
[139] | 912 | ###) |
---|
| 913 | |
---|
[579] | 914 | # Backward Compatibility StudyLevel |
---|
| 915 | |
---|
| 916 | from Products.WAeUP_SRP.Academics import StudyLevel |
---|
| 917 | |
---|
| 918 | from Products.WAeUP_SRP.Academics import addStudyLevel |
---|
| 919 | |
---|