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