[57] | 1 | #-*- mode: python; mode: fold -*- |
---|
[200] | 2 | # $Id: Students.py 765 2006-10-27 11:34:06Z 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',]) |
---|
[763] | 312 | student.invokeFactory('StudentPume','pume') |
---|
| 313 | dp = {'Title': 'Pume Data'} |
---|
[757] | 314 | student.invokeFactory('StudentApplication','application') |
---|
| 315 | da = {'Title': 'Application Data'} |
---|
| 316 | da["jamb_lastname"] = jamb_name |
---|
| 317 | da_fields = ('jamb_reg_no', |
---|
| 318 | 'jamb_sex', |
---|
| 319 | 'jamb_state', |
---|
| 320 | 'jamb_score', |
---|
| 321 | 'jamb_first_cos', |
---|
| 322 | 'jamb_sex', |
---|
| 323 | 'jamb_state', |
---|
| 324 | 'jamb_first_cos', |
---|
| 325 | 'jamb_second_cos', |
---|
| 326 | ) |
---|
[763] | 327 | for f in da_fields: |
---|
| 328 | da[f] = jamb.get(csv_d[f]) |
---|
[757] | 329 | app = student.application |
---|
[763] | 330 | app.getContent().edit(mapping=da) |
---|
[757] | 331 | #wftool.doActionFor(app,'open',dest_container=app) |
---|
| 332 | app.manage_setLocalRoles(sid, ['Owner',]) |
---|
[763] | 333 | dp_fields = ( |
---|
| 334 | 'pume_eng_score', |
---|
[764] | 335 | 'pume_gen_score', |
---|
[763] | 336 | 'pume_tot_score', |
---|
| 337 | ) |
---|
| 338 | for f in dp_fields: |
---|
[765] | 339 | dp[f] = jamb.get(csv_d[f]) |
---|
| 340 | pume = student.pume |
---|
| 341 | pume.getContent().edit(mapping=dp) |
---|
[763] | 342 | wftool.doActionFor(pume,'close',dest_container=app) |
---|
| 343 | pume.manage_setLocalRoles(sid, ['Owner',]) |
---|
[757] | 344 | student.getContent().createSubObjects() |
---|
| 345 | if len(no_import) > 1: |
---|
| 346 | open("%s/import/%s_not_imported.csv" % (i_home,name),"w").write( |
---|
| 347 | '\n'.join(no_import)) |
---|
[742] | 348 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
| 349 | ###) |
---|
| 350 | |
---|
[398] | 351 | security.declareProtected(ModifyPortalContent,"loadFullTimeStudentsResultsFromCSV") ###( |
---|
[396] | 352 | def loadFullTimeStudentsResultsFromCSV(self): |
---|
| 353 | """load Fulltime Studentdata from CSV values""" |
---|
| 354 | #return |
---|
[723] | 355 | level_wf_actions = {} |
---|
| 356 | level_wf_actions["SUCCESSFUL STUDENT"] = "pass_A" |
---|
| 357 | level_wf_actions["STUDENT WITH CARRYOVER COURSES"] = "pass_B" |
---|
[727] | 358 | level_wf_actions["STUDENT FOR PROBATION"] = "probate_C" |
---|
| 359 | level_wf_actions["STUDENT ON PROBATION/TRANSFER"] = "reject_D" |
---|
[398] | 360 | import transaction |
---|
[723] | 361 | wftool = self.portal_workflow |
---|
[398] | 362 | tr_count = 0 |
---|
| 363 | name = 'short_full_time_results_2004_2005' |
---|
[396] | 364 | no_import = False |
---|
| 365 | if not no_import: |
---|
| 366 | no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w") |
---|
| 367 | no_import.write('"Matnumber","CosCode","Ansbook","CosStuatus","Session","Mat_Cos","Score","CarryLevel","Grade","Weight","Semster","Verdict","Level","id","GPA"\n') |
---|
| 368 | logger = logging.getLogger('%s_import' % name) |
---|
| 369 | logger.info('Start loading from %s.csv' % name) |
---|
| 370 | students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() |
---|
| 371 | try: |
---|
| 372 | results = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
| 373 | except: |
---|
| 374 | logger.error('Error reading %s.csv' % name) |
---|
| 375 | return |
---|
[398] | 376 | l = self.portal_catalog({'meta_type': "Course"}) |
---|
| 377 | courses = {} |
---|
| 378 | for c in l: |
---|
| 379 | courses[c.id] = c.getObject() |
---|
[723] | 380 | level_changed = False |
---|
| 381 | student_changed = False |
---|
| 382 | sid = '' |
---|
| 383 | #import pdb;pdb.set_trace() |
---|
[396] | 384 | for result in results: |
---|
[723] | 385 | temp_sid = result.get('Matnumber') |
---|
| 386 | if temp_sid != sid: |
---|
| 387 | student_changed = True |
---|
| 388 | res = self.portal_catalog({'meta_type': "StudentClearance", |
---|
| 389 | 'SearchableText': temp_sid }) |
---|
| 390 | if not res: |
---|
| 391 | em = 'Student with ID %(Matnumber)s not found\n' % result |
---|
| 392 | logger.info(em) |
---|
| 393 | no_import.write(em) |
---|
| 394 | 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) |
---|
| 395 | continue |
---|
| 396 | elif len(res) > 1: |
---|
| 397 | em = 'More than one Student with ID %(Matnumber)s found\n' % result |
---|
| 398 | logger.info(em) |
---|
| 399 | no_import.write(em) |
---|
| 400 | 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) |
---|
| 401 | continue |
---|
| 402 | sid = temp_sid |
---|
| 403 | sf = res[0].getObject().aq_parent |
---|
| 404 | sc = getattr(sf,'study_course') |
---|
| 405 | level = '' |
---|
| 406 | else: |
---|
| 407 | student_changed = False |
---|
[398] | 408 | course = result.get('CosCode') |
---|
| 409 | if course not in courses.keys(): |
---|
| 410 | em = 'Course with ID %(CosCode)s not found\n' % result |
---|
[396] | 411 | logger.info(em) |
---|
| 412 | no_import.write(em) |
---|
[398] | 413 | 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] | 414 | continue |
---|
[727] | 415 | course_doc = courses[course].getContent() |
---|
[723] | 416 | temp_level = result.get('Level') |
---|
[742] | 417 | student_id = sf.getId() |
---|
| 418 | result['StudentId'] = student_id |
---|
[723] | 419 | if temp_level != level: |
---|
| 420 | try: |
---|
| 421 | int(temp_level) |
---|
| 422 | except: |
---|
| 423 | em = 'Result with ID %(Matnumber)s Course %(CosCode)s Level is empty\n' % result |
---|
| 424 | logger.info(em) |
---|
| 425 | no_import.write(em) |
---|
| 426 | 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) |
---|
| 427 | continue |
---|
[727] | 428 | level_changed = True |
---|
| 429 | if 'dlev' in vars().keys(): |
---|
[723] | 430 | wftool.doActionFor(l,level_wf_actions[dlev['verdict']]) |
---|
| 431 | level = temp_level |
---|
| 432 | l = getattr(sc,level,None) |
---|
| 433 | if l is None: |
---|
| 434 | logger.info('Creating Level %(Level)s for %(StudentId)s %(Matnumber)s' % result) |
---|
| 435 | sc.invokeFactory('StudentStudyLevel', level) |
---|
| 436 | l = getattr(sc, level) |
---|
[742] | 437 | l.manage_setLocalRoles(student_id, ['Owner',]) |
---|
[723] | 438 | else: |
---|
| 439 | level_changed = False |
---|
| 440 | cr = getattr(l,course,None) |
---|
| 441 | if cr is None: |
---|
| 442 | logger.info('Creating Course %(CosCode)s for %(StudentId)s %(Matnumber)s in Level %(Level)s' % result) |
---|
| 443 | l.invokeFactory('StudentCourseResult',course) |
---|
| 444 | cr = getattr(l,course) |
---|
| 445 | dcr = {} |
---|
[727] | 446 | from_course = ['title', |
---|
| 447 | 'credits', |
---|
| 448 | 'passmark', |
---|
| 449 | ] |
---|
| 450 | for f in from_course: |
---|
| 451 | dcr[f] = getattr(course_doc,f) |
---|
[454] | 452 | dlev = {} |
---|
[723] | 453 | dcr['ansbook'] = result.get('Ansbook') |
---|
| 454 | dcr['semester'] = getInt(result.get('Semster')) |
---|
| 455 | dcr['status'] = result.get('CosStuatus') |
---|
| 456 | dcr['score'] = getInt(result.get('Score')) |
---|
[454] | 457 | dlev['session'] = result.get('Session') |
---|
[723] | 458 | dcr['carry_level'] = result.get('CarryLevel') |
---|
| 459 | dcr['grade'] = result.get('Grade') |
---|
[725] | 460 | dcr['weight'] = result.get('Weight') |
---|
[454] | 461 | dlev['verdict'] = result.get('Verdict') |
---|
[725] | 462 | dcr['import_id'] = result.get('id') |
---|
| 463 | gpa = result.get('GPA').replace(',','.') |
---|
| 464 | dlev['imported_gpa'] = getFloat(gpa) |
---|
[723] | 465 | cr.getContent().edit(mapping = dcr) |
---|
[742] | 466 | cr.manage_setLocalRoles(student_id, ['Owner',]) |
---|
[454] | 467 | l.getContent().edit(mapping = dlev) |
---|
[398] | 468 | if tr_count > MAX_TRANS: |
---|
| 469 | transaction.commit() |
---|
| 470 | tr_count = 0 |
---|
| 471 | tr_count += 1 |
---|
[723] | 472 | wftool.doActionFor(cr,'close') |
---|
| 473 | wftool.doActionFor(l,level_wf_actions[dlev['verdict']]) |
---|
[681] | 474 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
[426] | 475 | |
---|
[398] | 476 | ###) |
---|
[396] | 477 | |
---|
[457] | 478 | security.declareProtected(ModifyPortalContent,"loadJAMBFromCSV")###( |
---|
| 479 | def loadJAMBFromCSV(self): |
---|
| 480 | """load JAMB data from CSV values""" |
---|
| 481 | #return |
---|
| 482 | students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() |
---|
| 483 | import transaction |
---|
| 484 | tr_count = 0 |
---|
[572] | 485 | name = 'SampleJAMBDataII' |
---|
[511] | 486 | wftool = self.portal_workflow |
---|
[457] | 487 | no_import = False |
---|
| 488 | if not no_import: |
---|
| 489 | no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w") |
---|
| 490 | 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') |
---|
| 491 | logger = logging.getLogger('%s_import' % name) |
---|
| 492 | logger.info('Start loading from %s.csv' % name) |
---|
| 493 | try: |
---|
| 494 | result = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
| 495 | except: |
---|
| 496 | logger.error('Error reading %s.csv' % name) |
---|
| 497 | return |
---|
| 498 | for jamb in result: |
---|
| 499 | 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) |
---|
| 500 | jamb_reg_no = jamb.get('REG-NO') |
---|
[472] | 501 | res = self.portal_catalog({'meta_type': "StudentApplication", |
---|
[457] | 502 | 'jamb_reg_no': jamb_reg_no }) |
---|
| 503 | if res: |
---|
| 504 | em = 'Student with REG-NO %(REG-NO)s already exists\n' % jamb |
---|
| 505 | logger.info(em) |
---|
| 506 | no_import.write(em) |
---|
| 507 | 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) |
---|
| 508 | continue |
---|
[511] | 509 | jamb_name = jamb.get("NAME") |
---|
[584] | 510 | jamb_name.replace('>','') |
---|
[511] | 511 | names = jamb_name.split() |
---|
| 512 | letter = names[-1][0].upper() |
---|
[714] | 513 | sid = self.generateStudentId(letter) |
---|
[457] | 514 | not_created = True |
---|
| 515 | while not_created: |
---|
| 516 | try: |
---|
| 517 | students_folder.invokeFactory('Student', sid) |
---|
| 518 | not_created = False |
---|
| 519 | except BadRequest: |
---|
[714] | 520 | sid = self.generateStudentId(letter) |
---|
[457] | 521 | logger.info('%(tr_count)s: Creating Student with ID %(sid)s REG-NO %(jamb_reg_no)s ' % vars()) |
---|
[511] | 522 | student = getattr(self,sid) |
---|
[519] | 523 | student.manage_setLocalRoles(sid, ['Owner',]) |
---|
[511] | 524 | student.invokeFactory('StudentApplication','application') |
---|
[472] | 525 | da = {'Title': 'Application Data'} |
---|
[457] | 526 | da["jamb_reg_no"] = jamb.get("REG-NO") |
---|
[511] | 527 | da["jamb_lastname"] = jamb_name |
---|
[457] | 528 | da["jamb_sex"] = jamb.get("SEX") |
---|
| 529 | da["jamb_state"] = jamb.get("STATE") |
---|
| 530 | da["jamb_lga"] = jamb.get("LGA") |
---|
| 531 | da["jamb_score"] = jamb.get("AGGREGATE") |
---|
| 532 | da["jamb_first_cos"] = jamb.get("COURSE1") |
---|
| 533 | da["jamb_second_cos"] = jamb.get("COURSE2") |
---|
| 534 | da["jamb_first_uni"] = jamb.get("UNIV1") |
---|
| 535 | da["jamb_second_uni"] = jamb.get("UNIV2") |
---|
[511] | 536 | app = student.application |
---|
| 537 | app_doc = app.getContent() |
---|
| 538 | app_doc.edit(mapping=da) |
---|
[658] | 539 | #wftool.doActionFor(app,'open',dest_container=app) |
---|
[511] | 540 | app.manage_setLocalRoles(sid, ['Owner',]) |
---|
| 541 | student.getContent().createSubObjects() |
---|
[457] | 542 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
| 543 | ###) |
---|
[426] | 544 | |
---|
[472] | 545 | |
---|
[511] | 546 | security.declareProtected(View,"fixOwnership") |
---|
| 547 | def fixOwnership(self): |
---|
| 548 | """fix Ownership""" |
---|
| 549 | for s in self.portal_catalog(meta_type = 'Student'): |
---|
| 550 | student = s.getObject() |
---|
| 551 | sid = s.getId |
---|
| 552 | import pdb;pdb.set_trace() |
---|
| 553 | student.application.manage_setLocalRoles(sid, ['Owner',]) |
---|
| 554 | student.personal.manage_setLocalRoles(sid, ['Owner',]) |
---|
[603] | 555 | |
---|
[364] | 556 | security.declareProtected(View,"Title") |
---|
| 557 | def Title(self): |
---|
| 558 | """compose title""" |
---|
[382] | 559 | return "Student Section" |
---|
[361] | 560 | |
---|
[714] | 561 | def generateStudentId(self,letter): ###( |
---|
| 562 | import random |
---|
| 563 | r = random |
---|
| 564 | if letter not in ('ABCDEFGIHKLMNOPQRSTUVWXY'): |
---|
| 565 | letter= r.choice('ABCDEFGHKLMNPQRSTUVWXY') |
---|
| 566 | students = self.portal_catalog(meta_type = "StudentsFolder")[-1] |
---|
| 567 | sid = "%c%d" % (letter,r.randint(99999,1000000)) |
---|
| 568 | while hasattr(students, sid): |
---|
| 569 | sid = "%c%d" % (letter,r.randint(99999,1000000)) |
---|
[758] | 570 | return sid |
---|
[714] | 571 | #return "%c%d" % (r.choice('ABCDEFGHKLMNPQRSTUVWXY'),r.randint(99999,1000000)) |
---|
| 572 | ###) |
---|
| 573 | |
---|
[361] | 574 | InitializeClass(StudentsFolder) |
---|
| 575 | |
---|
| 576 | def addStudentsFolder(container, id, REQUEST=None, **kw): |
---|
| 577 | """Add a Student.""" |
---|
| 578 | ob = StudentsFolder(id, **kw) |
---|
| 579 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 580 | ###) |
---|
| 581 | |
---|
[57] | 582 | class Student(CPSDocument): ###( |
---|
| 583 | """ |
---|
[154] | 584 | WAeUP Student container for the various student data |
---|
[57] | 585 | """ |
---|
| 586 | meta_type = 'Student' |
---|
| 587 | portal_type = meta_type |
---|
| 588 | security = ClassSecurityInfo() |
---|
[154] | 589 | |
---|
[152] | 590 | security.declareProtected(View,"Title") |
---|
| 591 | def Title(self): |
---|
| 592 | """compose title""" |
---|
[153] | 593 | reg_nr = self.getId()[1:] |
---|
[362] | 594 | data = getattr(self,'personal',None) |
---|
[152] | 595 | if data: |
---|
| 596 | content = data.getContent() |
---|
| 597 | return "%s %s" % (content.firstname,content.lastname) |
---|
[472] | 598 | data = getattr(self,'application',None) |
---|
[464] | 599 | if data: |
---|
| 600 | content = data.getContent() |
---|
| 601 | return "%s" % (content.jamb_lastname) |
---|
[152] | 602 | return self.title |
---|
[154] | 603 | |
---|
[511] | 604 | security.declarePrivate('makeStudentMember') ###( |
---|
| 605 | def makeStudentMember(self,sid,password='uNsEt'): |
---|
| 606 | """make the student a member""" |
---|
| 607 | membership = self.portal_membership |
---|
[603] | 608 | membership.addMember(sid, |
---|
[511] | 609 | password , |
---|
| 610 | roles=('Member', |
---|
| 611 | 'Student', |
---|
[522] | 612 | ), |
---|
[511] | 613 | domains='', |
---|
[522] | 614 | properties = {'memberareaCreationFlag': False,},) |
---|
[511] | 615 | member = membership.getMemberById(sid) |
---|
| 616 | self.portal_registration.afterAdd(member, sid, password, None) |
---|
| 617 | self.manage_setLocalRoles(sid, ['Owner',]) |
---|
| 618 | |
---|
| 619 | ###) |
---|
| 620 | |
---|
[764] | 621 | security.declareProtected(View,'createSubObjects') ###( |
---|
| 622 | def createSubObjects(self): |
---|
| 623 | """make the student a member""" |
---|
| 624 | dp = {'Title': 'Personal Data'} |
---|
| 625 | app_doc = self.application.getContent() |
---|
| 626 | names = app_doc.jamb_lastname.split() |
---|
| 627 | if len(names) == 3: |
---|
| 628 | dp['firstname'] = names[0].capitalize() |
---|
| 629 | dp['middlename'] = names[1].capitalize() |
---|
| 630 | dp['lastname'] = names[2].capitalize() |
---|
| 631 | elif len(names) == 2: |
---|
| 632 | dp['firstname'] = names[0].capitalize() |
---|
| 633 | dp['lastname'] = names[1].capitalize() |
---|
| 634 | else: |
---|
| 635 | dp['lastname'] = app_doc.jamb_lastname |
---|
| 636 | dp['sex'] = app_doc.jamb_sex == 'F' |
---|
| 637 | dp['lga'] = "%s/%s" % (app_doc.jamb_state,app_doc.jamb_lga ) |
---|
| 638 | proxy = self.aq_parent |
---|
| 639 | proxy.invokeFactory('StudentPersonal','personal') |
---|
| 640 | per = proxy.personal |
---|
| 641 | per_doc = per.getContent() |
---|
| 642 | per_doc.edit(mapping = dp) |
---|
| 643 | per.manage_setLocalRoles(self.getId(), ['Owner',]) |
---|
| 644 | #self.portal_workflow.doActionFor(per,'open',dest_container=per) |
---|
[603] | 645 | |
---|
[511] | 646 | ###) |
---|
| 647 | |
---|
[57] | 648 | InitializeClass(Student) |
---|
| 649 | |
---|
| 650 | def addStudent(container, id, REQUEST=None, **kw): |
---|
| 651 | """Add a Student.""" |
---|
| 652 | ob = Student(id, **kw) |
---|
| 653 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 654 | |
---|
| 655 | ###) |
---|
[91] | 656 | |
---|
[639] | 657 | class StudentAccommodation(CPSDocument): ###( |
---|
| 658 | """ |
---|
| 659 | WAeUP Student container for the various student data |
---|
| 660 | """ |
---|
| 661 | meta_type = 'StudentAccommodation' |
---|
| 662 | portal_type = meta_type |
---|
| 663 | security = ClassSecurityInfo() |
---|
| 664 | |
---|
| 665 | security.declareProtected(View,"Title") |
---|
| 666 | def Title(self): |
---|
| 667 | """compose title""" |
---|
| 668 | content = self.getContent() |
---|
| 669 | #return "Accommodation Data for %s %s" % (content.firstname,content.lastname) |
---|
| 670 | return "Accommodation Data for Session %s" % content.session |
---|
| 671 | |
---|
| 672 | |
---|
| 673 | InitializeClass(StudentAccommodation) |
---|
| 674 | |
---|
| 675 | def addStudentAccommodation(container, id, REQUEST=None, **kw): |
---|
| 676 | """Add a Students personal data.""" |
---|
| 677 | ob = StudentAccommodation(id, **kw) |
---|
| 678 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 679 | |
---|
| 680 | ###) |
---|
| 681 | |
---|
[89] | 682 | class StudentPersonal(CPSDocument): ###( |
---|
| 683 | """ |
---|
[154] | 684 | WAeUP Student container for the various student data |
---|
[89] | 685 | """ |
---|
| 686 | meta_type = 'StudentPersonal' |
---|
| 687 | portal_type = meta_type |
---|
| 688 | security = ClassSecurityInfo() |
---|
[152] | 689 | |
---|
| 690 | security.declareProtected(View,"Title") |
---|
| 691 | def Title(self): |
---|
| 692 | """compose title""" |
---|
| 693 | content = self.getContent() |
---|
[364] | 694 | #return "Personal Data for %s %s" % (content.firstname,content.lastname) |
---|
| 695 | return "Personal Data" |
---|
[152] | 696 | |
---|
[154] | 697 | |
---|
[89] | 698 | InitializeClass(StudentPersonal) |
---|
| 699 | |
---|
| 700 | def addStudentPersonal(container, id, REQUEST=None, **kw): |
---|
| 701 | """Add a Students personal data.""" |
---|
| 702 | ob = StudentPersonal(id, **kw) |
---|
| 703 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 704 | |
---|
| 705 | ###) |
---|
| 706 | |
---|
[423] | 707 | class StudentClearance(CPSDocument): ###( |
---|
| 708 | """ |
---|
| 709 | WAeUP Student container for the various student data |
---|
| 710 | """ |
---|
| 711 | meta_type = 'StudentClearance' |
---|
| 712 | portal_type = meta_type |
---|
| 713 | security = ClassSecurityInfo() |
---|
| 714 | |
---|
| 715 | security.declareProtected(View,"Title") |
---|
| 716 | def Title(self): |
---|
| 717 | """compose title""" |
---|
| 718 | content = self.getContent() |
---|
| 719 | #return "Clearance Data for %s %s" % (content.firstname,content.lastname) |
---|
| 720 | return "Clearance Data" |
---|
| 721 | |
---|
| 722 | |
---|
| 723 | InitializeClass(StudentClearance) |
---|
| 724 | |
---|
| 725 | def addStudentClearance(container, id, REQUEST=None, **kw): |
---|
| 726 | """Add a Students personal data.""" |
---|
| 727 | ob = StudentClearance(id, **kw) |
---|
| 728 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 729 | |
---|
| 730 | ###) |
---|
| 731 | |
---|
[454] | 732 | class StudentStudyLevel(CPSDocument): ###( |
---|
| 733 | """ |
---|
| 734 | WAeUP Student container for the various student data |
---|
| 735 | """ |
---|
| 736 | meta_type = 'StudentStudyLevel' |
---|
| 737 | portal_type = meta_type |
---|
| 738 | security = ClassSecurityInfo() |
---|
| 739 | |
---|
| 740 | security.declareProtected(View,"Title") |
---|
| 741 | def Title(self): |
---|
| 742 | """compose title""" |
---|
| 743 | return "Level %s" % self.aq_parent.getId() |
---|
| 744 | |
---|
[723] | 745 | ## security.declarePublic("gpa") |
---|
| 746 | ## def gpa(self): |
---|
| 747 | ## """calculate the gpa""" |
---|
| 748 | ## sum = 0 |
---|
| 749 | ## course_count = 0 |
---|
| 750 | ## for sc in self.objectValues(): |
---|
| 751 | ## result = sc.getContent() |
---|
| 752 | ## if not result.grade: |
---|
| 753 | ## continue |
---|
| 754 | ## res = self.portal_catalog({'meta_type': 'Course', |
---|
| 755 | ## 'id': sc.aq_parent.id}) |
---|
| 756 | ## if len(res) != 1: |
---|
| 757 | ## continue |
---|
| 758 | ## course = res[0].getObject().getContent() |
---|
| 759 | ## sum += course.credits * ['F','E','D','C','B','A'].index(result.grade) |
---|
| 760 | ## course_count += 1 |
---|
| 761 | ## if course_count: |
---|
| 762 | ## return sum/course_count |
---|
| 763 | ## return 0.0 |
---|
[472] | 764 | |
---|
[454] | 765 | InitializeClass(StudentStudyLevel) |
---|
| 766 | |
---|
| 767 | def addStudentStudyLevel(container, id, REQUEST=None, **kw): |
---|
| 768 | """Add a Students personal data.""" |
---|
| 769 | ob = StudentStudyLevel(id, **kw) |
---|
| 770 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 771 | |
---|
| 772 | ###) |
---|
| 773 | |
---|
[362] | 774 | class StudentStudyCourse(CPSDocument): ###( |
---|
| 775 | """ |
---|
| 776 | WAeUP Student container for the various student data |
---|
| 777 | """ |
---|
| 778 | meta_type = 'StudentStudyCourse' |
---|
| 779 | portal_type = meta_type |
---|
| 780 | security = ClassSecurityInfo() |
---|
| 781 | |
---|
[364] | 782 | security.declareProtected(View,"Title") |
---|
| 783 | def Title(self): |
---|
| 784 | """compose title""" |
---|
| 785 | content = self.getContent() |
---|
[453] | 786 | return "Study Course" |
---|
[362] | 787 | |
---|
| 788 | |
---|
| 789 | InitializeClass(StudentStudyCourse) |
---|
| 790 | |
---|
| 791 | def addStudentStudyCourse(container, id, REQUEST=None, **kw): |
---|
| 792 | """Add a Students personal data.""" |
---|
| 793 | ob = StudentStudyCourse(id, **kw) |
---|
| 794 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 795 | |
---|
| 796 | ###) |
---|
| 797 | |
---|
[472] | 798 | class StudentApplication(CPSDocument): ###( |
---|
[179] | 799 | """ |
---|
| 800 | WAeUP Student container for the various student data |
---|
| 801 | """ |
---|
[472] | 802 | meta_type = 'StudentApplication' |
---|
[179] | 803 | portal_type = meta_type |
---|
| 804 | security = ClassSecurityInfo() |
---|
| 805 | |
---|
[181] | 806 | security.declareProtected(View,"Title") |
---|
| 807 | def Title(self): |
---|
| 808 | """compose title""" |
---|
[472] | 809 | return "Application Data" |
---|
[179] | 810 | |
---|
[181] | 811 | |
---|
[472] | 812 | InitializeClass(StudentApplication) |
---|
[179] | 813 | |
---|
[472] | 814 | def addStudentApplication(container, id, REQUEST=None, **kw): |
---|
[179] | 815 | """Add a Students eligibility data.""" |
---|
[472] | 816 | ob = StudentApplication(id, **kw) |
---|
[179] | 817 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
[763] | 818 | ###) |
---|
[179] | 819 | |
---|
[758] | 820 | |
---|
| 821 | class StudentPume(CPSDocument): ###( |
---|
| 822 | """ |
---|
| 823 | WAeUP Student container for the various student data |
---|
| 824 | """ |
---|
| 825 | meta_type = 'StudentPume' |
---|
| 826 | portal_type = meta_type |
---|
| 827 | security = ClassSecurityInfo() |
---|
| 828 | |
---|
| 829 | security.declareProtected(View,"Title") |
---|
| 830 | def Title(self): |
---|
| 831 | """compose title""" |
---|
| 832 | return "PUME Results" |
---|
| 833 | |
---|
| 834 | |
---|
| 835 | InitializeClass(StudentPume) |
---|
| 836 | |
---|
| 837 | def addStudentPume(container, id, REQUEST=None, **kw): |
---|
| 838 | """Add a Students PUME data.""" |
---|
| 839 | ob = StudentPume(id, **kw) |
---|
| 840 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
[179] | 841 | ###) |
---|
[181] | 842 | |
---|
[565] | 843 | ##class StudentSemester(CPSDocument): ###( |
---|
| 844 | ## """ |
---|
| 845 | ## WAeUP StudentSemester containing the courses and students |
---|
| 846 | ## """ |
---|
| 847 | ## meta_type = 'StudentSemester' |
---|
| 848 | ## portal_type = meta_type |
---|
| 849 | ## security = ClassSecurityInfo() |
---|
| 850 | ## |
---|
| 851 | ##InitializeClass(StudentSemester) |
---|
| 852 | ## |
---|
| 853 | ##def addStudentSemester(container, id, REQUEST=None, **kw): |
---|
| 854 | ## """Add a StudentSemester.""" |
---|
| 855 | ## ob = StudentSemester(id, **kw) |
---|
| 856 | ## return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 857 | ## |
---|
| 858 | #####) |
---|
[464] | 859 | |
---|
[758] | 860 | ##class Semester(CPSDocument): ###( |
---|
| 861 | ## """ |
---|
| 862 | ## WAeUP Semester containing the courses and students |
---|
| 863 | ## """ |
---|
| 864 | ## meta_type = 'Semester' |
---|
| 865 | ## portal_type = meta_type |
---|
| 866 | ## security = ClassSecurityInfo() |
---|
| 867 | ## |
---|
| 868 | ##InitializeClass(Semester) |
---|
| 869 | ## |
---|
| 870 | ##def addSemester(container, id, REQUEST=None, **kw): |
---|
| 871 | ## """Add a Semester.""" |
---|
| 872 | ## ob = Semester(id, **kw) |
---|
| 873 | ## return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 874 | ## |
---|
| 875 | #####) |
---|
[464] | 876 | |
---|
| 877 | class StudentCourseResult(CPSDocument): ###( |
---|
[89] | 878 | """ |
---|
[464] | 879 | WAeUP StudentCourseResult |
---|
[89] | 880 | """ |
---|
[464] | 881 | meta_type = 'StudentCourseResult' |
---|
[89] | 882 | portal_type = meta_type |
---|
| 883 | security = ClassSecurityInfo() |
---|
[472] | 884 | |
---|
[454] | 885 | def getCourseEntry(self,cid): |
---|
[723] | 886 | res = self.portal_catalog({'meta_type': "Course", |
---|
[454] | 887 | 'id': cid}) |
---|
| 888 | if res: |
---|
| 889 | return res[-1] |
---|
| 890 | else: |
---|
| 891 | return None |
---|
[154] | 892 | |
---|
[454] | 893 | security.declareProtected(View,"Title") |
---|
| 894 | def Title(self): |
---|
| 895 | """compose title""" |
---|
[723] | 896 | cid = self.aq_parent.getId() |
---|
[454] | 897 | ce = self.getCourseEntry(cid) |
---|
| 898 | if ce: |
---|
| 899 | return "%s" % ce.Title |
---|
| 900 | return "No course with id %s" % cid |
---|
[152] | 901 | |
---|
[464] | 902 | InitializeClass(StudentCourseResult) |
---|
[454] | 903 | |
---|
[464] | 904 | def addStudentCourseResult(container, id, REQUEST=None, **kw): |
---|
| 905 | """Add a StudentCourseResult.""" |
---|
| 906 | ob = StudentCourseResult(id, **kw) |
---|
[89] | 907 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
[139] | 908 | ###) |
---|
| 909 | |
---|
[579] | 910 | # Backward Compatibility StudyLevel |
---|
| 911 | |
---|
| 912 | from Products.WAeUP_SRP.Academics import StudyLevel |
---|
| 913 | |
---|
| 914 | from Products.WAeUP_SRP.Academics import addStudyLevel |
---|
| 915 | |
---|