[966] | 1 | #-*- mode: python; mode: fold -*- |
---|
[363] | 2 | # (C) Copyright 2005 AixtraWare <http://aixtraware.de> |
---|
| 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: WAeUPTables.py 2039 2007-07-20 08:58:54Z joachim $ |
---|
| 20 | |
---|
| 21 | from zope.interface import implements |
---|
| 22 | from Globals import InitializeClass |
---|
| 23 | from Products.ZCatalog.ZCatalog import ZCatalog |
---|
[1620] | 24 | from Products.ZCatalog.ProgressHandler import ZLogHandler |
---|
[780] | 25 | from AccessControl import ClassSecurityInfo |
---|
| 26 | from Products.CMFCore.permissions import ModifyPortalContent |
---|
[1700] | 27 | import urllib |
---|
[1620] | 28 | import DateTime,time |
---|
[780] | 29 | import csv,re |
---|
| 30 | import logging |
---|
| 31 | import Globals |
---|
| 32 | p_home = Globals.package_home(globals()) |
---|
| 33 | i_home = Globals.INSTANCE_HOME |
---|
[1845] | 34 | from Products.CMFCore.CatalogTool import CatalogTool |
---|
[1702] | 35 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
[780] | 36 | |
---|
[363] | 37 | from interfaces import IWAeUPTable |
---|
| 38 | |
---|
| 39 | class AttributeHolder(object): |
---|
| 40 | pass |
---|
| 41 | |
---|
| 42 | def dict2ob(dict): |
---|
| 43 | ob = AttributeHolder() |
---|
| 44 | for key, value in dict.items(): |
---|
| 45 | setattr(ob, key, value) |
---|
| 46 | return ob |
---|
| 47 | |
---|
[1146] | 48 | class WAeUPTable(ZCatalog): ###( |
---|
[834] | 49 | |
---|
[363] | 50 | implements(IWAeUPTable) |
---|
[780] | 51 | security = ClassSecurityInfo() |
---|
[834] | 52 | |
---|
[1620] | 53 | def refreshCatalog(self, clear=0, pghandler=None): |
---|
| 54 | """ don't refresh for a normal table """ |
---|
| 55 | |
---|
| 56 | if self.REQUEST and self.REQUEST.RESPONSE: |
---|
| 57 | self.REQUEST.RESPONSE.redirect( |
---|
| 58 | URL1 + |
---|
| 59 | '/manage_catalogAdvanced?manage_tabs_message=Catalog%20refresh%20not%20implemented') |
---|
| 60 | |
---|
| 61 | def manage_catalogClear(self, REQUEST=None, RESPONSE=None, URL1=None): |
---|
| 62 | """ clears the whole enchilada """ |
---|
[1986] | 63 | |
---|
[1916] | 64 | #if REQUEST and RESPONSE: |
---|
| 65 | # RESPONSE.redirect( |
---|
| 66 | # URL1 + |
---|
| 67 | # '/manage_catalogAdvanced?manage_tabs_message=Catalog%20Clearing%20disabled') |
---|
[1620] | 68 | |
---|
[1916] | 69 | |
---|
| 70 | self._catalog.clear() |
---|
[1620] | 71 | if REQUEST and RESPONSE: |
---|
| 72 | RESPONSE.redirect( |
---|
| 73 | URL1 + |
---|
[1916] | 74 | '/manage_catalogAdvanced?manage_tabs_message=Catalog%20cleared') |
---|
[1620] | 75 | |
---|
[363] | 76 | def addRecord(self, **data): |
---|
[502] | 77 | # The uid is the same as "bed". |
---|
| 78 | uid = data[self.key] |
---|
| 79 | res = self.searchResults({"%s" % self.key : uid}) |
---|
| 80 | if len(res) > 0: |
---|
| 81 | raise ValueError("More than one record with uid %s" % uid) |
---|
| 82 | self.catalog_object(dict2ob(data), uid=uid) |
---|
| 83 | return uid |
---|
[834] | 84 | |
---|
[363] | 85 | def deleteRecord(self, uid): |
---|
| 86 | self.uncatalog_object(uid) |
---|
[834] | 87 | |
---|
[502] | 88 | def searchAndSetRecord(self, **data): |
---|
| 89 | raise NotImplemented |
---|
| 90 | |
---|
| 91 | def modifyRecord(self, **data): |
---|
| 92 | #records = self.searchResults(uid=uid) |
---|
| 93 | uid = data[self.key] |
---|
| 94 | records = self.searchResults({"%s" % self.key : uid}) |
---|
[363] | 95 | if len(records) > 1: |
---|
| 96 | # Can not happen, but anyway... |
---|
| 97 | raise ValueError("More than one record with uid %s" % uid) |
---|
| 98 | if len(records) == 0: |
---|
| 99 | raise KeyError("No record for uid %s" % uid) |
---|
| 100 | record = records[0] |
---|
| 101 | record_data = {} |
---|
| 102 | for field in self.schema() + self.indexes(): |
---|
| 103 | record_data[field] = getattr(record, field) |
---|
| 104 | # Add the updated data: |
---|
| 105 | record_data.update(data) |
---|
| 106 | self.catalog_object(dict2ob(record_data), uid) |
---|
| 107 | |
---|
[1062] | 108 | def reindexIndex(self, name, REQUEST,pghandler=None): |
---|
| 109 | if isinstance(name, str): |
---|
| 110 | name = (name,) |
---|
| 111 | paths = self._catalog.uids.items() |
---|
| 112 | i = 0 |
---|
| 113 | #import pdb;pdb.set_trace() |
---|
| 114 | for p,rid in paths: |
---|
| 115 | i += 1 |
---|
| 116 | metadata = self.getMetadataForRID(rid) |
---|
| 117 | record_data = {} |
---|
| 118 | for field in name: |
---|
| 119 | record_data[field] = metadata.get(field) |
---|
| 120 | uid = metadata.get(self.key) |
---|
| 121 | self.catalog_object(dict2ob(record_data), uid, idxs=name, |
---|
| 122 | update_metadata=0) |
---|
[1082] | 123 | |
---|
[780] | 124 | security.declareProtected(ModifyPortalContent,"exportAllRecords") |
---|
| 125 | def exportAllRecords(self): |
---|
| 126 | "export a WAeUPTable" |
---|
| 127 | #import pdb;pdb.set_trace() |
---|
| 128 | fields = [field for field in self.schema()] |
---|
| 129 | format = ','.join(['"%%(%s)s"' % fn for fn in fields]) |
---|
| 130 | csv = [] |
---|
| 131 | csv.append(','.join(['"%s"' % fn for fn in fields])) |
---|
| 132 | for uid in self._catalog.uids: |
---|
| 133 | records = self.searchResults({"%s" % self.key : uid}) |
---|
| 134 | if len(records) > 1: |
---|
| 135 | # Can not happen, but anyway... |
---|
| 136 | raise ValueError("More than one record with uid %s" % uid) |
---|
| 137 | if len(records) == 0: |
---|
| 138 | raise KeyError("No record for uid %s" % uid) |
---|
| 139 | rec = records[0] |
---|
| 140 | csv.append(format % rec) |
---|
| 141 | current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") |
---|
| 142 | open("%s/import/%s-%s.csv" % (i_home,self.getId(),current),"w+").write('\n'.join(csv)) |
---|
[1935] | 143 | ###) |
---|
[834] | 144 | |
---|
[1146] | 145 | class AccommodationTable(WAeUPTable): ###( |
---|
[834] | 146 | |
---|
[404] | 147 | meta_type = 'WAeUP Accommodation Tool' |
---|
[502] | 148 | name = "accommodation" |
---|
| 149 | key = "bed" |
---|
[363] | 150 | def __init__(self): |
---|
[404] | 151 | WAeUPTable.__init__(self, 'portal_accommodation') |
---|
[363] | 152 | |
---|
[635] | 153 | def searchAndReserveBed(self, student_id,bed_type): |
---|
| 154 | records = self.searchResults({'student' : student_id}) |
---|
| 155 | if len(records) > 0: |
---|
[1293] | 156 | return -1,"Student with Id %s already booked bed %s." % (student_id,records[0].bed) |
---|
[834] | 157 | |
---|
[673] | 158 | records = [r for r in self.searchResults({'bed_type' : bed_type}) if not r.student] |
---|
[686] | 159 | #import pdb;pdb.set_trace() |
---|
[635] | 160 | if len(records) == 0: |
---|
[1306] | 161 | return -2,"No bed available" |
---|
[635] | 162 | rec = records[0] |
---|
| 163 | self.modifyRecord(bed=rec.bed,student=student_id) |
---|
[1571] | 164 | s_logger = logging.getLogger('WAeUPTables.AccommodationTable.searchAndReserveBed') |
---|
| 165 | s_logger.info('%s reserved bed %s' % (student_id,rec.bed)) |
---|
[635] | 166 | return 1,rec.bed |
---|
[363] | 167 | |
---|
[834] | 168 | |
---|
[404] | 169 | InitializeClass(AccommodationTable) |
---|
[411] | 170 | |
---|
[1146] | 171 | ###) |
---|
| 172 | |
---|
| 173 | class PinTable(WAeUPTable): ###( |
---|
[1030] | 174 | from ZODB.POSException import ConflictError |
---|
[440] | 175 | meta_type = 'WAeUP Pin Tool' |
---|
[502] | 176 | name = "pins" |
---|
| 177 | key = 'pin' |
---|
[440] | 178 | def __init__(self): |
---|
| 179 | WAeUPTable.__init__(self, 'portal_pins') |
---|
[1082] | 180 | |
---|
| 181 | |
---|
[710] | 182 | def searchAndSetRecord(self, uid, student_id,prefix): |
---|
[502] | 183 | #records = self.searchResults(uid=uid) |
---|
[710] | 184 | records = self.searchResults(student = student_id) |
---|
[990] | 185 | #import pdb;pdb.set_trace() |
---|
[1776] | 186 | if len(records) > 0 and prefix in ('CLR','APP'): |
---|
[710] | 187 | for r in records: |
---|
[834] | 188 | if r.pin != uid and r.prefix_batch.startswith(prefix): |
---|
[710] | 189 | return -2 |
---|
[502] | 190 | records = self.searchResults({"%s" % self.key : uid}) |
---|
| 191 | if len(records) > 1: |
---|
| 192 | # Can not happen, but anyway... |
---|
| 193 | raise ValueError("More than one record with uid %s" % uid) |
---|
| 194 | if len(records) == 0: |
---|
| 195 | return -1 |
---|
| 196 | record = records[0] |
---|
| 197 | if record.student == "": |
---|
| 198 | record_data = {} |
---|
| 199 | for field in self.schema() + self.indexes(): |
---|
| 200 | record_data[field] = getattr(record, field) |
---|
| 201 | # Add the updated data: |
---|
[635] | 202 | record_data['student'] = student_id |
---|
[1030] | 203 | try: |
---|
| 204 | self.catalog_object(dict2ob(record_data), uid) |
---|
| 205 | return 1 |
---|
| 206 | except ConflictError: |
---|
| 207 | return 2 |
---|
[990] | 208 | if record.student.upper() != student_id.upper(): |
---|
[502] | 209 | return 0 |
---|
[997] | 210 | if record.student.upper() == student_id.upper(): |
---|
[502] | 211 | return 2 |
---|
[997] | 212 | return -3 |
---|
[440] | 213 | |
---|
| 214 | InitializeClass(PinTable) |
---|
| 215 | |
---|
[1146] | 216 | ###) |
---|
[966] | 217 | |
---|
[1146] | 218 | class PumeResultsTable(WAeUPTable): ###( |
---|
| 219 | |
---|
[966] | 220 | meta_type = 'WAeUP PumeResults Tool' |
---|
| 221 | name = "pumeresults" |
---|
| 222 | key = "jamb_reg_no" |
---|
| 223 | def __init__(self): |
---|
| 224 | WAeUPTable.__init__(self, 'portal_pumeresults') |
---|
| 225 | |
---|
| 226 | |
---|
| 227 | InitializeClass(PumeResultsTable) |
---|
| 228 | |
---|
[1146] | 229 | ###) |
---|
[971] | 230 | |
---|
[1146] | 231 | class StudentsCatalog(WAeUPTable): ###( |
---|
[1620] | 232 | security = ClassSecurityInfo() |
---|
[1146] | 233 | |
---|
[971] | 234 | meta_type = 'WAeUP Students Catalog' |
---|
| 235 | name = "students_catalog" |
---|
| 236 | key = "id" |
---|
[1700] | 237 | affected_types = { ###( |
---|
[1749] | 238 | 'StudentApplication': |
---|
[1707] | 239 | {'id': 'application', |
---|
| 240 | 'fields': |
---|
[1700] | 241 | ('jamb_reg_no', |
---|
| 242 | 'entry_mode', |
---|
[1749] | 243 | #'entry_level', |
---|
[1700] | 244 | 'entry_session', |
---|
[1707] | 245 | ) |
---|
| 246 | }, |
---|
[1700] | 247 | 'StudentClearance': |
---|
[1707] | 248 | {'id': 'clearance', |
---|
| 249 | 'fields': |
---|
[1700] | 250 | ('matric_no', |
---|
[1707] | 251 | ) |
---|
| 252 | }, |
---|
[1700] | 253 | 'StudentPersonal': |
---|
[1707] | 254 | {'id': 'personal', |
---|
| 255 | 'fields': |
---|
[1700] | 256 | ('name', |
---|
| 257 | 'sex', |
---|
| 258 | 'email', |
---|
| 259 | 'phone', |
---|
[1707] | 260 | ) |
---|
| 261 | }, |
---|
[1700] | 262 | 'StudentStudyCourse': |
---|
[1707] | 263 | {'id': 'study_course', |
---|
| 264 | 'fields': |
---|
[1700] | 265 | ('course', |
---|
| 266 | 'faculty', |
---|
| 267 | 'department', |
---|
| 268 | 'level', |
---|
[1705] | 269 | 'mode', |
---|
[1700] | 270 | 'session', |
---|
| 271 | 'verdict', |
---|
[1707] | 272 | ) |
---|
| 273 | }, |
---|
[1700] | 274 | } |
---|
| 275 | ###) |
---|
[1625] | 276 | |
---|
[971] | 277 | def __init__(self): |
---|
| 278 | WAeUPTable.__init__(self, 'students_catalog') |
---|
[1620] | 279 | return |
---|
[1625] | 280 | |
---|
[1700] | 281 | def manage_catalogClear(self, REQUEST=None, RESPONSE=None, URL1=None): |
---|
| 282 | """ clears the whole enchilada """ |
---|
| 283 | self._catalog.clear() |
---|
[971] | 284 | |
---|
[1700] | 285 | if REQUEST and RESPONSE: |
---|
| 286 | RESPONSE.redirect( |
---|
| 287 | URL1 + |
---|
| 288 | '/manage_catalogAdvanced?manage_tabs_message=Catalog%20Cleared') |
---|
[971] | 289 | |
---|
[1700] | 290 | def manage_catalogReindex(self, REQUEST, RESPONSE, URL1): ###( |
---|
| 291 | """ clear the catalog, then re-index everything """ |
---|
| 292 | |
---|
| 293 | elapse = time.time() |
---|
| 294 | c_elapse = time.clock() |
---|
| 295 | |
---|
| 296 | pgthreshold = self._getProgressThreshold() |
---|
| 297 | handler = (pgthreshold > 0) and ZLogHandler(pgthreshold) or None |
---|
| 298 | self.refreshCatalog(clear=1, pghandler=handler) |
---|
| 299 | |
---|
| 300 | elapse = time.time() - elapse |
---|
| 301 | c_elapse = time.clock() - c_elapse |
---|
| 302 | |
---|
| 303 | RESPONSE.redirect( |
---|
| 304 | URL1 + |
---|
| 305 | '/manage_catalogAdvanced?manage_tabs_message=' + |
---|
| 306 | urllib.quote('Catalog Updated \n' |
---|
| 307 | 'Total time: %s\n' |
---|
| 308 | 'Total CPU time: %s' % (`elapse`, `c_elapse`))) |
---|
| 309 | ###) |
---|
| 310 | |
---|
| 311 | def get_from_doc_department(self,doc): ###( |
---|
[1620] | 312 | "return the students department" |
---|
[1700] | 313 | if doc is None: |
---|
[1620] | 314 | return None |
---|
[1700] | 315 | certificate_res = self.portal_catalog(id = doc.study_course) |
---|
[1620] | 316 | if len(certificate_res) != 1: |
---|
| 317 | return None |
---|
| 318 | return certificate_res[0].getPath().split('/')[-3] |
---|
| 319 | |
---|
[1700] | 320 | def get_from_doc_faculty(self,doc): |
---|
| 321 | "return the students faculty" |
---|
| 322 | if doc is None: |
---|
[1620] | 323 | return None |
---|
[1700] | 324 | certificate_res = self.portal_catalog(id = doc.study_course) |
---|
| 325 | if len(certificate_res) != 1: |
---|
| 326 | return None |
---|
| 327 | return certificate_res[0].getPath().split('/')[-4] |
---|
[1620] | 328 | |
---|
[1700] | 329 | def get_from_doc_level(self,doc): |
---|
| 330 | "return the students level" |
---|
| 331 | if doc is None: |
---|
[1620] | 332 | return None |
---|
[1700] | 333 | return getattr(doc,'current_level',None) |
---|
[1620] | 334 | |
---|
[1705] | 335 | def get_from_doc_mode(self,doc): |
---|
| 336 | "return the students mode" |
---|
[1700] | 337 | if doc is None: |
---|
[1620] | 338 | return None |
---|
[1705] | 339 | cm = getattr(doc,'current_mode',None) |
---|
| 340 | return cm |
---|
[1625] | 341 | |
---|
[1749] | 342 | |
---|
[1705] | 343 | def get_from_doc_session(self,doc): |
---|
| 344 | "return the students current_session" |
---|
| 345 | if doc is None: |
---|
| 346 | return None |
---|
| 347 | return getattr(doc,'current_session',None) |
---|
| 348 | |
---|
[1700] | 349 | def get_from_doc_entry_session(self,doc): |
---|
| 350 | "return the students entry_session" |
---|
| 351 | if doc is None: |
---|
[1620] | 352 | return None |
---|
[1705] | 353 | es = getattr(doc,'entry_session',None) |
---|
[1729] | 354 | if es is not None and len(es) == 2: |
---|
[1705] | 355 | return es |
---|
[1700] | 356 | try: |
---|
| 357 | digit = int(doc.jamb_reg_no[0]) |
---|
| 358 | except: |
---|
[1986] | 359 | return "-1" |
---|
[1700] | 360 | if digit < 8: |
---|
| 361 | return "0%c" % doc.jamb_reg_no[0] |
---|
| 362 | return "9%c" % doc.jamb_reg_no[0] |
---|
| 363 | |
---|
| 364 | def get_from_doc_course(self,doc): |
---|
[1620] | 365 | "return the students study_course" |
---|
[1700] | 366 | if doc is None: |
---|
[1620] | 367 | return None |
---|
[1700] | 368 | return getattr(doc,'study_course',None) |
---|
[1620] | 369 | |
---|
[1700] | 370 | def get_from_doc_name(self,doc): |
---|
[1620] | 371 | "return the students name from the personal" |
---|
[1700] | 372 | if doc is None: |
---|
[1620] | 373 | return None |
---|
| 374 | return "%s %s %s" % (doc.firstname,doc.middlename,doc.lastname) |
---|
| 375 | |
---|
[1700] | 376 | def get_from_doc_verdict(self,doc): |
---|
| 377 | "return the students study_course" |
---|
| 378 | if doc is None: |
---|
[1620] | 379 | return None |
---|
[1700] | 380 | return getattr(doc,'current_verdict',None) |
---|
[1702] | 381 | ###) |
---|
[1620] | 382 | |
---|
[1702] | 383 | def reindexIndex(self, name, REQUEST,pghandler=None): ###( |
---|
| 384 | if isinstance(name, str): |
---|
| 385 | name = (name,) |
---|
[1749] | 386 | reindextypes = {} |
---|
[1702] | 387 | reindex_special = [] |
---|
| 388 | for n in name: |
---|
| 389 | if n in ("review_state","registered_courses"): |
---|
| 390 | reindex_special.append(n) |
---|
| 391 | else: |
---|
| 392 | for pt in self.affected_types.keys(): |
---|
[1707] | 393 | if n in self.affected_types[pt]['fields']: |
---|
[1702] | 394 | if reindextypes.has_key(pt): |
---|
| 395 | reindextypes[pt].append(n) |
---|
| 396 | else: |
---|
| 397 | reindextypes[pt]= [n] |
---|
| 398 | break |
---|
| 399 | students = self.portal_catalog(portal_type="Student") |
---|
[1954] | 400 | if hasattr(self,'portal_catalog_real'): |
---|
| 401 | aq_portal = self.portal_catalog_real.evalAdvancedQuery |
---|
| 402 | else: |
---|
| 403 | aq_portal = self.portal_catalog.evalAdvancedQuery |
---|
[1702] | 404 | num_objects = len(students) |
---|
| 405 | if pghandler: |
---|
| 406 | pghandler.init('Refreshing catalog: %s' % self.absolute_url(1), num_objects) |
---|
| 407 | noattr = set(('StudentClearance','StudentPersonal')) & set(reindextypes.keys()) |
---|
| 408 | for i in xrange(num_objects): |
---|
| 409 | if pghandler: pghandler.report(i) |
---|
| 410 | student_brain = students[i] |
---|
[1707] | 411 | student_object = student_brain.getObject() |
---|
[1702] | 412 | data = {} |
---|
| 413 | modified = False |
---|
| 414 | sid = data['id'] = student_brain.getId |
---|
| 415 | if reindex_special and 'review_state' in reindex_special: |
---|
| 416 | modified = True |
---|
| 417 | data['review_state'] = student_brain.review_state |
---|
[1707] | 418 | sub_objects = False |
---|
| 419 | for pt in reindextypes.keys(): |
---|
[1702] | 420 | modified = True |
---|
[1707] | 421 | try: |
---|
| 422 | doc = getattr(student_object,self.affected_types[pt]['id']).getContent() |
---|
| 423 | sub_objects = True |
---|
| 424 | except: |
---|
| 425 | continue |
---|
| 426 | for field in self.affected_types[pt]['fields']: |
---|
| 427 | if hasattr(self,'get_from_doc_%s' % field): |
---|
| 428 | data[field] = getattr(self,'get_from_doc_%s' % field)(doc) |
---|
| 429 | else: |
---|
| 430 | data[field] = getattr(doc,field) |
---|
| 431 | if not sub_objects and noattr: |
---|
| 432 | import_res = self.returning_import(id = sid) |
---|
| 433 | if not import_res: |
---|
| 434 | continue |
---|
| 435 | import_record = import_res[0] |
---|
| 436 | data['matric_no'] = import_record.matric_no |
---|
| 437 | data['sex'] = import_record.Sex == 'F' |
---|
| 438 | data['name'] = "%s %s %s" % (import_record.Firstname, |
---|
| 439 | import_record.Middlename, |
---|
| 440 | import_record.Lastname) |
---|
[1815] | 441 | data['jamb_reg_no'] = import_record.Entryregno |
---|
[1702] | 442 | if reindex_special and 'registered_courses' in reindex_special: |
---|
[1954] | 443 | try: |
---|
| 444 | study_course = getattr(student_object,"study_course") |
---|
| 445 | level_ids = study_course.objectIds() |
---|
| 446 | except: |
---|
| 447 | continue |
---|
| 448 | if not level_ids: |
---|
| 449 | continue |
---|
| 450 | modified = True |
---|
| 451 | level_ids.sort() |
---|
| 452 | course_ids = getattr(study_course,level_ids[-1]).objectIds() |
---|
| 453 | courses = [] |
---|
| 454 | for c in course_ids: |
---|
| 455 | if c.endswith('_co'): |
---|
| 456 | courses.append(c[:-3]) |
---|
| 457 | else: |
---|
| 458 | courses.append(c) |
---|
| 459 | data['registered_courses'] = courses |
---|
[1702] | 460 | if modified: |
---|
| 461 | self.modifyRecord(**data) |
---|
| 462 | if pghandler: pghandler.finish() |
---|
| 463 | ###) |
---|
[1620] | 464 | |
---|
| 465 | def refreshCatalog(self, clear=0, pghandler=None): ###( |
---|
| 466 | """ re-index everything we can find """ |
---|
| 467 | students_folder = self.portal_url.getPortalObject().campus.students |
---|
| 468 | if clear: |
---|
[1724] | 469 | self._catalog.clear() |
---|
[1700] | 470 | students = self.portal_catalog(portal_type="Student") |
---|
| 471 | num_objects = len(students) |
---|
[1620] | 472 | if pghandler: |
---|
| 473 | pghandler.init('Refreshing catalog: %s' % self.absolute_url(1), num_objects) |
---|
| 474 | for i in xrange(num_objects): |
---|
| 475 | if pghandler: pghandler.report(i) |
---|
[1700] | 476 | student_brain = students[i] |
---|
| 477 | spath = student_brain.getPath() |
---|
[1727] | 478 | student_object = student_brain.getObject() |
---|
[1620] | 479 | data = {} |
---|
[1700] | 480 | sid = data['id'] = student_brain.getId |
---|
| 481 | data['review_state'] = student_brain.review_state |
---|
[1707] | 482 | sub_objects = False |
---|
| 483 | for pt in self.affected_types.keys(): |
---|
| 484 | modified = True |
---|
| 485 | try: |
---|
| 486 | doc = getattr(student_object,self.affected_types[pt]['id']).getContent() |
---|
| 487 | sub_objects = True |
---|
| 488 | except: |
---|
[1727] | 489 | #from pdb import set_trace;set_trace() |
---|
[1707] | 490 | continue |
---|
| 491 | for field in self.affected_types[pt]['fields']: |
---|
| 492 | if hasattr(self,'get_from_doc_%s' % field): |
---|
| 493 | data[field] = getattr(self,'get_from_doc_%s' % field)(doc) |
---|
| 494 | else: |
---|
[1727] | 495 | data[field] = getattr(doc,field,None) |
---|
| 496 | if not sub_objects: |
---|
[1700] | 497 | import_res = self.returning_import(id = sid) |
---|
| 498 | if not import_res: |
---|
[1620] | 499 | continue |
---|
[1700] | 500 | import_record = import_res[0] |
---|
| 501 | data['matric_no'] = import_record.matric_no |
---|
| 502 | data['sex'] = import_record.Sex == 'F' |
---|
| 503 | data['name'] = "%s %s %s" % (import_record.Firstname, |
---|
| 504 | import_record.Middlename, |
---|
| 505 | import_record.Lastname) |
---|
[1815] | 506 | data['jamb_reg_no'] = import_record.Entryregno |
---|
[1727] | 507 | else: |
---|
| 508 | study_course = getattr(student_object,'study_course',None) |
---|
| 509 | current_level = data.get('level',None) |
---|
| 510 | data['registered_courses'] = [] |
---|
| 511 | if study_course and current_level and current_level in study_course.objectIds(): |
---|
| 512 | level_obj = getattr(study_course,current_level) |
---|
[1749] | 513 | courses = [] |
---|
[1727] | 514 | for c in level_obj.objectIds(): |
---|
| 515 | if c.endswith('_co'): |
---|
| 516 | courses.append(c[:-3]) |
---|
| 517 | else: |
---|
| 518 | courses.append(c) |
---|
[1749] | 519 | data['registered_courses'] = courses |
---|
[1700] | 520 | self.addRecord(**data) |
---|
[1620] | 521 | if pghandler: pghandler.finish() |
---|
| 522 | ###) |
---|
| 523 | |
---|
[1700] | 524 | security.declarePrivate('notify_event_listener') ###( |
---|
[1620] | 525 | def notify_event_listener(self,event_type,object,infos): |
---|
| 526 | "listen for events" |
---|
[1716] | 527 | if not infos.has_key('rpath'): |
---|
| 528 | return |
---|
[1702] | 529 | pt = getattr(object,'portal_type',None) |
---|
| 530 | mt = getattr(object,'meta_type',None) |
---|
[1954] | 531 | students_catalog = self |
---|
[1702] | 532 | data = {} |
---|
| 533 | if pt == 'Student' and\ |
---|
| 534 | mt == 'CPS Proxy Folder' and\ |
---|
| 535 | event_type.startswith('workflow'): |
---|
| 536 | data['id'] = object.getId() |
---|
| 537 | data['review_state'] = self.portal_workflow.getInfoFor(object,'review_state',None) |
---|
| 538 | students_catalog.modifyRecord(**data) |
---|
| 539 | return |
---|
[1700] | 540 | rpl = infos['rpath'].split('/') |
---|
[1731] | 541 | if pt == 'Student' and mt == 'CPS Proxy Folder'\ |
---|
| 542 | and event_type == "sys_add_object": |
---|
[1700] | 543 | student_id = object.id |
---|
| 544 | try: |
---|
| 545 | self.addRecord(id = student_id) |
---|
| 546 | except ValueError: |
---|
| 547 | pass |
---|
| 548 | return |
---|
[1716] | 549 | elif pt == 'StudentCourseResult' and mt == 'CPS Proxy Folder': |
---|
| 550 | if event_type not in ("sys_add_object","sys_del_object"): |
---|
| 551 | return |
---|
[2033] | 552 | level_session = getattr(object.aq_parent.getContent(),'session','unknown') |
---|
| 553 | if level_session not in (self.getSessionId()[-2:],'2006/2007'): |
---|
| 554 | return |
---|
[1716] | 555 | course_id = object.getId() |
---|
[1954] | 556 | if course_id.endswith('_co'): |
---|
| 557 | course_id = course_id[:-3] |
---|
[1716] | 558 | student_id = object.absolute_url_path().split('/')[-4] |
---|
[1954] | 559 | res = students_catalog(id = student_id) |
---|
[1716] | 560 | if not res: |
---|
| 561 | return |
---|
| 562 | student_rec = res[0] |
---|
[2039] | 563 | registered_courses = getattr(student_rec,'registered_courses',None) |
---|
| 564 | if not registered_courses: |
---|
[1967] | 565 | registered_courses = [] |
---|
[2039] | 566 | #import pdb;pdb.set_trace() |
---|
[1971] | 567 | if event_type == "sys_add_object": |
---|
| 568 | if course_id not in registered_courses: |
---|
| 569 | registered_courses.append(course_id) |
---|
| 570 | else: |
---|
| 571 | return |
---|
[2039] | 572 | elif registered_courses and event_type == "sys_del_object": |
---|
| 573 | removed = False |
---|
[1954] | 574 | while course_id in registered_courses: |
---|
[2039] | 575 | removed = True |
---|
[1954] | 576 | registered_courses.remove(course_id) |
---|
[2039] | 577 | if not removed: |
---|
| 578 | return |
---|
[1716] | 579 | data['id'] = student_id |
---|
| 580 | data['registered_courses'] = registered_courses |
---|
| 581 | self.modifyRecord(**data) |
---|
[1971] | 582 | return |
---|
[1716] | 583 | if pt not in self.affected_types.keys(): |
---|
[1700] | 584 | return |
---|
[1716] | 585 | if event_type not in ('sys_modify_object'): |
---|
| 586 | return |
---|
[1700] | 587 | if mt == 'CPS Proxy Folder': |
---|
| 588 | return |
---|
[1716] | 589 | for field in self.affected_types[pt]['fields']: |
---|
[1700] | 590 | if hasattr(self,'get_from_doc_%s' % field): |
---|
| 591 | data[field] = getattr(self,'get_from_doc_%s' % field)(object) |
---|
| 592 | else: |
---|
| 593 | data[field] = getattr(object,field) |
---|
| 594 | data['id'] = rpl[2] |
---|
[1716] | 595 | self.modifyRecord(**data) |
---|
[1700] | 596 | ###) |
---|
[1620] | 597 | |
---|
[1625] | 598 | |
---|
[971] | 599 | InitializeClass(StudentsCatalog) |
---|
| 600 | |
---|
[1146] | 601 | ###) |
---|
| 602 | |
---|
[1971] | 603 | class StatisticsCatalog(StudentsCatalog): ###( |
---|
| 604 | security = ClassSecurityInfo() |
---|
| 605 | meta_type = 'WAeUP Statistics Catalog' |
---|
| 606 | name = "statistics" |
---|
| 607 | affected_types = { ###( |
---|
| 608 | 'StudentApplication': |
---|
| 609 | {'id': 'application', |
---|
| 610 | 'fields': |
---|
| 611 | ('jamb_reg_no', |
---|
| 612 | 'entry_mode', |
---|
| 613 | #'entry_level', |
---|
| 614 | 'entry_session', |
---|
| 615 | ) |
---|
| 616 | }, |
---|
| 617 | 'StudentClearance': |
---|
| 618 | {'id': 'clearance', |
---|
| 619 | 'fields': |
---|
| 620 | ('matric_no', |
---|
| 621 | ) |
---|
| 622 | }, |
---|
| 623 | 'StudentPersonal': |
---|
| 624 | {'id': 'personal', |
---|
| 625 | 'fields': |
---|
| 626 | ('name', |
---|
| 627 | 'sex', |
---|
| 628 | 'email', |
---|
| 629 | 'phone', |
---|
| 630 | ) |
---|
| 631 | }, |
---|
| 632 | 'StudentStudyCourse': |
---|
| 633 | {'id': 'study_course', |
---|
| 634 | 'fields': |
---|
| 635 | ('course', |
---|
| 636 | 'faculty', |
---|
| 637 | 'department', |
---|
| 638 | 'level', |
---|
| 639 | 'mode', |
---|
| 640 | 'session', |
---|
| 641 | 'verdict', |
---|
| 642 | ) |
---|
| 643 | }, |
---|
| 644 | } |
---|
| 645 | ###) |
---|
| 646 | |
---|
| 647 | |
---|
| 648 | InitializeClass(StudentsCatalog) |
---|
| 649 | ###) |
---|
| 650 | |
---|
[1146] | 651 | class CoursesCatalog(WAeUPTable): ###( |
---|
[1716] | 652 | security = ClassSecurityInfo() |
---|
[1146] | 653 | |
---|
| 654 | meta_type = 'WAeUP Courses Catalog' |
---|
| 655 | name = "students_catalog" |
---|
| 656 | key = "code" |
---|
| 657 | def __init__(self): |
---|
| 658 | WAeUPTable.__init__(self, 'courses_catalog') |
---|
| 659 | |
---|
[1716] | 660 | def manage_catalogReindex(self, REQUEST, RESPONSE, URL1): ###( |
---|
| 661 | """ clear the catalog, then re-index everything """ |
---|
[1146] | 662 | |
---|
[1716] | 663 | elapse = time.time() |
---|
| 664 | c_elapse = time.clock() |
---|
| 665 | |
---|
| 666 | pgthreshold = self._getProgressThreshold() |
---|
| 667 | handler = (pgthreshold > 0) and ZLogHandler(pgthreshold) or None |
---|
| 668 | self.refreshCatalog(clear=1, pghandler=handler) |
---|
| 669 | |
---|
| 670 | elapse = time.time() - elapse |
---|
| 671 | c_elapse = time.clock() - c_elapse |
---|
| 672 | |
---|
| 673 | RESPONSE.redirect( |
---|
| 674 | URL1 + |
---|
| 675 | '/manage_catalogAdvanced?manage_tabs_message=' + |
---|
| 676 | urllib.quote('Catalog Updated \n' |
---|
| 677 | 'Total time: %s\n' |
---|
| 678 | 'Total CPU time: %s' % (`elapse`, `c_elapse`))) |
---|
| 679 | ###) |
---|
| 680 | |
---|
| 681 | def reindexIndex(self, name, REQUEST,pghandler=None): ###( |
---|
| 682 | if isinstance(name, str): |
---|
| 683 | name = (name,) |
---|
| 684 | courses = self.portal_catalog(portal_type="Course") |
---|
| 685 | num_objects = len(courses) |
---|
| 686 | if pghandler: |
---|
| 687 | pghandler.init('Refreshing catalog: %s' % self.absolute_url(1), num_objects) |
---|
| 688 | for i in xrange(num_objects): |
---|
| 689 | if pghandler: pghandler.report(i) |
---|
| 690 | course_brain = courses[i] |
---|
| 691 | course_object = course_brain.getObject() |
---|
| 692 | pl = course_brain.getPath().split('/') |
---|
| 693 | data = {} |
---|
| 694 | cid = data[self.key] = course_brain.getId |
---|
| 695 | data['faculty'] = pl[-4] |
---|
| 696 | data['department'] = pl[-3] |
---|
| 697 | doc = course_object.getContent() |
---|
| 698 | for field in name: |
---|
| 699 | if field not in (self.key,'faculty','department'): |
---|
| 700 | data[field] = getattr(doc,field) |
---|
| 701 | self.modifyRecord(**data) |
---|
| 702 | if pghandler: pghandler.finish() |
---|
| 703 | ###) |
---|
| 704 | |
---|
| 705 | def refreshCatalog(self, clear=0, pghandler=None): ###( |
---|
| 706 | """ re-index everything we can find """ |
---|
[1724] | 707 | if clear: |
---|
| 708 | self._catalog.clear() |
---|
[1716] | 709 | courses = self.portal_catalog(portal_type="Course") |
---|
| 710 | num_objects = len(courses) |
---|
| 711 | if pghandler: |
---|
| 712 | pghandler.init('Refreshing catalog: %s' % self.absolute_url(1), num_objects) |
---|
[1724] | 713 | #from pdb import set_trace;set_trace() |
---|
[1716] | 714 | for i in xrange(num_objects): |
---|
| 715 | if pghandler: pghandler.report(i) |
---|
| 716 | course_brain = courses[i] |
---|
[1724] | 717 | course_doc = course_brain.getObject().getContent() |
---|
[1716] | 718 | pl = course_brain.getPath().split('/') |
---|
| 719 | data = {} |
---|
[1724] | 720 | for field in self.schema(): |
---|
[1749] | 721 | data[field] = getattr(course_doc,field,None) |
---|
[1716] | 722 | data[self.key] = course_brain.getId |
---|
[1724] | 723 | ai = pl.index('academics') |
---|
| 724 | data['faculty'] = pl[ai +1] |
---|
| 725 | data['department'] = pl[ai +2] |
---|
| 726 | if clear: |
---|
| 727 | self.addRecord(**data) |
---|
| 728 | else: |
---|
| 729 | self.modifyRecord(**data) |
---|
[1716] | 730 | if pghandler: pghandler.finish() |
---|
| 731 | ###) |
---|
| 732 | |
---|
| 733 | security.declarePrivate('notify_event_listener') ###( |
---|
| 734 | def notify_event_listener(self,event_type,object,infos): |
---|
| 735 | "listen for events" |
---|
| 736 | if not infos.has_key('rpath'): |
---|
| 737 | return |
---|
| 738 | pt = getattr(object,'portal_type',None) |
---|
| 739 | mt = getattr(object,'meta_type',None) |
---|
| 740 | if pt != 'Course': |
---|
| 741 | return |
---|
| 742 | data = {} |
---|
| 743 | rpl = infos['rpath'].split('/') |
---|
| 744 | if event_type not in ("sys_add_object","sys_modify_object","sys_del_object"): |
---|
| 745 | return |
---|
| 746 | course_id = object.getId() |
---|
| 747 | data[self.key] = course_id |
---|
[1724] | 748 | if event_type == "sys_add_object" and mt == 'CPS Proxy Folder': |
---|
[1716] | 749 | try: |
---|
| 750 | self.addRecord(**data) |
---|
| 751 | except ValueError: |
---|
[1724] | 752 | return |
---|
| 753 | course_id = object.getId() |
---|
| 754 | doc = object.getContent() |
---|
| 755 | if doc is None: |
---|
| 756 | return |
---|
| 757 | for field in self.schema(): |
---|
[1749] | 758 | data[field] = getattr(doc,field,None) |
---|
[1724] | 759 | data[self.key] = course_id |
---|
| 760 | ai = rpl.index('academics') |
---|
| 761 | data['faculty'] = rpl[ai +1] |
---|
| 762 | data['department'] = rpl[ai +2] |
---|
| 763 | self.modifyRecord(**data) |
---|
| 764 | return |
---|
[1716] | 765 | if event_type == "sys_del_object": |
---|
| 766 | self.deleteRecord(course_id) |
---|
[1724] | 767 | return |
---|
[1716] | 768 | if event_type == "sys_modify_object" and mt == 'Course': |
---|
[1724] | 769 | #from pdb import set_trace;set_trace() |
---|
[1716] | 770 | for field in self.schema(): |
---|
[1749] | 771 | data[field] = getattr(object,field,None) |
---|
[1716] | 772 | course_id = object.aq_parent.getId() |
---|
| 773 | data[self.key] = course_id |
---|
[1724] | 774 | ai = rpl.index('academics') |
---|
| 775 | data['faculty'] = rpl[ai +1] |
---|
| 776 | data['department'] = rpl[ai +2] |
---|
[1716] | 777 | self.modifyRecord(**data) |
---|
| 778 | ###) |
---|
| 779 | |
---|
| 780 | |
---|
[1146] | 781 | InitializeClass(CoursesCatalog) |
---|
[1151] | 782 | ###) |
---|
[1146] | 783 | |
---|
[1625] | 784 | class OnlinePaymentsImport(WAeUPTable): ###( |
---|
[1620] | 785 | |
---|
| 786 | meta_type = 'WAeUP Online Payment Transactions' |
---|
[1625] | 787 | name = "online_payments_import" |
---|
[1620] | 788 | key = "order_id" |
---|
| 789 | def __init__(self): |
---|
| 790 | WAeUPTable.__init__(self, self.name) |
---|
| 791 | |
---|
| 792 | |
---|
| 793 | InitializeClass(CoursesCatalog) |
---|
| 794 | ###) |
---|
| 795 | |
---|
[1151] | 796 | class ReturningImport(WAeUPTable): ###( |
---|
[1146] | 797 | |
---|
[1151] | 798 | meta_type = 'Returning Import Table' |
---|
| 799 | name = "returning_import" |
---|
[1146] | 800 | key = "matric_no" |
---|
| 801 | def __init__(self): |
---|
[1151] | 802 | WAeUPTable.__init__(self, 'returning_import') |
---|
[1146] | 803 | |
---|
| 804 | |
---|
[1151] | 805 | InitializeClass(ReturningImport) |
---|
| 806 | ###) |
---|
[1146] | 807 | |
---|
| 808 | class ResultsImport(WAeUPTable): ###( |
---|
| 809 | |
---|
| 810 | meta_type = 'Results Import Table' |
---|
| 811 | name = "results_import" |
---|
| 812 | key = "key" |
---|
| 813 | def __init__(self): |
---|
| 814 | WAeUPTable.__init__(self, 'results_import') |
---|
| 815 | |
---|
| 816 | |
---|
| 817 | InitializeClass(ResultsImport) |
---|
| 818 | |
---|
| 819 | ###) |
---|
| 820 | |
---|
| 821 | class PaymentsCatalog(WAeUPTable): ###( |
---|
| 822 | |
---|
| 823 | meta_type = 'WAeUP Payments Catalog' |
---|
| 824 | name = "students_catalog" |
---|
| 825 | key = "id" |
---|
| 826 | def __init__(self): |
---|
| 827 | WAeUPTable.__init__(self, 'payments_catalog') |
---|
| 828 | |
---|
| 829 | |
---|
| 830 | InitializeClass(PaymentsCatalog) |
---|
| 831 | |
---|
| 832 | ###) |
---|
| 833 | |
---|
[414] | 834 | # BBB: |
---|
| 835 | AccomodationTable = AccommodationTable |
---|