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