[57] | 1 | #-*- mode: python; mode: fold -*- |
---|
[200] | 2 | # $Id: Students.py 382 2006-08-16 22:09:45Z henrik $ |
---|
[45] | 3 | from Globals import InitializeClass |
---|
| 4 | from AccessControl import ClassSecurityInfo |
---|
[164] | 5 | from AccessControl.SecurityManagement import newSecurityManager |
---|
[45] | 6 | |
---|
[47] | 7 | from Products.CMFCore.utils import UniqueObject, getToolByName |
---|
[45] | 8 | from Products.CMFCore.permissions import View |
---|
| 9 | from Products.CMFCore.permissions import ModifyPortalContent |
---|
[154] | 10 | from Products.CPSCore.CPSBase import CPSBase_adder, CPSBaseFolder |
---|
| 11 | #from Products.CPSCore.CPSBase import CPSBaseDocument as BaseDocument |
---|
| 12 | from Products.CPSDocument.CPSDocument import CPSDocument |
---|
| 13 | from Products.CPSCore.CPSBase import CPSBaseBTreeFolder as BaseBTreeFolder |
---|
[164] | 14 | from Products.CPSCore.CPSMembershipTool import CPSUnrestrictedUser |
---|
[361] | 15 | from Products.WAeUP_SRP.Academics import makeCertificateCode |
---|
[362] | 16 | import logging |
---|
| 17 | import csv,re |
---|
| 18 | import Globals |
---|
| 19 | p_home = Globals.package_home(globals()) |
---|
| 20 | i_home = Globals.INSTANCE_HOME |
---|
[154] | 21 | |
---|
[361] | 22 | class StudentsFolder(CPSDocument): ###( |
---|
| 23 | """ |
---|
| 24 | WAeUP container for the various WAeUP containers data |
---|
| 25 | """ |
---|
[362] | 26 | meta_type = 'StudentsFolder' |
---|
[361] | 27 | portal_type = meta_type |
---|
| 28 | security = ClassSecurityInfo() |
---|
[154] | 29 | |
---|
[361] | 30 | security.declareProtected(ModifyPortalContent,"loadFullTimeStudentsFromCSV")###( |
---|
| 31 | def loadFullTimeStudentsFromCSV(self): |
---|
| 32 | """load Fulltime Studentdata from CSV values""" |
---|
| 33 | #return |
---|
| 34 | name = 'short_full_time' |
---|
| 35 | no_import = False |
---|
| 36 | logger = logging.getLogger('%s_import' % name) |
---|
| 37 | logger.info('Start loading from %s.csv' % name) |
---|
| 38 | students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() |
---|
| 39 | try: |
---|
| 40 | students = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
| 41 | except: |
---|
| 42 | logger.error('Error reading %s.csv' % name) |
---|
| 43 | return |
---|
| 44 | l = self.portal_catalog({'meta_type': "Student"}) |
---|
| 45 | studs = {} |
---|
| 46 | for s in l: |
---|
| 47 | studs[s.id] = s.getObject() |
---|
| 48 | l = self.portal_catalog({'meta_type': "Certificate"}) |
---|
| 49 | certs = {} |
---|
| 50 | for c in l: |
---|
[362] | 51 | certs[c.id] = c.getObject() |
---|
[361] | 52 | for student in students: |
---|
| 53 | 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"' % student) |
---|
| 54 | sid = student.get('MatricNo') |
---|
| 55 | certcode = makeCertificateCode(student.get('CourseMajor')) |
---|
| 56 | s = studs.get(sid,None) |
---|
| 57 | if certcode not in certs.keys(): |
---|
| 58 | em = 'Certificate with ID %s %s not found' % (certcode, student.get('CourseMajor')) |
---|
| 59 | if not no_import: |
---|
| 60 | no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w") |
---|
| 61 | 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') |
---|
| 62 | logger.info(em) |
---|
| 63 | 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"' % student) |
---|
| 64 | continue |
---|
| 65 | if s is None: |
---|
| 66 | #self.log('Creating Faculty %(id)s = %(Title)s' % faculty) |
---|
[362] | 67 | logger.info('Creating Student with ID %(MatricNo)s %(fullname)s' % student) |
---|
[361] | 68 | students_folder.invokeFactory('Student', sid) |
---|
| 69 | s = getattr(self,sid) |
---|
| 70 | s.invokeFactory('StudentPersonal','personal') |
---|
[362] | 71 | sp = s.personal |
---|
[361] | 72 | d = {'Title': 'Personal Data'} |
---|
[362] | 73 | d['matricel_no'] = student.get('MatricNo') |
---|
| 74 | d['entry_reg_no'] = student.get('EntryRegNo') |
---|
[361] | 75 | d['fullname'] = student.get('fullname') |
---|
| 76 | d['firstname'] = student.get('FirstName') |
---|
| 77 | d['middlename'] = student.get('MiddleName') |
---|
[362] | 78 | d['lastname'] = student.get('Lastname') |
---|
[361] | 79 | d['former_surname'] = student.get('FormerSurname') |
---|
[362] | 80 | d['sex'] = student.get('Sex') == 'F' |
---|
[361] | 81 | d['nationality'] = student.get('Nationality') |
---|
[382] | 82 | d['state'] = student.get('State') |
---|
| 83 | d['lga'] = student.get('LGA') |
---|
[361] | 84 | d['street'] = student.get('PermanentAddress') |
---|
| 85 | d['city'] = student.get('PermanentAddressCity') |
---|
| 86 | d['campus_address'] = student.get('CampusAddress') |
---|
| 87 | d['phone'] = student.get('PhoneNumber') |
---|
[362] | 88 | d['email'] = student.get('Emailaddress') |
---|
| 89 | sp.getContent().edit(mapping=d) |
---|
| 90 | # |
---|
| 91 | # Study Course |
---|
| 92 | # |
---|
| 93 | s.invokeFactory('StudentStudyCourse','study_course') |
---|
| 94 | sc = s.study_course |
---|
| 95 | d = {} |
---|
| 96 | d['matricel_no'] = student.get('MatricNo') |
---|
| 97 | d['entry_reg_no'] = student.get('EntryRegNo') |
---|
| 98 | d['faculty'] = student.get('Faculty') |
---|
| 99 | d['department'] = student.get('Dept') |
---|
| 100 | d['course_major'] = certcode |
---|
| 101 | css = student.get('CurrentSession') or '2004-2005' |
---|
| 102 | cs = int(css.split('-')[0]) - 2000 |
---|
| 103 | cl = int(student.get('StudentLevel'))/100 |
---|
| 104 | d['entry_session'] = "200%s" % (cs - cl) |
---|
| 105 | sc.getContent().edit(mapping=d) |
---|
[364] | 106 | # |
---|
| 107 | # Level |
---|
| 108 | # |
---|
| 109 | level = student.get('StudentLevel') |
---|
| 110 | l = getattr(sc,level,None) |
---|
| 111 | if l is None: |
---|
| 112 | #self.log('Creating Department %(DeptCode)s = %(Description)s' % dep) |
---|
| 113 | logger.info('Creating Level %(StudentLevel)s for %(fullname)s' % student) |
---|
| 114 | sc.invokeFactory('StudyLevel', level) |
---|
| 115 | l = getattr(sc, level) |
---|
| 116 | certificate = certs[certcode] |
---|
| 117 | cert_level = getattr(certificate,level,None) |
---|
| 118 | if cert_level is None: |
---|
| 119 | logger.info('Level %(level)s not in %(certcode)s' % vars()) |
---|
| 120 | l.getContent().edit(mapping={'Title': "Level %s" % level}) |
---|
| 121 | l.invokeFactory('Semester','first') |
---|
| 122 | l.invokeFactory('Semester','second') |
---|
| 123 | first_s = getattr(l,'first') |
---|
| 124 | first_s.getContent().edit(mapping={'Title': 'First Semester'}) |
---|
| 125 | second_s = getattr(l,'second') |
---|
| 126 | second_s.getContent().edit(mapping={'Title': 'Second Semester'}) |
---|
[361] | 127 | else: |
---|
| 128 | em = 'Faculty with ID %(MatricNo)s %(fullname)s already exists' % student |
---|
| 129 | if not no_import: |
---|
| 130 | no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w") |
---|
| 131 | 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') |
---|
| 132 | logger.info(em) |
---|
| 133 | 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"' % student) |
---|
| 134 | return self.students.folder_contents() |
---|
| 135 | ###) |
---|
[382] | 136 | |
---|
[364] | 137 | security.declareProtected(View,"Title") |
---|
| 138 | def Title(self): |
---|
| 139 | """compose title""" |
---|
[382] | 140 | return "Student Section" |
---|
[361] | 141 | |
---|
| 142 | InitializeClass(StudentsFolder) |
---|
| 143 | |
---|
| 144 | def addStudentsFolder(container, id, REQUEST=None, **kw): |
---|
| 145 | """Add a Student.""" |
---|
| 146 | ob = StudentsFolder(id, **kw) |
---|
| 147 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 148 | ###) |
---|
| 149 | |
---|
[57] | 150 | class Student(CPSDocument): ###( |
---|
| 151 | """ |
---|
[154] | 152 | WAeUP Student container for the various student data |
---|
[57] | 153 | """ |
---|
| 154 | meta_type = 'Student' |
---|
| 155 | portal_type = meta_type |
---|
| 156 | security = ClassSecurityInfo() |
---|
[154] | 157 | |
---|
[152] | 158 | security.declareProtected(View,"Title") |
---|
| 159 | def Title(self): |
---|
| 160 | """compose title""" |
---|
[153] | 161 | reg_nr = self.getId()[1:] |
---|
[362] | 162 | data = getattr(self,'personal',None) |
---|
[152] | 163 | if data is None: |
---|
[362] | 164 | data = getattr(self,'jamb',None) |
---|
[152] | 165 | if data: |
---|
| 166 | content = data.getContent() |
---|
| 167 | return "%s %s" % (content.firstname,content.lastname) |
---|
| 168 | return self.title |
---|
[154] | 169 | |
---|
| 170 | def Description(self): |
---|
| 171 | """compose description""" |
---|
[170] | 172 | data = getattr(self,'PERSONAL',None) |
---|
| 173 | if data is None: |
---|
[191] | 174 | return "none" |
---|
[154] | 175 | if data: |
---|
[191] | 176 | content = data.getContent() |
---|
| 177 | return "%s" % (content.description) |
---|
[154] | 178 | return self.description |
---|
| 179 | |
---|
[164] | 180 | security.declareProtected(View,"setScratchCardData") |
---|
| 181 | def setScratchCardData(self,ident,ds): |
---|
| 182 | """set this data """ |
---|
| 183 | dict = {'%s_sc_pin' % ident : ds.get('sc_pin'), |
---|
| 184 | '%s_sc_id' % ident : ds.get('sc_id'), |
---|
| 185 | '%s_sc_value' % ident : ds.get('sc_value'), |
---|
[166] | 186 | '%s_date' % ident : ds.get('sc_date'), |
---|
[164] | 187 | } |
---|
[170] | 188 | |
---|
[173] | 189 | old_user = self.portal_membership.getAuthenticatedMember() |
---|
[166] | 190 | if self.portal_membership.isAnonymousUser(): |
---|
| 191 | tmp_user = CPSUnrestrictedUser('s%(jamb_id)s' % ds, '', |
---|
[164] | 192 | ['StudentManager'], '') |
---|
[166] | 193 | tmp_user = tmp_user.__of__(self.acl_users) |
---|
| 194 | newSecurityManager(None, tmp_user) |
---|
| 195 | #print str(dict) |
---|
[164] | 196 | self.edit(mapping=dict) |
---|
[173] | 197 | newSecurityManager(None, old_user) |
---|
[164] | 198 | |
---|
| 199 | security.declareProtected(View,"memberIsOwner") |
---|
| 200 | def memberIsOwner(self): |
---|
| 201 | """is the current user the owner""" |
---|
| 202 | member = self.portal_membership.getAuthenticatedMember() |
---|
| 203 | #print member, self.getId(),self.aq_parent.getId() |
---|
| 204 | if self.aq_parent.getId() == str(member): |
---|
| 205 | return True |
---|
| 206 | return False |
---|
| 207 | |
---|
[166] | 208 | security.declareProtected(View,"accommodationIsBooked") |
---|
| 209 | def accommodationIsBooked(self): |
---|
| 210 | """is the accommodation booked""" |
---|
| 211 | if self.accommodation_sc_pin != '': |
---|
| 212 | return True |
---|
| 213 | return False |
---|
| 214 | |
---|
| 215 | security.declareProtected(View,"accommodationIsPayed") |
---|
| 216 | def accommodationIsPayed(self): |
---|
| 217 | """is the accommodation payed""" |
---|
[168] | 218 | if self.hostel_fee_sc_pin != '': |
---|
[166] | 219 | return True |
---|
| 220 | return False |
---|
| 221 | |
---|
| 222 | security.declareProtected(View,"isRegisteredForCurrentLevel") |
---|
| 223 | def isRegisteredForCurrentLevel(self): |
---|
| 224 | """is the student registered for the current level""" |
---|
| 225 | for l in self.aq_parent.objectValues(): |
---|
| 226 | if l.portal_type == 'StudyLevel': |
---|
| 227 | return True |
---|
| 228 | return False |
---|
| 229 | |
---|
[57] | 230 | InitializeClass(Student) |
---|
| 231 | |
---|
| 232 | def addStudent(container, id, REQUEST=None, **kw): |
---|
| 233 | """Add a Student.""" |
---|
| 234 | ob = Student(id, **kw) |
---|
| 235 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 236 | |
---|
| 237 | ###) |
---|
[91] | 238 | |
---|
[89] | 239 | class StudentPersonal(CPSDocument): ###( |
---|
| 240 | """ |
---|
[154] | 241 | WAeUP Student container for the various student data |
---|
[89] | 242 | """ |
---|
| 243 | meta_type = 'StudentPersonal' |
---|
| 244 | portal_type = meta_type |
---|
| 245 | security = ClassSecurityInfo() |
---|
[152] | 246 | |
---|
| 247 | security.declareProtected(View,"Title") |
---|
| 248 | def Title(self): |
---|
| 249 | """compose title""" |
---|
| 250 | content = self.getContent() |
---|
[364] | 251 | #return "Personal Data for %s %s" % (content.firstname,content.lastname) |
---|
| 252 | return "Personal Data" |
---|
[152] | 253 | |
---|
[154] | 254 | |
---|
[89] | 255 | InitializeClass(StudentPersonal) |
---|
| 256 | |
---|
| 257 | def addStudentPersonal(container, id, REQUEST=None, **kw): |
---|
| 258 | """Add a Students personal data.""" |
---|
| 259 | ob = StudentPersonal(id, **kw) |
---|
| 260 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 261 | |
---|
| 262 | ###) |
---|
| 263 | |
---|
[362] | 264 | class StudentStudyCourse(CPSDocument): ###( |
---|
| 265 | """ |
---|
| 266 | WAeUP Student container for the various student data |
---|
| 267 | """ |
---|
| 268 | meta_type = 'StudentStudyCourse' |
---|
| 269 | portal_type = meta_type |
---|
| 270 | security = ClassSecurityInfo() |
---|
| 271 | |
---|
[364] | 272 | security.declareProtected(View,"Title") |
---|
| 273 | def Title(self): |
---|
| 274 | """compose title""" |
---|
| 275 | content = self.getContent() |
---|
[382] | 276 | return "Course Major" |
---|
[362] | 277 | |
---|
| 278 | |
---|
| 279 | InitializeClass(StudentStudyCourse) |
---|
| 280 | |
---|
| 281 | def addStudentStudyCourse(container, id, REQUEST=None, **kw): |
---|
| 282 | """Add a Students personal data.""" |
---|
| 283 | ob = StudentStudyCourse(id, **kw) |
---|
| 284 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 285 | |
---|
| 286 | ###) |
---|
| 287 | |
---|
[179] | 288 | class StudentEligibility(CPSDocument): ###( |
---|
| 289 | """ |
---|
| 290 | WAeUP Student container for the various student data |
---|
| 291 | """ |
---|
| 292 | meta_type = 'StudentEligibility' |
---|
| 293 | portal_type = meta_type |
---|
| 294 | security = ClassSecurityInfo() |
---|
| 295 | |
---|
[181] | 296 | security.declareProtected(View,"Title") |
---|
| 297 | def Title(self): |
---|
| 298 | """compose title""" |
---|
| 299 | return "Eligibility Data" |
---|
[179] | 300 | |
---|
[181] | 301 | |
---|
[179] | 302 | InitializeClass(StudentEligibility) |
---|
| 303 | |
---|
| 304 | def addStudentEligibility(container, id, REQUEST=None, **kw): |
---|
| 305 | """Add a Students eligibility data.""" |
---|
| 306 | ob = StudentEligibility(id, **kw) |
---|
| 307 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 308 | |
---|
| 309 | ###) |
---|
[181] | 310 | |
---|
[166] | 311 | class StudentDocuments(CPSDocument): ###( |
---|
| 312 | """ |
---|
| 313 | WAeUP Student container for the various student data |
---|
| 314 | """ |
---|
| 315 | meta_type = 'StudentDocuments' |
---|
| 316 | portal_type = meta_type |
---|
| 317 | security = ClassSecurityInfo() |
---|
| 318 | |
---|
| 319 | security.declareProtected(View,"Title") |
---|
| 320 | def Title(self): |
---|
| 321 | """compose title""" |
---|
| 322 | content = self.getContent() |
---|
| 323 | return "Scanned Documents" |
---|
| 324 | |
---|
| 325 | |
---|
| 326 | InitializeClass(StudentDocuments) |
---|
| 327 | |
---|
| 328 | def addStudentDocuments(container, id, REQUEST=None, **kw): |
---|
| 329 | """Add a Students documents""" |
---|
| 330 | ob = StudentDocuments(id, **kw) |
---|
| 331 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 332 | |
---|
| 333 | ###) |
---|
| 334 | |
---|
[89] | 335 | class Jamb(CPSDocument): ###( |
---|
| 336 | """ |
---|
| 337 | WAeUP Jamb containing the courses and students |
---|
| 338 | """ |
---|
| 339 | meta_type = 'Jamb' |
---|
| 340 | portal_type = meta_type |
---|
| 341 | security = ClassSecurityInfo() |
---|
[154] | 342 | |
---|
[152] | 343 | security.declareProtected(View,"Title") |
---|
| 344 | def Title(self): |
---|
| 345 | """compose title""" |
---|
| 346 | content = self.getContent() |
---|
| 347 | return "JAMB Data for %s %s" % (content.firstname,content.lastname) |
---|
| 348 | |
---|
| 349 | security.declareProtected(View,"setOwnership") |
---|
| 350 | def setOwnership(self,member_id): |
---|
| 351 | """set ownership""" |
---|
| 352 | pm = getattr(self,'portal_membership') |
---|
| 353 | member = pm.getMemberById(member_id) |
---|
| 354 | self.changeOwnership(member) |
---|
| 355 | |
---|
[89] | 356 | InitializeClass(Jamb) |
---|
| 357 | |
---|
| 358 | def addJamb(container, id, REQUEST=None, **kw): |
---|
| 359 | """Add a Jamb.""" |
---|
| 360 | ob = Jamb(id, **kw) |
---|
| 361 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 362 | |
---|
[139] | 363 | ###) |
---|
| 364 | |
---|
| 365 | class StudyLevel(CPSDocument): ###( |
---|
| 366 | """ |
---|
| 367 | WAeUP StudyLevel containing the courses and students |
---|
| 368 | """ |
---|
| 369 | meta_type = 'StudyLevel' |
---|
| 370 | portal_type = meta_type |
---|
| 371 | security = ClassSecurityInfo() |
---|
[154] | 372 | |
---|
[139] | 373 | InitializeClass(StudyLevel) |
---|
| 374 | |
---|
| 375 | def addStudyLevel(container, id, REQUEST=None, **kw): |
---|
| 376 | """Add a StudyLevel.""" |
---|
| 377 | ob = StudyLevel(id, **kw) |
---|
| 378 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 379 | |
---|
| 380 | ###) |
---|
| 381 | |
---|
| 382 | class Semester(CPSDocument): ###( |
---|
| 383 | """ |
---|
| 384 | WAeUP Semester containing the courses and students |
---|
| 385 | """ |
---|
| 386 | meta_type = 'Semester' |
---|
| 387 | portal_type = meta_type |
---|
| 388 | security = ClassSecurityInfo() |
---|
[154] | 389 | |
---|
[139] | 390 | InitializeClass(Semester) |
---|
| 391 | |
---|
| 392 | def addSemester(container, id, REQUEST=None, **kw): |
---|
| 393 | """Add a Semester.""" |
---|
| 394 | ob = Semester(id, **kw) |
---|
| 395 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
[200] | 396 | |
---|
[139] | 397 | ###) |
---|
| 398 | |
---|