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