[197] | 1 | #-*- mode: python; mode: fold -*- |
---|
| 2 | # (C) Copyright 2005 The WAeUP group <http://www.waeup.org> |
---|
| 3 | # Author: Joachim Schmitz (js@aixtraware.de) |
---|
| 4 | # |
---|
| 5 | # This program is free software; you can redistribute it and/or modify |
---|
| 6 | # it under the terms of the GNU General Public License version 2 as published |
---|
| 7 | # by the Free Software Foundation. |
---|
| 8 | # |
---|
| 9 | # This program is distributed in the hope that it will be useful, |
---|
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 12 | # GNU General Public License for more details. |
---|
| 13 | # |
---|
| 14 | # You should have received a copy of the GNU General Public License |
---|
| 15 | # along with this program; if not, write to the Free Software |
---|
| 16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
---|
| 17 | # 02111-1307, USA. |
---|
| 18 | # |
---|
| 19 | # $Id: WAeUPTool.py 1250 2007-01-09 17:19:20Z joachim $ |
---|
[1174] | 20 | """The WAeUP Tool Box. |
---|
[197] | 21 | """ |
---|
| 22 | |
---|
| 23 | from AccessControl import ClassSecurityInfo |
---|
[828] | 24 | from Acquisition import aq_inner |
---|
| 25 | from Acquisition import aq_parent |
---|
| 26 | from Globals import DTMLFile |
---|
| 27 | from Globals import InitializeClass |
---|
| 28 | from OFS.SimpleItem import SimpleItem |
---|
[197] | 29 | |
---|
[828] | 30 | from Products.CMFCore.ActionProviderBase import ActionProviderBase |
---|
| 31 | from Products.CMFCore.permissions import View |
---|
| 32 | from Products.ZCatalog.ZCatalog import ZCatalog |
---|
| 33 | from Products.CMFCore.permissions import ModifyPortalContent |
---|
[197] | 34 | from Products.CMFCore.utils import UniqueObject |
---|
[1194] | 35 | from Products.CMFCore.URLTool import URLTool |
---|
[1151] | 36 | from Students import makeCertificateCode |
---|
| 37 | import logging |
---|
[1170] | 38 | import transaction |
---|
[197] | 39 | |
---|
[1151] | 40 | |
---|
[1171] | 41 | |
---|
| 42 | |
---|
[828] | 43 | class WAeUPTool(UniqueObject, SimpleItem, ActionProviderBase): |
---|
[197] | 44 | """WAeUP tool""" |
---|
| 45 | |
---|
[828] | 46 | id = 'waeup_tool' |
---|
[197] | 47 | meta_type = 'WAeUP Tool' |
---|
[828] | 48 | _actions = () |
---|
[197] | 49 | |
---|
| 50 | security = ClassSecurityInfo() |
---|
[828] | 51 | security.declareObjectProtected(View) |
---|
[197] | 52 | |
---|
[828] | 53 | manage_options = ( ActionProviderBase.manage_options |
---|
| 54 | + SimpleItem.manage_options |
---|
| 55 | ) |
---|
| 56 | |
---|
[1174] | 57 | |
---|
[1151] | 58 | def generateStudentId(self,letter): ###( |
---|
| 59 | import random |
---|
| 60 | r = random |
---|
[1194] | 61 | ##if letter not in ('ABCDEFGIHKLMNOPQRSTUVWXY'): |
---|
| 62 | if letter == '?': |
---|
[1151] | 63 | letter= r.choice('ABCDEFGHKLMNPQRSTUVWXY') |
---|
| 64 | sid = "%c%d" % (letter,r.randint(99999,1000000)) |
---|
[1194] | 65 | ## students = self.portal_url.getPortalObject().campus.students |
---|
| 66 | ## while hasattr(students, sid): |
---|
| 67 | ## sid = "%c%d" % (letter,r.randint(99999,1000000)) |
---|
| 68 | while self.students_catalog(id = sid): |
---|
[1151] | 69 | sid = "%c%d" % (letter,r.randint(99999,1000000)) |
---|
| 70 | return sid |
---|
| 71 | ###) |
---|
[828] | 72 | |
---|
[1250] | 73 | security.declareProtected(ModifyPortalContent,'getCredential') |
---|
| 74 | def getCredential(self,student_id): |
---|
| 75 | "return a student password" |
---|
| 76 | student_entry = getattr(self.portal_directories.students,student_id,None) |
---|
| 77 | if student_entry is None: |
---|
| 78 | return None |
---|
| 79 | else: |
---|
| 80 | return student_entry.password |
---|
| 81 | |
---|
[1170] | 82 | security.declareProtected(ModifyPortalContent,'createOne') ###( |
---|
[1194] | 83 | def createOne(self,students_folder,student_brain,letter,commit=False): |
---|
| 84 | sid = self.waeup_tool.generateStudentId(letter) |
---|
[1170] | 85 | students_folder.invokeFactory('Student', sid) |
---|
| 86 | student = getattr(students_folder,sid) |
---|
| 87 | self.portal_workflow.doActionFor(student,'return') |
---|
| 88 | student.manage_setLocalRoles(sid, ['Owner',]) |
---|
| 89 | matric_no = student_brain.matric_no |
---|
| 90 | jamb_reg_no = student_brain.Entryregno |
---|
| 91 | self.students_catalog.addRecord(id = sid, |
---|
| 92 | matric_no = matric_no, |
---|
| 93 | jamb_reg_no = jamb_reg_no, |
---|
| 94 | sex = student_brain.Sex == "F", |
---|
| 95 | name = "%s %s %s" % (student_brain.Firstname, |
---|
| 96 | student_brain.Middlename, |
---|
| 97 | student_brain.Lastname) |
---|
| 98 | ) |
---|
| 99 | if commit: |
---|
| 100 | transaction.commit() |
---|
| 101 | return sid,jamb_reg_no |
---|
| 102 | ###) |
---|
| 103 | |
---|
[1151] | 104 | security.declarePublic('getCertificateBrain') ###( |
---|
| 105 | def getCertificateBrain(self,cert_id): |
---|
| 106 | "do it" |
---|
| 107 | res = ZCatalog.searchResults(self.portal_catalog, |
---|
| 108 | {'portal_type':"Certificate", |
---|
| 109 | 'id': cert_id}) |
---|
| 110 | if res: |
---|
| 111 | return res[0] |
---|
| 112 | return None |
---|
| 113 | ###) |
---|
[1160] | 114 | |
---|
[1151] | 115 | security.declarePublic('findStudentByMatricelNo') ###( |
---|
| 116 | def findStudentByMatricelNo(self,matric_no): |
---|
| 117 | "do it" |
---|
| 118 | res = ZCatalog.searchResults(self.portal_catalog, |
---|
| 119 | {'portal_type':"StudentClearance", |
---|
| 120 | 'SearchableText': matric_no}) |
---|
| 121 | if res: |
---|
| 122 | return res[0] |
---|
| 123 | return None |
---|
| 124 | ###) |
---|
| 125 | |
---|
| 126 | security.declarePublic('makeStudentMember') ###( |
---|
| 127 | def makeStudentMember(self,sid,password='uNsEt'): |
---|
| 128 | """make the student a member""" |
---|
| 129 | membership = self.portal_membership |
---|
| 130 | membership.addMember(sid, |
---|
| 131 | password , |
---|
| 132 | roles=('Member', |
---|
| 133 | 'Student', |
---|
| 134 | ), |
---|
| 135 | domains='', |
---|
| 136 | properties = {'memberareaCreationFlag': False, |
---|
| 137 | 'homeless': True},) |
---|
| 138 | member = membership.getMemberById(sid) |
---|
| 139 | self.portal_registration.afterAdd(member, sid, password, None) |
---|
| 140 | self.manage_setLocalRoles(sid, ['Owner',]) |
---|
| 141 | ###) |
---|
[1160] | 142 | |
---|
[1151] | 143 | security.declarePublic('makeStudentData') ###( |
---|
[1158] | 144 | def makeStudentData(self,student_id,email=None,phone_nr=None): |
---|
[1151] | 145 | "create Datastructure for a returning Student" |
---|
| 146 | #import pdb;pdb.set_trace() |
---|
| 147 | logger = logging.getLogger('Student.CreateData') |
---|
| 148 | students_folder = self.portal_url.getPortalObject().campus.students |
---|
| 149 | res = self.students_catalog(id=student_id) |
---|
| 150 | if res: |
---|
| 151 | st = res[0] |
---|
| 152 | res = self.returning_import(matric_no = st.matric_no) |
---|
| 153 | if res: |
---|
[1160] | 154 | student = res[0] |
---|
[1158] | 155 | logger.info('"%s", "creating Datastructure"' % student_id) |
---|
[1171] | 156 | |
---|
| 157 | #student should not be allowed to perform this transition |
---|
[1174] | 158 | #wftool = self.portal_workflow |
---|
| 159 | #wftool.doActionFor(student,'return') |
---|
[1171] | 160 | |
---|
[1151] | 161 | certcode_org = student.Coursemajorcode |
---|
| 162 | certcode = makeCertificateCode(certcode_org) |
---|
| 163 | certificate_brain = self.getCertificateBrain(certcode) |
---|
| 164 | if not certificate_brain: |
---|
| 165 | em = 'Certificate %s org-code %s not found\n' % (certcode, certcode_org) |
---|
| 166 | logger.info(em) |
---|
| 167 | level = student.Level |
---|
[1250] | 168 | validlevel = False |
---|
[1151] | 169 | try: |
---|
| 170 | int(level) |
---|
[1250] | 171 | validlevel = True |
---|
[1151] | 172 | except: |
---|
| 173 | em = '"%(matric_no)s","invalid Level","%(Level)s"' % student |
---|
| 174 | logger.info(em) |
---|
[1250] | 175 | if not validlevel: |
---|
| 176 | erg = self.results_import(matric_no = student.matric_no) |
---|
| 177 | level = 'xxx' |
---|
| 178 | if erg: |
---|
| 179 | level = erg[0].Level |
---|
| 180 | try: |
---|
| 181 | int(level) |
---|
| 182 | em = '"%s","fixed Level from results_import","%s"' % (student.matric_no,erg[0].Level) |
---|
| 183 | logger.info(em) |
---|
| 184 | validlevel = True |
---|
| 185 | except: |
---|
| 186 | em = '"%s","invalid Level in results_import","%s"' % (student.matric_no,erg[0].Level) |
---|
| 187 | logger.info(em) |
---|
[1151] | 188 | matric_no = student.matric_no |
---|
| 189 | sid = student_id |
---|
| 190 | student_obj = getattr(students_folder,sid) |
---|
| 191 | student_obj.invokeFactory('StudentApplication','application') |
---|
| 192 | application = student_obj.application |
---|
[1169] | 193 | self.portal_workflow.doActionFor(application,'open',dest_container=application) |
---|
[1151] | 194 | da = {'Title': 'Application Data'} |
---|
| 195 | student_obj.invokeFactory('StudentPersonal','personal') |
---|
| 196 | da['jamb_reg_no'] = student.Entryregno |
---|
| 197 | da['entry_mode'] = student.Mode_of_Entry |
---|
| 198 | personal = student_obj.personal |
---|
| 199 | self.portal_workflow.doActionFor(personal,'open',dest_container=personal) |
---|
| 200 | dp = {'Title': 'Personal Data'} |
---|
| 201 | student_obj.invokeFactory('StudentClearance','clearance') |
---|
| 202 | clearance = student_obj.clearance |
---|
[1169] | 203 | self.portal_workflow.doActionFor(clearance,'open',dest_container=clearance) |
---|
[1151] | 204 | dc = {'Title': 'Clearance/Eligibility Record'} |
---|
| 205 | dc['matric_no'] = matric_no |
---|
| 206 | state = student.State |
---|
| 207 | lga = student.LGA |
---|
| 208 | if state and lga: |
---|
| 209 | lga = state + ' / ' + lga |
---|
| 210 | else: |
---|
| 211 | lga = "None" |
---|
[1174] | 212 | da['jamb_lga'] = dc['lga'] = lga |
---|
[1173] | 213 | da['app_email'] = dp['email'] = email |
---|
| 214 | da['app_mobile'] = dp['phone'] = phone_nr |
---|
[1174] | 215 | da['jamb_firstname'] = dp['firstname'] = student.Firstname |
---|
| 216 | da['jamb_middlename'] = dp['middlename'] = student.Middlename |
---|
| 217 | da['jamb_lastname'] = dp['lastname'] = student.Lastname |
---|
| 218 | da['jamb_sex'] = student.Sex |
---|
[1151] | 219 | dp['sex'] = student.Sex == 'F' |
---|
| 220 | dp['perm_address'] = student.Permanent_Address |
---|
| 221 | application.getContent().edit(mapping=da) |
---|
[1169] | 222 | self.portal_workflow.doActionFor(application,'close',dest_container=application) |
---|
[1151] | 223 | personal.getContent().edit(mapping=dp) |
---|
| 224 | clearance.getContent().edit(mapping=dc) |
---|
[1169] | 225 | self.portal_workflow.doActionFor(clearance,'close',dest_container=clearance) |
---|
[1158] | 226 | catd = {} |
---|
| 227 | catd['id'] = sid |
---|
| 228 | catd['entry_mode']= da['entry_mode'] |
---|
| 229 | catd['matric_no'] = matric_no |
---|
[1171] | 230 | catd['jamb_reg_no'] = da['jamb_reg_no'] |
---|
| 231 | catd['name'] = "%(firstname)s %(middlename)s %(lastname)s" % dp |
---|
| 232 | catd['sex'] = dp['sex'] |
---|
| 233 | catd['level'] = level |
---|
[1158] | 234 | if certificate_brain: |
---|
| 235 | cpath = certificate_brain.getPath().split('/') |
---|
[1171] | 236 | catd['faculty'] = cpath[-4] |
---|
| 237 | catd['department'] = cpath[-3] |
---|
[1158] | 238 | catd['course'] = certcode |
---|
| 239 | self.students_catalog.modifyRecord(**catd) |
---|
[1151] | 240 | # |
---|
| 241 | # Study Course |
---|
| 242 | # |
---|
| 243 | student_obj.invokeFactory('StudentStudyCourse','study_course') |
---|
| 244 | studycourse = student_obj.study_course |
---|
| 245 | self.portal_workflow.doActionFor(studycourse,'open',dest_container=studycourse) |
---|
| 246 | dsc = {} |
---|
| 247 | dsc['study_course'] = certcode |
---|
| 248 | studycourse.getContent().edit(mapping=dsc) |
---|
| 249 | # |
---|
| 250 | # Level |
---|
| 251 | # |
---|
[1198] | 252 | ## l = getattr(studycourse,level,None) |
---|
| 253 | ## if l is None: |
---|
| 254 | ## studycourse.invokeFactory('StudentStudyLevel', level) |
---|
| 255 | ## l = getattr(studycourse, level) |
---|
| 256 | ## self.portal_workflow.doActionFor(l,'open',dest_container=l) |
---|
| 257 | ## l.getContent().edit(mapping={'Title': "Level %s" % level}) |
---|
[1194] | 258 | ###) |
---|
[1160] | 259 | |
---|
[1194] | 260 | security.declarePublic('makeStudentLevel') ###( |
---|
| 261 | def makeStudentLevel(self,student_id): |
---|
| 262 | "create the StudyLevel for a returning Student" |
---|
| 263 | #import pdb;pdb.set_trace() |
---|
| 264 | logger = logging.getLogger('Student.CreateLevel') |
---|
| 265 | students_folder = self.portal_url.getPortalObject().campus.students |
---|
| 266 | res = self.students_catalog(id=student_id) |
---|
| 267 | if res: |
---|
| 268 | st = res[0] |
---|
| 269 | course = st.course |
---|
| 270 | matric_no = st.matric_no |
---|
| 271 | level = st.level |
---|
| 272 | res = self.results_import(matric_no = matric_no) |
---|
| 273 | if res: |
---|
| 274 | results = res |
---|
| 275 | logger.info('"%s", "creating Level", "%s"' % (student_id,level)) |
---|
| 276 | # |
---|
| 277 | # Level |
---|
| 278 | # |
---|
| 279 | student_obj = getattr(self.portal_url.getPortalObject().campus.students,student_id) |
---|
| 280 | studycourse = getattr(student_obj,"study_course",None) |
---|
| 281 | self.portal_workflow.doActionFor(studycourse,'close_for_edit',dest_container=studycourse) |
---|
| 282 | l = getattr(studycourse,level,None) |
---|
| 283 | if l is None: |
---|
| 284 | studycourse.invokeFactory('StudentStudyLevel', level) |
---|
| 285 | l = getattr(studycourse, level) |
---|
| 286 | self.portal_workflow.doActionFor(l,'open',dest_container=l) |
---|
| 287 | l.getContent().edit(mapping={'Title': "Level %s" % level}) |
---|
| 288 | ###) |
---|
| 289 | |
---|
[1151] | 290 | security.declarePublic('getAccommodationInfo') ###( |
---|
[828] | 291 | def getAccommodationInfo(self,bed): |
---|
| 292 | """return Accommodation Info""" |
---|
| 293 | info = {} |
---|
| 294 | hall,block,room,letter = bed.split('_') |
---|
| 295 | res = ZCatalog.searchResults(self.portal_catalog,portal_type="AccoHall",id=hall) |
---|
| 296 | if res and len(res) == 1: |
---|
| 297 | hall_brain = res[0] |
---|
| 298 | hall_doc = hall_brain.getObject().getContent() |
---|
| 299 | else: |
---|
| 300 | return info |
---|
| 301 | info['hall_title'] = hall_brain.Title |
---|
| 302 | info['maintenance_code'] = hall_doc.maintenance_code |
---|
| 303 | res = ZCatalog.searchResults(self.portal_catalog,portal_type="ScratchCardBatch") |
---|
| 304 | batch_doc = None |
---|
| 305 | for brain in res: |
---|
| 306 | if brain.id.startswith(info['maintenance_code']): |
---|
| 307 | batch_doc = brain.getObject().getContent() |
---|
| 308 | break |
---|
| 309 | if batch_doc is None: |
---|
| 310 | info['maintenance_fee'] = None |
---|
| 311 | else: |
---|
| 312 | info['maintenance_fee'] = batch_doc.cost |
---|
| 313 | return info |
---|
[1151] | 314 | ###) |
---|
[828] | 315 | |
---|
[1151] | 316 | security.declareProtected(ModifyPortalContent,'deleteAllCourses') ###( |
---|
| 317 | def deleteAllCourses(self,department="All"): |
---|
| 318 | ''' delete the courses''' |
---|
| 319 | pm = self.portal_membership |
---|
| 320 | member = pm.getAuthenticatedMember() |
---|
[1160] | 321 | |
---|
[1151] | 322 | if str(member) not in ("henrik","joachim"): |
---|
| 323 | return "not possible" |
---|
| 324 | if department == "All": |
---|
| 325 | res = self.portal_catalog({'meta_type': 'Department'}) |
---|
| 326 | if len(res) < 1: |
---|
| 327 | return "No Departments found" |
---|
[1160] | 328 | |
---|
[1151] | 329 | deleted = [] |
---|
| 330 | for dep in res: |
---|
| 331 | cf = dep.getObject().courses |
---|
| 332 | if cf: |
---|
| 333 | cf.manage_delObjects(ids=cf.objectIds()) |
---|
| 334 | deleted.append("deleted Courses in %s" % dep.getId) |
---|
| 335 | return "\r".join(deleted) |
---|
[1160] | 336 | ###) |
---|
[1151] | 337 | |
---|
[1160] | 338 | |
---|
[828] | 339 | InitializeClass(WAeUPTool) |
---|