[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 1986 2007-07-05 09:10:38Z henrik $ |
---|
| 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 |
---|
| 552 | course_id = object.getId() |
---|
[1954] | 553 | if course_id.endswith('_co'): |
---|
| 554 | course_id = course_id[:-3] |
---|
[1716] | 555 | student_id = object.absolute_url_path().split('/')[-4] |
---|
[1954] | 556 | res = students_catalog(id = student_id) |
---|
[1716] | 557 | if not res: |
---|
| 558 | return |
---|
| 559 | student_rec = res[0] |
---|
[1966] | 560 | registered_courses = getattr(student_rec,'registered_courses',[]) |
---|
[1971] | 561 | #import pdb;pdb.set_trace() |
---|
[1967] | 562 | try: |
---|
| 563 | x = course_id in registered_courses |
---|
| 564 | except TypeError: |
---|
| 565 | registered_courses = [] |
---|
[1971] | 566 | if event_type == "sys_add_object": |
---|
| 567 | if course_id not in registered_courses: |
---|
| 568 | registered_courses.append(course_id) |
---|
| 569 | else: |
---|
| 570 | return |
---|
[1954] | 571 | elif event_type == "sys_del_object": |
---|
| 572 | while course_id in registered_courses: |
---|
| 573 | registered_courses.remove(course_id) |
---|
[1716] | 574 | data['id'] = student_id |
---|
| 575 | data['registered_courses'] = registered_courses |
---|
| 576 | self.modifyRecord(**data) |
---|
[1971] | 577 | return |
---|
[1716] | 578 | if pt not in self.affected_types.keys(): |
---|
[1700] | 579 | return |
---|
[1716] | 580 | if event_type not in ('sys_modify_object'): |
---|
| 581 | return |
---|
[1700] | 582 | if mt == 'CPS Proxy Folder': |
---|
| 583 | return |
---|
[1716] | 584 | for field in self.affected_types[pt]['fields']: |
---|
[1700] | 585 | if hasattr(self,'get_from_doc_%s' % field): |
---|
| 586 | data[field] = getattr(self,'get_from_doc_%s' % field)(object) |
---|
| 587 | else: |
---|
| 588 | data[field] = getattr(object,field) |
---|
| 589 | data['id'] = rpl[2] |
---|
[1716] | 590 | self.modifyRecord(**data) |
---|
[1700] | 591 | ###) |
---|
[1620] | 592 | |
---|
[1625] | 593 | |
---|
[971] | 594 | InitializeClass(StudentsCatalog) |
---|
| 595 | |
---|
[1146] | 596 | ###) |
---|
| 597 | |
---|
[1971] | 598 | class StatisticsCatalog(StudentsCatalog): ###( |
---|
| 599 | security = ClassSecurityInfo() |
---|
| 600 | meta_type = 'WAeUP Statistics Catalog' |
---|
| 601 | name = "statistics" |
---|
| 602 | affected_types = { ###( |
---|
| 603 | 'StudentApplication': |
---|
| 604 | {'id': 'application', |
---|
| 605 | 'fields': |
---|
| 606 | ('jamb_reg_no', |
---|
| 607 | 'entry_mode', |
---|
| 608 | #'entry_level', |
---|
| 609 | 'entry_session', |
---|
| 610 | ) |
---|
| 611 | }, |
---|
| 612 | 'StudentClearance': |
---|
| 613 | {'id': 'clearance', |
---|
| 614 | 'fields': |
---|
| 615 | ('matric_no', |
---|
| 616 | ) |
---|
| 617 | }, |
---|
| 618 | 'StudentPersonal': |
---|
| 619 | {'id': 'personal', |
---|
| 620 | 'fields': |
---|
| 621 | ('name', |
---|
| 622 | 'sex', |
---|
| 623 | 'email', |
---|
| 624 | 'phone', |
---|
| 625 | ) |
---|
| 626 | }, |
---|
| 627 | 'StudentStudyCourse': |
---|
| 628 | {'id': 'study_course', |
---|
| 629 | 'fields': |
---|
| 630 | ('course', |
---|
| 631 | 'faculty', |
---|
| 632 | 'department', |
---|
| 633 | 'level', |
---|
| 634 | 'mode', |
---|
| 635 | 'session', |
---|
| 636 | 'verdict', |
---|
| 637 | ) |
---|
| 638 | }, |
---|
| 639 | } |
---|
| 640 | ###) |
---|
| 641 | |
---|
| 642 | |
---|
| 643 | InitializeClass(StudentsCatalog) |
---|
| 644 | ###) |
---|
| 645 | |
---|
[1146] | 646 | class CoursesCatalog(WAeUPTable): ###( |
---|
[1716] | 647 | security = ClassSecurityInfo() |
---|
[1146] | 648 | |
---|
| 649 | meta_type = 'WAeUP Courses Catalog' |
---|
| 650 | name = "students_catalog" |
---|
| 651 | key = "code" |
---|
| 652 | def __init__(self): |
---|
| 653 | WAeUPTable.__init__(self, 'courses_catalog') |
---|
| 654 | |
---|
[1716] | 655 | def manage_catalogReindex(self, REQUEST, RESPONSE, URL1): ###( |
---|
| 656 | """ clear the catalog, then re-index everything """ |
---|
[1146] | 657 | |
---|
[1716] | 658 | elapse = time.time() |
---|
| 659 | c_elapse = time.clock() |
---|
| 660 | |
---|
| 661 | pgthreshold = self._getProgressThreshold() |
---|
| 662 | handler = (pgthreshold > 0) and ZLogHandler(pgthreshold) or None |
---|
| 663 | self.refreshCatalog(clear=1, pghandler=handler) |
---|
| 664 | |
---|
| 665 | elapse = time.time() - elapse |
---|
| 666 | c_elapse = time.clock() - c_elapse |
---|
| 667 | |
---|
| 668 | RESPONSE.redirect( |
---|
| 669 | URL1 + |
---|
| 670 | '/manage_catalogAdvanced?manage_tabs_message=' + |
---|
| 671 | urllib.quote('Catalog Updated \n' |
---|
| 672 | 'Total time: %s\n' |
---|
| 673 | 'Total CPU time: %s' % (`elapse`, `c_elapse`))) |
---|
| 674 | ###) |
---|
| 675 | |
---|
| 676 | def reindexIndex(self, name, REQUEST,pghandler=None): ###( |
---|
| 677 | if isinstance(name, str): |
---|
| 678 | name = (name,) |
---|
| 679 | courses = self.portal_catalog(portal_type="Course") |
---|
| 680 | num_objects = len(courses) |
---|
| 681 | if pghandler: |
---|
| 682 | pghandler.init('Refreshing catalog: %s' % self.absolute_url(1), num_objects) |
---|
| 683 | for i in xrange(num_objects): |
---|
| 684 | if pghandler: pghandler.report(i) |
---|
| 685 | course_brain = courses[i] |
---|
| 686 | course_object = course_brain.getObject() |
---|
| 687 | pl = course_brain.getPath().split('/') |
---|
| 688 | data = {} |
---|
| 689 | cid = data[self.key] = course_brain.getId |
---|
| 690 | data['faculty'] = pl[-4] |
---|
| 691 | data['department'] = pl[-3] |
---|
| 692 | doc = course_object.getContent() |
---|
| 693 | for field in name: |
---|
| 694 | if field not in (self.key,'faculty','department'): |
---|
| 695 | data[field] = getattr(doc,field) |
---|
| 696 | self.modifyRecord(**data) |
---|
| 697 | if pghandler: pghandler.finish() |
---|
| 698 | ###) |
---|
| 699 | |
---|
| 700 | def refreshCatalog(self, clear=0, pghandler=None): ###( |
---|
| 701 | """ re-index everything we can find """ |
---|
[1724] | 702 | if clear: |
---|
| 703 | self._catalog.clear() |
---|
[1716] | 704 | courses = self.portal_catalog(portal_type="Course") |
---|
| 705 | num_objects = len(courses) |
---|
| 706 | if pghandler: |
---|
| 707 | pghandler.init('Refreshing catalog: %s' % self.absolute_url(1), num_objects) |
---|
[1724] | 708 | #from pdb import set_trace;set_trace() |
---|
[1716] | 709 | for i in xrange(num_objects): |
---|
| 710 | if pghandler: pghandler.report(i) |
---|
| 711 | course_brain = courses[i] |
---|
[1724] | 712 | course_doc = course_brain.getObject().getContent() |
---|
[1716] | 713 | pl = course_brain.getPath().split('/') |
---|
| 714 | data = {} |
---|
[1724] | 715 | for field in self.schema(): |
---|
[1749] | 716 | data[field] = getattr(course_doc,field,None) |
---|
[1716] | 717 | data[self.key] = course_brain.getId |
---|
[1724] | 718 | ai = pl.index('academics') |
---|
| 719 | data['faculty'] = pl[ai +1] |
---|
| 720 | data['department'] = pl[ai +2] |
---|
| 721 | if clear: |
---|
| 722 | self.addRecord(**data) |
---|
| 723 | else: |
---|
| 724 | self.modifyRecord(**data) |
---|
[1716] | 725 | if pghandler: pghandler.finish() |
---|
| 726 | ###) |
---|
| 727 | |
---|
| 728 | security.declarePrivate('notify_event_listener') ###( |
---|
| 729 | def notify_event_listener(self,event_type,object,infos): |
---|
| 730 | "listen for events" |
---|
| 731 | if not infos.has_key('rpath'): |
---|
| 732 | return |
---|
| 733 | pt = getattr(object,'portal_type',None) |
---|
| 734 | mt = getattr(object,'meta_type',None) |
---|
| 735 | if pt != 'Course': |
---|
| 736 | return |
---|
| 737 | data = {} |
---|
| 738 | rpl = infos['rpath'].split('/') |
---|
| 739 | if event_type not in ("sys_add_object","sys_modify_object","sys_del_object"): |
---|
| 740 | return |
---|
| 741 | course_id = object.getId() |
---|
| 742 | data[self.key] = course_id |
---|
[1724] | 743 | if event_type == "sys_add_object" and mt == 'CPS Proxy Folder': |
---|
[1716] | 744 | try: |
---|
| 745 | self.addRecord(**data) |
---|
| 746 | except ValueError: |
---|
[1724] | 747 | return |
---|
| 748 | course_id = object.getId() |
---|
| 749 | doc = object.getContent() |
---|
| 750 | if doc is None: |
---|
| 751 | return |
---|
| 752 | for field in self.schema(): |
---|
[1749] | 753 | data[field] = getattr(doc,field,None) |
---|
[1724] | 754 | data[self.key] = course_id |
---|
| 755 | ai = rpl.index('academics') |
---|
| 756 | data['faculty'] = rpl[ai +1] |
---|
| 757 | data['department'] = rpl[ai +2] |
---|
| 758 | self.modifyRecord(**data) |
---|
| 759 | return |
---|
[1716] | 760 | if event_type == "sys_del_object": |
---|
| 761 | self.deleteRecord(course_id) |
---|
[1724] | 762 | return |
---|
[1716] | 763 | if event_type == "sys_modify_object" and mt == 'Course': |
---|
[1724] | 764 | #from pdb import set_trace;set_trace() |
---|
[1716] | 765 | for field in self.schema(): |
---|
[1749] | 766 | data[field] = getattr(object,field,None) |
---|
[1716] | 767 | course_id = object.aq_parent.getId() |
---|
| 768 | data[self.key] = course_id |
---|
[1724] | 769 | ai = rpl.index('academics') |
---|
| 770 | data['faculty'] = rpl[ai +1] |
---|
| 771 | data['department'] = rpl[ai +2] |
---|
[1716] | 772 | self.modifyRecord(**data) |
---|
| 773 | ###) |
---|
| 774 | |
---|
| 775 | |
---|
[1146] | 776 | InitializeClass(CoursesCatalog) |
---|
[1151] | 777 | ###) |
---|
[1146] | 778 | |
---|
[1625] | 779 | class OnlinePaymentsImport(WAeUPTable): ###( |
---|
[1620] | 780 | |
---|
| 781 | meta_type = 'WAeUP Online Payment Transactions' |
---|
[1625] | 782 | name = "online_payments_import" |
---|
[1620] | 783 | key = "order_id" |
---|
| 784 | def __init__(self): |
---|
| 785 | WAeUPTable.__init__(self, self.name) |
---|
| 786 | |
---|
| 787 | |
---|
| 788 | InitializeClass(CoursesCatalog) |
---|
| 789 | ###) |
---|
| 790 | |
---|
[1151] | 791 | class ReturningImport(WAeUPTable): ###( |
---|
[1146] | 792 | |
---|
[1151] | 793 | meta_type = 'Returning Import Table' |
---|
| 794 | name = "returning_import" |
---|
[1146] | 795 | key = "matric_no" |
---|
| 796 | def __init__(self): |
---|
[1151] | 797 | WAeUPTable.__init__(self, 'returning_import') |
---|
[1146] | 798 | |
---|
| 799 | |
---|
[1151] | 800 | InitializeClass(ReturningImport) |
---|
| 801 | ###) |
---|
[1146] | 802 | |
---|
| 803 | class ResultsImport(WAeUPTable): ###( |
---|
| 804 | |
---|
| 805 | meta_type = 'Results Import Table' |
---|
| 806 | name = "results_import" |
---|
| 807 | key = "key" |
---|
| 808 | def __init__(self): |
---|
| 809 | WAeUPTable.__init__(self, 'results_import') |
---|
| 810 | |
---|
| 811 | |
---|
| 812 | InitializeClass(ResultsImport) |
---|
| 813 | |
---|
| 814 | ###) |
---|
| 815 | |
---|
| 816 | class PaymentsCatalog(WAeUPTable): ###( |
---|
| 817 | |
---|
| 818 | meta_type = 'WAeUP Payments Catalog' |
---|
| 819 | name = "students_catalog" |
---|
| 820 | key = "id" |
---|
| 821 | def __init__(self): |
---|
| 822 | WAeUPTable.__init__(self, 'payments_catalog') |
---|
| 823 | |
---|
| 824 | |
---|
| 825 | InitializeClass(PaymentsCatalog) |
---|
| 826 | |
---|
| 827 | ###) |
---|
| 828 | |
---|
[414] | 829 | # BBB: |
---|
| 830 | AccomodationTable = AccommodationTable |
---|