[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 1971 2007-06-27 10:03:44Z 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 """ |
---|
[1916] | 63 | |
---|
| 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: |
---|
| 359 | return "xx" |
---|
| 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_session(self,doc): |
---|
| 365 | "return the students session" |
---|
| 366 | if doc is None: |
---|
[1620] | 367 | return None |
---|
[1700] | 368 | return getattr(doc,'current_session',None) |
---|
[1620] | 369 | |
---|
[1700] | 370 | def get_from_doc_course(self,doc): |
---|
[1620] | 371 | "return the students study_course" |
---|
[1700] | 372 | if doc is None: |
---|
[1620] | 373 | return None |
---|
[1700] | 374 | return getattr(doc,'study_course',None) |
---|
[1620] | 375 | |
---|
[1700] | 376 | def get_from_doc_name(self,doc): |
---|
[1620] | 377 | "return the students name from the personal" |
---|
[1700] | 378 | if doc is None: |
---|
[1620] | 379 | return None |
---|
| 380 | return "%s %s %s" % (doc.firstname,doc.middlename,doc.lastname) |
---|
| 381 | |
---|
[1700] | 382 | def get_from_doc_verdict(self,doc): |
---|
| 383 | "return the students study_course" |
---|
| 384 | if doc is None: |
---|
[1620] | 385 | return None |
---|
[1700] | 386 | return getattr(doc,'current_verdict',None) |
---|
[1702] | 387 | ###) |
---|
[1620] | 388 | |
---|
[1702] | 389 | def reindexIndex(self, name, REQUEST,pghandler=None): ###( |
---|
| 390 | if isinstance(name, str): |
---|
| 391 | name = (name,) |
---|
[1749] | 392 | reindextypes = {} |
---|
[1702] | 393 | reindex_special = [] |
---|
| 394 | for n in name: |
---|
| 395 | if n in ("review_state","registered_courses"): |
---|
| 396 | reindex_special.append(n) |
---|
| 397 | else: |
---|
| 398 | for pt in self.affected_types.keys(): |
---|
[1707] | 399 | if n in self.affected_types[pt]['fields']: |
---|
[1702] | 400 | if reindextypes.has_key(pt): |
---|
| 401 | reindextypes[pt].append(n) |
---|
| 402 | else: |
---|
| 403 | reindextypes[pt]= [n] |
---|
| 404 | break |
---|
| 405 | students = self.portal_catalog(portal_type="Student") |
---|
[1954] | 406 | if hasattr(self,'portal_catalog_real'): |
---|
| 407 | aq_portal = self.portal_catalog_real.evalAdvancedQuery |
---|
| 408 | else: |
---|
| 409 | aq_portal = self.portal_catalog.evalAdvancedQuery |
---|
[1702] | 410 | num_objects = len(students) |
---|
| 411 | if pghandler: |
---|
| 412 | pghandler.init('Refreshing catalog: %s' % self.absolute_url(1), num_objects) |
---|
| 413 | noattr = set(('StudentClearance','StudentPersonal')) & set(reindextypes.keys()) |
---|
| 414 | for i in xrange(num_objects): |
---|
| 415 | if pghandler: pghandler.report(i) |
---|
| 416 | student_brain = students[i] |
---|
[1707] | 417 | student_object = student_brain.getObject() |
---|
[1702] | 418 | data = {} |
---|
| 419 | modified = False |
---|
| 420 | sid = data['id'] = student_brain.getId |
---|
| 421 | if reindex_special and 'review_state' in reindex_special: |
---|
| 422 | modified = True |
---|
| 423 | data['review_state'] = student_brain.review_state |
---|
[1707] | 424 | sub_objects = False |
---|
| 425 | for pt in reindextypes.keys(): |
---|
[1702] | 426 | modified = True |
---|
[1707] | 427 | try: |
---|
| 428 | doc = getattr(student_object,self.affected_types[pt]['id']).getContent() |
---|
| 429 | sub_objects = True |
---|
| 430 | except: |
---|
| 431 | continue |
---|
| 432 | for field in self.affected_types[pt]['fields']: |
---|
| 433 | if hasattr(self,'get_from_doc_%s' % field): |
---|
| 434 | data[field] = getattr(self,'get_from_doc_%s' % field)(doc) |
---|
| 435 | else: |
---|
| 436 | data[field] = getattr(doc,field) |
---|
| 437 | if not sub_objects and noattr: |
---|
| 438 | import_res = self.returning_import(id = sid) |
---|
| 439 | if not import_res: |
---|
| 440 | continue |
---|
| 441 | import_record = import_res[0] |
---|
| 442 | data['matric_no'] = import_record.matric_no |
---|
| 443 | data['sex'] = import_record.Sex == 'F' |
---|
| 444 | data['name'] = "%s %s %s" % (import_record.Firstname, |
---|
| 445 | import_record.Middlename, |
---|
| 446 | import_record.Lastname) |
---|
[1815] | 447 | data['jamb_reg_no'] = import_record.Entryregno |
---|
[1702] | 448 | if reindex_special and 'registered_courses' in reindex_special: |
---|
[1954] | 449 | try: |
---|
| 450 | study_course = getattr(student_object,"study_course") |
---|
| 451 | level_ids = study_course.objectIds() |
---|
| 452 | except: |
---|
| 453 | continue |
---|
| 454 | if not level_ids: |
---|
| 455 | continue |
---|
| 456 | modified = True |
---|
| 457 | level_ids.sort() |
---|
| 458 | course_ids = getattr(study_course,level_ids[-1]).objectIds() |
---|
| 459 | courses = [] |
---|
| 460 | for c in course_ids: |
---|
| 461 | if c.endswith('_co'): |
---|
| 462 | courses.append(c[:-3]) |
---|
| 463 | else: |
---|
| 464 | courses.append(c) |
---|
| 465 | data['registered_courses'] = courses |
---|
[1702] | 466 | if modified: |
---|
| 467 | self.modifyRecord(**data) |
---|
| 468 | if pghandler: pghandler.finish() |
---|
| 469 | ###) |
---|
[1620] | 470 | |
---|
| 471 | def refreshCatalog(self, clear=0, pghandler=None): ###( |
---|
| 472 | """ re-index everything we can find """ |
---|
| 473 | students_folder = self.portal_url.getPortalObject().campus.students |
---|
| 474 | if clear: |
---|
[1724] | 475 | self._catalog.clear() |
---|
[1700] | 476 | students = self.portal_catalog(portal_type="Student") |
---|
| 477 | num_objects = len(students) |
---|
[1620] | 478 | if pghandler: |
---|
| 479 | pghandler.init('Refreshing catalog: %s' % self.absolute_url(1), num_objects) |
---|
| 480 | for i in xrange(num_objects): |
---|
| 481 | if pghandler: pghandler.report(i) |
---|
[1700] | 482 | student_brain = students[i] |
---|
| 483 | spath = student_brain.getPath() |
---|
[1727] | 484 | student_object = student_brain.getObject() |
---|
[1620] | 485 | data = {} |
---|
[1700] | 486 | sid = data['id'] = student_brain.getId |
---|
| 487 | data['review_state'] = student_brain.review_state |
---|
[1707] | 488 | sub_objects = False |
---|
| 489 | for pt in self.affected_types.keys(): |
---|
| 490 | modified = True |
---|
| 491 | try: |
---|
| 492 | doc = getattr(student_object,self.affected_types[pt]['id']).getContent() |
---|
| 493 | sub_objects = True |
---|
| 494 | except: |
---|
[1727] | 495 | #from pdb import set_trace;set_trace() |
---|
[1707] | 496 | continue |
---|
| 497 | for field in self.affected_types[pt]['fields']: |
---|
| 498 | if hasattr(self,'get_from_doc_%s' % field): |
---|
| 499 | data[field] = getattr(self,'get_from_doc_%s' % field)(doc) |
---|
| 500 | else: |
---|
[1727] | 501 | data[field] = getattr(doc,field,None) |
---|
| 502 | if not sub_objects: |
---|
[1700] | 503 | import_res = self.returning_import(id = sid) |
---|
| 504 | if not import_res: |
---|
[1620] | 505 | continue |
---|
[1700] | 506 | import_record = import_res[0] |
---|
| 507 | data['matric_no'] = import_record.matric_no |
---|
| 508 | data['sex'] = import_record.Sex == 'F' |
---|
| 509 | data['name'] = "%s %s %s" % (import_record.Firstname, |
---|
| 510 | import_record.Middlename, |
---|
| 511 | import_record.Lastname) |
---|
[1815] | 512 | data['jamb_reg_no'] = import_record.Entryregno |
---|
[1727] | 513 | else: |
---|
| 514 | study_course = getattr(student_object,'study_course',None) |
---|
| 515 | current_level = data.get('level',None) |
---|
| 516 | data['registered_courses'] = [] |
---|
| 517 | if study_course and current_level and current_level in study_course.objectIds(): |
---|
| 518 | level_obj = getattr(study_course,current_level) |
---|
[1749] | 519 | courses = [] |
---|
[1727] | 520 | for c in level_obj.objectIds(): |
---|
| 521 | if c.endswith('_co'): |
---|
| 522 | courses.append(c[:-3]) |
---|
| 523 | else: |
---|
| 524 | courses.append(c) |
---|
[1749] | 525 | data['registered_courses'] = courses |
---|
[1700] | 526 | self.addRecord(**data) |
---|
[1620] | 527 | if pghandler: pghandler.finish() |
---|
| 528 | ###) |
---|
| 529 | |
---|
[1700] | 530 | security.declarePrivate('notify_event_listener') ###( |
---|
[1620] | 531 | def notify_event_listener(self,event_type,object,infos): |
---|
| 532 | "listen for events" |
---|
[1716] | 533 | if not infos.has_key('rpath'): |
---|
| 534 | return |
---|
[1702] | 535 | pt = getattr(object,'portal_type',None) |
---|
| 536 | mt = getattr(object,'meta_type',None) |
---|
[1954] | 537 | students_catalog = self |
---|
[1702] | 538 | data = {} |
---|
| 539 | if pt == 'Student' and\ |
---|
| 540 | mt == 'CPS Proxy Folder' and\ |
---|
| 541 | event_type.startswith('workflow'): |
---|
| 542 | data['id'] = object.getId() |
---|
| 543 | data['review_state'] = self.portal_workflow.getInfoFor(object,'review_state',None) |
---|
| 544 | students_catalog.modifyRecord(**data) |
---|
| 545 | return |
---|
[1700] | 546 | rpl = infos['rpath'].split('/') |
---|
[1731] | 547 | if pt == 'Student' and mt == 'CPS Proxy Folder'\ |
---|
| 548 | and event_type == "sys_add_object": |
---|
[1700] | 549 | student_id = object.id |
---|
| 550 | try: |
---|
| 551 | self.addRecord(id = student_id) |
---|
| 552 | except ValueError: |
---|
| 553 | pass |
---|
| 554 | return |
---|
[1716] | 555 | elif pt == 'StudentCourseResult' and mt == 'CPS Proxy Folder': |
---|
| 556 | if event_type not in ("sys_add_object","sys_del_object"): |
---|
| 557 | return |
---|
| 558 | course_id = object.getId() |
---|
[1954] | 559 | if course_id.endswith('_co'): |
---|
| 560 | course_id = course_id[:-3] |
---|
[1716] | 561 | student_id = object.absolute_url_path().split('/')[-4] |
---|
[1954] | 562 | res = students_catalog(id = student_id) |
---|
[1716] | 563 | if not res: |
---|
| 564 | return |
---|
| 565 | student_rec = res[0] |
---|
[1966] | 566 | registered_courses = getattr(student_rec,'registered_courses',[]) |
---|
[1971] | 567 | #import pdb;pdb.set_trace() |
---|
[1967] | 568 | try: |
---|
| 569 | x = course_id in registered_courses |
---|
| 570 | except TypeError: |
---|
| 571 | registered_courses = [] |
---|
[1971] | 572 | if event_type == "sys_add_object": |
---|
| 573 | if course_id not in registered_courses: |
---|
| 574 | registered_courses.append(course_id) |
---|
| 575 | else: |
---|
| 576 | return |
---|
[1954] | 577 | elif event_type == "sys_del_object": |
---|
| 578 | while course_id in registered_courses: |
---|
| 579 | registered_courses.remove(course_id) |
---|
[1716] | 580 | data['id'] = student_id |
---|
| 581 | data['registered_courses'] = registered_courses |
---|
| 582 | self.modifyRecord(**data) |
---|
[1971] | 583 | return |
---|
[1716] | 584 | if pt not in self.affected_types.keys(): |
---|
[1700] | 585 | return |
---|
[1716] | 586 | if event_type not in ('sys_modify_object'): |
---|
| 587 | return |
---|
[1700] | 588 | if mt == 'CPS Proxy Folder': |
---|
| 589 | return |
---|
[1716] | 590 | for field in self.affected_types[pt]['fields']: |
---|
[1700] | 591 | if hasattr(self,'get_from_doc_%s' % field): |
---|
| 592 | data[field] = getattr(self,'get_from_doc_%s' % field)(object) |
---|
| 593 | else: |
---|
| 594 | data[field] = getattr(object,field) |
---|
| 595 | data['id'] = rpl[2] |
---|
[1716] | 596 | self.modifyRecord(**data) |
---|
[1700] | 597 | ###) |
---|
[1620] | 598 | |
---|
[1625] | 599 | |
---|
[971] | 600 | InitializeClass(StudentsCatalog) |
---|
| 601 | |
---|
[1146] | 602 | ###) |
---|
| 603 | |
---|
[1971] | 604 | class StatisticsCatalog(StudentsCatalog): ###( |
---|
| 605 | security = ClassSecurityInfo() |
---|
| 606 | meta_type = 'WAeUP Statistics Catalog' |
---|
| 607 | name = "statistics" |
---|
| 608 | affected_types = { ###( |
---|
| 609 | 'StudentApplication': |
---|
| 610 | {'id': 'application', |
---|
| 611 | 'fields': |
---|
| 612 | ('jamb_reg_no', |
---|
| 613 | 'entry_mode', |
---|
| 614 | #'entry_level', |
---|
| 615 | 'entry_session', |
---|
| 616 | ) |
---|
| 617 | }, |
---|
| 618 | 'StudentClearance': |
---|
| 619 | {'id': 'clearance', |
---|
| 620 | 'fields': |
---|
| 621 | ('matric_no', |
---|
| 622 | ) |
---|
| 623 | }, |
---|
| 624 | 'StudentPersonal': |
---|
| 625 | {'id': 'personal', |
---|
| 626 | 'fields': |
---|
| 627 | ('name', |
---|
| 628 | 'sex', |
---|
| 629 | 'email', |
---|
| 630 | 'phone', |
---|
| 631 | ) |
---|
| 632 | }, |
---|
| 633 | 'StudentStudyCourse': |
---|
| 634 | {'id': 'study_course', |
---|
| 635 | 'fields': |
---|
| 636 | ('course', |
---|
| 637 | 'faculty', |
---|
| 638 | 'department', |
---|
| 639 | 'level', |
---|
| 640 | 'mode', |
---|
| 641 | 'session', |
---|
| 642 | 'verdict', |
---|
| 643 | ) |
---|
| 644 | }, |
---|
| 645 | } |
---|
| 646 | ###) |
---|
| 647 | |
---|
| 648 | |
---|
| 649 | InitializeClass(StudentsCatalog) |
---|
| 650 | ###) |
---|
| 651 | |
---|
[1146] | 652 | class CoursesCatalog(WAeUPTable): ###( |
---|
[1716] | 653 | security = ClassSecurityInfo() |
---|
[1146] | 654 | |
---|
| 655 | meta_type = 'WAeUP Courses Catalog' |
---|
| 656 | name = "students_catalog" |
---|
| 657 | key = "code" |
---|
| 658 | def __init__(self): |
---|
| 659 | WAeUPTable.__init__(self, 'courses_catalog') |
---|
| 660 | |
---|
[1716] | 661 | def manage_catalogReindex(self, REQUEST, RESPONSE, URL1): ###( |
---|
| 662 | """ clear the catalog, then re-index everything """ |
---|
[1146] | 663 | |
---|
[1716] | 664 | elapse = time.time() |
---|
| 665 | c_elapse = time.clock() |
---|
| 666 | |
---|
| 667 | pgthreshold = self._getProgressThreshold() |
---|
| 668 | handler = (pgthreshold > 0) and ZLogHandler(pgthreshold) or None |
---|
| 669 | self.refreshCatalog(clear=1, pghandler=handler) |
---|
| 670 | |
---|
| 671 | elapse = time.time() - elapse |
---|
| 672 | c_elapse = time.clock() - c_elapse |
---|
| 673 | |
---|
| 674 | RESPONSE.redirect( |
---|
| 675 | URL1 + |
---|
| 676 | '/manage_catalogAdvanced?manage_tabs_message=' + |
---|
| 677 | urllib.quote('Catalog Updated \n' |
---|
| 678 | 'Total time: %s\n' |
---|
| 679 | 'Total CPU time: %s' % (`elapse`, `c_elapse`))) |
---|
| 680 | ###) |
---|
| 681 | |
---|
| 682 | def reindexIndex(self, name, REQUEST,pghandler=None): ###( |
---|
| 683 | if isinstance(name, str): |
---|
| 684 | name = (name,) |
---|
| 685 | courses = self.portal_catalog(portal_type="Course") |
---|
| 686 | num_objects = len(courses) |
---|
| 687 | if pghandler: |
---|
| 688 | pghandler.init('Refreshing catalog: %s' % self.absolute_url(1), num_objects) |
---|
| 689 | for i in xrange(num_objects): |
---|
| 690 | if pghandler: pghandler.report(i) |
---|
| 691 | course_brain = courses[i] |
---|
| 692 | course_object = course_brain.getObject() |
---|
| 693 | pl = course_brain.getPath().split('/') |
---|
| 694 | data = {} |
---|
| 695 | cid = data[self.key] = course_brain.getId |
---|
| 696 | data['faculty'] = pl[-4] |
---|
| 697 | data['department'] = pl[-3] |
---|
| 698 | doc = course_object.getContent() |
---|
| 699 | for field in name: |
---|
| 700 | if field not in (self.key,'faculty','department'): |
---|
| 701 | data[field] = getattr(doc,field) |
---|
| 702 | self.modifyRecord(**data) |
---|
| 703 | if pghandler: pghandler.finish() |
---|
| 704 | ###) |
---|
| 705 | |
---|
| 706 | def refreshCatalog(self, clear=0, pghandler=None): ###( |
---|
| 707 | """ re-index everything we can find """ |
---|
[1724] | 708 | if clear: |
---|
| 709 | self._catalog.clear() |
---|
[1716] | 710 | courses = self.portal_catalog(portal_type="Course") |
---|
| 711 | num_objects = len(courses) |
---|
| 712 | if pghandler: |
---|
| 713 | pghandler.init('Refreshing catalog: %s' % self.absolute_url(1), num_objects) |
---|
[1724] | 714 | #from pdb import set_trace;set_trace() |
---|
[1716] | 715 | for i in xrange(num_objects): |
---|
| 716 | if pghandler: pghandler.report(i) |
---|
| 717 | course_brain = courses[i] |
---|
[1724] | 718 | course_doc = course_brain.getObject().getContent() |
---|
[1716] | 719 | pl = course_brain.getPath().split('/') |
---|
| 720 | data = {} |
---|
[1724] | 721 | for field in self.schema(): |
---|
[1749] | 722 | data[field] = getattr(course_doc,field,None) |
---|
[1716] | 723 | data[self.key] = course_brain.getId |
---|
[1724] | 724 | ai = pl.index('academics') |
---|
| 725 | data['faculty'] = pl[ai +1] |
---|
| 726 | data['department'] = pl[ai +2] |
---|
| 727 | if clear: |
---|
| 728 | self.addRecord(**data) |
---|
| 729 | else: |
---|
| 730 | self.modifyRecord(**data) |
---|
[1716] | 731 | if pghandler: pghandler.finish() |
---|
| 732 | ###) |
---|
| 733 | |
---|
| 734 | security.declarePrivate('notify_event_listener') ###( |
---|
| 735 | def notify_event_listener(self,event_type,object,infos): |
---|
| 736 | "listen for events" |
---|
| 737 | if not infos.has_key('rpath'): |
---|
| 738 | return |
---|
| 739 | pt = getattr(object,'portal_type',None) |
---|
| 740 | mt = getattr(object,'meta_type',None) |
---|
| 741 | if pt != 'Course': |
---|
| 742 | return |
---|
| 743 | data = {} |
---|
| 744 | rpl = infos['rpath'].split('/') |
---|
| 745 | if event_type not in ("sys_add_object","sys_modify_object","sys_del_object"): |
---|
| 746 | return |
---|
| 747 | course_id = object.getId() |
---|
| 748 | data[self.key] = course_id |
---|
[1724] | 749 | if event_type == "sys_add_object" and mt == 'CPS Proxy Folder': |
---|
[1716] | 750 | try: |
---|
| 751 | self.addRecord(**data) |
---|
| 752 | except ValueError: |
---|
[1724] | 753 | return |
---|
| 754 | course_id = object.getId() |
---|
| 755 | doc = object.getContent() |
---|
| 756 | if doc is None: |
---|
| 757 | return |
---|
| 758 | for field in self.schema(): |
---|
[1749] | 759 | data[field] = getattr(doc,field,None) |
---|
[1724] | 760 | data[self.key] = course_id |
---|
| 761 | ai = rpl.index('academics') |
---|
| 762 | data['faculty'] = rpl[ai +1] |
---|
| 763 | data['department'] = rpl[ai +2] |
---|
| 764 | self.modifyRecord(**data) |
---|
| 765 | return |
---|
[1716] | 766 | if event_type == "sys_del_object": |
---|
| 767 | self.deleteRecord(course_id) |
---|
[1724] | 768 | return |
---|
[1716] | 769 | if event_type == "sys_modify_object" and mt == 'Course': |
---|
[1724] | 770 | #from pdb import set_trace;set_trace() |
---|
[1716] | 771 | for field in self.schema(): |
---|
[1749] | 772 | data[field] = getattr(object,field,None) |
---|
[1716] | 773 | course_id = object.aq_parent.getId() |
---|
| 774 | data[self.key] = course_id |
---|
[1724] | 775 | ai = rpl.index('academics') |
---|
| 776 | data['faculty'] = rpl[ai +1] |
---|
| 777 | data['department'] = rpl[ai +2] |
---|
[1716] | 778 | self.modifyRecord(**data) |
---|
| 779 | ###) |
---|
| 780 | |
---|
| 781 | |
---|
[1146] | 782 | InitializeClass(CoursesCatalog) |
---|
[1151] | 783 | ###) |
---|
[1146] | 784 | |
---|
[1625] | 785 | class OnlinePaymentsImport(WAeUPTable): ###( |
---|
[1620] | 786 | |
---|
| 787 | meta_type = 'WAeUP Online Payment Transactions' |
---|
[1625] | 788 | name = "online_payments_import" |
---|
[1620] | 789 | key = "order_id" |
---|
| 790 | def __init__(self): |
---|
| 791 | WAeUPTable.__init__(self, self.name) |
---|
| 792 | |
---|
| 793 | |
---|
| 794 | InitializeClass(CoursesCatalog) |
---|
| 795 | ###) |
---|
| 796 | |
---|
[1151] | 797 | class ReturningImport(WAeUPTable): ###( |
---|
[1146] | 798 | |
---|
[1151] | 799 | meta_type = 'Returning Import Table' |
---|
| 800 | name = "returning_import" |
---|
[1146] | 801 | key = "matric_no" |
---|
| 802 | def __init__(self): |
---|
[1151] | 803 | WAeUPTable.__init__(self, 'returning_import') |
---|
[1146] | 804 | |
---|
| 805 | |
---|
[1151] | 806 | InitializeClass(ReturningImport) |
---|
| 807 | ###) |
---|
[1146] | 808 | |
---|
| 809 | class ResultsImport(WAeUPTable): ###( |
---|
| 810 | |
---|
| 811 | meta_type = 'Results Import Table' |
---|
| 812 | name = "results_import" |
---|
| 813 | key = "key" |
---|
| 814 | def __init__(self): |
---|
| 815 | WAeUPTable.__init__(self, 'results_import') |
---|
| 816 | |
---|
| 817 | |
---|
| 818 | InitializeClass(ResultsImport) |
---|
| 819 | |
---|
| 820 | ###) |
---|
| 821 | |
---|
| 822 | class PaymentsCatalog(WAeUPTable): ###( |
---|
| 823 | |
---|
| 824 | meta_type = 'WAeUP Payments Catalog' |
---|
| 825 | name = "students_catalog" |
---|
| 826 | key = "id" |
---|
| 827 | def __init__(self): |
---|
| 828 | WAeUPTable.__init__(self, 'payments_catalog') |
---|
| 829 | |
---|
| 830 | |
---|
| 831 | InitializeClass(PaymentsCatalog) |
---|
| 832 | |
---|
| 833 | ###) |
---|
| 834 | |
---|
[414] | 835 | # BBB: |
---|
| 836 | AccomodationTable = AccommodationTable |
---|