1 | #-*- mode: python; mode: fold -*- |
---|
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 1988 2007-07-05 11:14:12Z joachim $ |
---|
20 | |
---|
21 | from zope.interface import implements |
---|
22 | from Globals import InitializeClass |
---|
23 | from Products.ZCatalog.ZCatalog import ZCatalog |
---|
24 | from Products.ZCatalog.ProgressHandler import ZLogHandler |
---|
25 | from AccessControl import ClassSecurityInfo |
---|
26 | from Products.CMFCore.permissions import ModifyPortalContent |
---|
27 | import urllib |
---|
28 | import DateTime,time |
---|
29 | import csv,re |
---|
30 | import logging |
---|
31 | import Globals |
---|
32 | p_home = Globals.package_home(globals()) |
---|
33 | i_home = Globals.INSTANCE_HOME |
---|
34 | from Products.CMFCore.CatalogTool import CatalogTool |
---|
35 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
36 | |
---|
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 | |
---|
48 | class WAeUPTable(ZCatalog): ###( |
---|
49 | |
---|
50 | implements(IWAeUPTable) |
---|
51 | security = ClassSecurityInfo() |
---|
52 | |
---|
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 """ |
---|
63 | |
---|
64 | #if REQUEST and RESPONSE: |
---|
65 | # RESPONSE.redirect( |
---|
66 | # URL1 + |
---|
67 | # '/manage_catalogAdvanced?manage_tabs_message=Catalog%20Clearing%20disabled') |
---|
68 | |
---|
69 | |
---|
70 | self._catalog.clear() |
---|
71 | if REQUEST and RESPONSE: |
---|
72 | RESPONSE.redirect( |
---|
73 | URL1 + |
---|
74 | '/manage_catalogAdvanced?manage_tabs_message=Catalog%20cleared') |
---|
75 | |
---|
76 | def addRecord(self, **data): |
---|
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 |
---|
84 | |
---|
85 | def deleteRecord(self, uid): |
---|
86 | self.uncatalog_object(uid) |
---|
87 | |
---|
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}) |
---|
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 | |
---|
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) |
---|
123 | |
---|
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)) |
---|
143 | ###) |
---|
144 | |
---|
145 | class AccommodationTable(WAeUPTable): ###( |
---|
146 | |
---|
147 | meta_type = 'WAeUP Accommodation Tool' |
---|
148 | name = "accommodation" |
---|
149 | key = "bed" |
---|
150 | def __init__(self): |
---|
151 | WAeUPTable.__init__(self, 'portal_accommodation') |
---|
152 | |
---|
153 | def searchAndReserveBed(self, student_id,bed_type): |
---|
154 | records = self.searchResults({'student' : student_id}) |
---|
155 | if len(records) > 0: |
---|
156 | return -1,"Student with Id %s already booked bed %s." % (student_id,records[0].bed) |
---|
157 | |
---|
158 | records = [r for r in self.searchResults({'bed_type' : bed_type}) if not r.student] |
---|
159 | #import pdb;pdb.set_trace() |
---|
160 | if len(records) == 0: |
---|
161 | return -2,"No bed available" |
---|
162 | rec = records[0] |
---|
163 | self.modifyRecord(bed=rec.bed,student=student_id) |
---|
164 | s_logger = logging.getLogger('WAeUPTables.AccommodationTable.searchAndReserveBed') |
---|
165 | s_logger.info('%s reserved bed %s' % (student_id,rec.bed)) |
---|
166 | return 1,rec.bed |
---|
167 | |
---|
168 | |
---|
169 | InitializeClass(AccommodationTable) |
---|
170 | |
---|
171 | ###) |
---|
172 | |
---|
173 | class PinTable(WAeUPTable): ###( |
---|
174 | from ZODB.POSException import ConflictError |
---|
175 | meta_type = 'WAeUP Pin Tool' |
---|
176 | name = "pins" |
---|
177 | key = 'pin' |
---|
178 | def __init__(self): |
---|
179 | WAeUPTable.__init__(self, 'portal_pins') |
---|
180 | |
---|
181 | |
---|
182 | def searchAndSetRecord(self, uid, student_id,prefix): |
---|
183 | #records = self.searchResults(uid=uid) |
---|
184 | records = self.searchResults(student = student_id) |
---|
185 | #import pdb;pdb.set_trace() |
---|
186 | if len(records) > 0 and prefix in ('CLR','APP'): |
---|
187 | for r in records: |
---|
188 | if r.pin != uid and r.prefix_batch.startswith(prefix): |
---|
189 | return -2 |
---|
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: |
---|
202 | record_data['student'] = student_id |
---|
203 | try: |
---|
204 | self.catalog_object(dict2ob(record_data), uid) |
---|
205 | return 1 |
---|
206 | except ConflictError: |
---|
207 | return 2 |
---|
208 | if record.student.upper() != student_id.upper(): |
---|
209 | return 0 |
---|
210 | if record.student.upper() == student_id.upper(): |
---|
211 | return 2 |
---|
212 | return -3 |
---|
213 | |
---|
214 | InitializeClass(PinTable) |
---|
215 | |
---|
216 | ###) |
---|
217 | |
---|
218 | class PumeResultsTable(WAeUPTable): ###( |
---|
219 | |
---|
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 | |
---|
229 | ###) |
---|
230 | |
---|
231 | class StudentsCatalog(WAeUPTable): ###( |
---|
232 | security = ClassSecurityInfo() |
---|
233 | |
---|
234 | meta_type = 'WAeUP Students Catalog' |
---|
235 | name = "students_catalog" |
---|
236 | key = "id" |
---|
237 | affected_types = { ###( |
---|
238 | 'StudentApplication': |
---|
239 | {'id': 'application', |
---|
240 | 'fields': |
---|
241 | ('jamb_reg_no', |
---|
242 | 'entry_mode', |
---|
243 | #'entry_level', |
---|
244 | 'entry_session', |
---|
245 | ) |
---|
246 | }, |
---|
247 | 'StudentClearance': |
---|
248 | {'id': 'clearance', |
---|
249 | 'fields': |
---|
250 | ('matric_no', |
---|
251 | ) |
---|
252 | }, |
---|
253 | 'StudentPersonal': |
---|
254 | {'id': 'personal', |
---|
255 | 'fields': |
---|
256 | ('name', |
---|
257 | 'sex', |
---|
258 | 'email', |
---|
259 | 'phone', |
---|
260 | ) |
---|
261 | }, |
---|
262 | 'StudentStudyCourse': |
---|
263 | {'id': 'study_course', |
---|
264 | 'fields': |
---|
265 | ('course', |
---|
266 | 'faculty', |
---|
267 | 'department', |
---|
268 | 'level', |
---|
269 | 'mode', |
---|
270 | 'session', |
---|
271 | 'verdict', |
---|
272 | ) |
---|
273 | }, |
---|
274 | } |
---|
275 | ###) |
---|
276 | |
---|
277 | def __init__(self): |
---|
278 | WAeUPTable.__init__(self, 'students_catalog') |
---|
279 | return |
---|
280 | |
---|
281 | def manage_catalogClear(self, REQUEST=None, RESPONSE=None, URL1=None): |
---|
282 | """ clears the whole enchilada """ |
---|
283 | self._catalog.clear() |
---|
284 | |
---|
285 | if REQUEST and RESPONSE: |
---|
286 | RESPONSE.redirect( |
---|
287 | URL1 + |
---|
288 | '/manage_catalogAdvanced?manage_tabs_message=Catalog%20Cleared') |
---|
289 | |
---|
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): ###( |
---|
312 | "return the students department" |
---|
313 | if doc is None: |
---|
314 | return None |
---|
315 | certificate_res = self.portal_catalog(id = doc.study_course) |
---|
316 | if len(certificate_res) != 1: |
---|
317 | return None |
---|
318 | return certificate_res[0].getPath().split('/')[-3] |
---|
319 | |
---|
320 | def get_from_doc_faculty(self,doc): |
---|
321 | "return the students faculty" |
---|
322 | if doc is None: |
---|
323 | return None |
---|
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] |
---|
328 | |
---|
329 | def get_from_doc_level(self,doc): |
---|
330 | "return the students level" |
---|
331 | if doc is None: |
---|
332 | return None |
---|
333 | return getattr(doc,'current_level',None) |
---|
334 | |
---|
335 | def get_from_doc_mode(self,doc): |
---|
336 | "return the students mode" |
---|
337 | if doc is None: |
---|
338 | return None |
---|
339 | cm = getattr(doc,'current_mode',None) |
---|
340 | return cm |
---|
341 | |
---|
342 | |
---|
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 | |
---|
349 | def get_from_doc_entry_session(self,doc): |
---|
350 | "return the students entry_session" |
---|
351 | if doc is None: |
---|
352 | return None |
---|
353 | es = getattr(doc,'entry_session',None) |
---|
354 | if es is not None and len(es) == 2: |
---|
355 | return es |
---|
356 | try: |
---|
357 | digit = int(doc.jamb_reg_no[0]) |
---|
358 | except: |
---|
359 | return "-1" |
---|
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): |
---|
365 | "return the students study_course" |
---|
366 | if doc is None: |
---|
367 | return None |
---|
368 | return getattr(doc,'study_course',None) |
---|
369 | |
---|
370 | def get_from_doc_name(self,doc): |
---|
371 | "return the students name from the personal" |
---|
372 | if doc is None: |
---|
373 | return None |
---|
374 | return "%s %s %s" % (doc.firstname,doc.middlename,doc.lastname) |
---|
375 | |
---|
376 | def get_from_doc_verdict(self,doc): |
---|
377 | "return the students study_course" |
---|
378 | if doc is None: |
---|
379 | return None |
---|
380 | return getattr(doc,'current_verdict',None) |
---|
381 | ###) |
---|
382 | |
---|
383 | def reindexIndex(self, name, REQUEST,pghandler=None): ###( |
---|
384 | if isinstance(name, str): |
---|
385 | name = (name,) |
---|
386 | reindextypes = {} |
---|
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(): |
---|
393 | if n in self.affected_types[pt]['fields']: |
---|
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") |
---|
400 | if hasattr(self,'portal_catalog_real'): |
---|
401 | aq_portal = self.portal_catalog_real.evalAdvancedQuery |
---|
402 | else: |
---|
403 | aq_portal = self.portal_catalog.evalAdvancedQuery |
---|
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] |
---|
411 | student_object = student_brain.getObject() |
---|
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 |
---|
418 | sub_objects = False |
---|
419 | for pt in reindextypes.keys(): |
---|
420 | modified = True |
---|
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) |
---|
441 | data['jamb_reg_no'] = import_record.Entryregno |
---|
442 | if reindex_special and 'registered_courses' in reindex_special: |
---|
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 |
---|
460 | if modified: |
---|
461 | self.modifyRecord(**data) |
---|
462 | if pghandler: pghandler.finish() |
---|
463 | ###) |
---|
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: |
---|
469 | self._catalog.clear() |
---|
470 | students = self.portal_catalog(portal_type="Student") |
---|
471 | num_objects = len(students) |
---|
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) |
---|
476 | student_brain = students[i] |
---|
477 | spath = student_brain.getPath() |
---|
478 | student_object = student_brain.getObject() |
---|
479 | data = {} |
---|
480 | sid = data['id'] = student_brain.getId |
---|
481 | data['review_state'] = student_brain.review_state |
---|
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: |
---|
489 | #from pdb import set_trace;set_trace() |
---|
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: |
---|
495 | data[field] = getattr(doc,field,None) |
---|
496 | if not sub_objects: |
---|
497 | import_res = self.returning_import(id = sid) |
---|
498 | if not import_res: |
---|
499 | continue |
---|
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) |
---|
506 | data['jamb_reg_no'] = import_record.Entryregno |
---|
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) |
---|
513 | courses = [] |
---|
514 | for c in level_obj.objectIds(): |
---|
515 | if c.endswith('_co'): |
---|
516 | courses.append(c[:-3]) |
---|
517 | else: |
---|
518 | courses.append(c) |
---|
519 | data['registered_courses'] = courses |
---|
520 | self.addRecord(**data) |
---|
521 | if pghandler: pghandler.finish() |
---|
522 | ###) |
---|
523 | |
---|
524 | security.declarePrivate('notify_event_listener') ###( |
---|
525 | def notify_event_listener(self,event_type,object,infos): |
---|
526 | "listen for events" |
---|
527 | if not infos.has_key('rpath'): |
---|
528 | return |
---|
529 | pt = getattr(object,'portal_type',None) |
---|
530 | mt = getattr(object,'meta_type',None) |
---|
531 | students_catalog = self |
---|
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 |
---|
540 | rpl = infos['rpath'].split('/') |
---|
541 | if pt == 'Student' and mt == 'CPS Proxy Folder'\ |
---|
542 | and event_type == "sys_add_object": |
---|
543 | student_id = object.id |
---|
544 | try: |
---|
545 | self.addRecord(id = student_id) |
---|
546 | except ValueError: |
---|
547 | pass |
---|
548 | return |
---|
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() |
---|
553 | if course_id.endswith('_co'): |
---|
554 | course_id = course_id[:-3] |
---|
555 | student_id = object.absolute_url_path().split('/')[-4] |
---|
556 | res = students_catalog(id = student_id) |
---|
557 | if not res: |
---|
558 | return |
---|
559 | student_rec = res[0] |
---|
560 | registered_courses = getattr(student_rec,'registered_courses',[]) |
---|
561 | #import pdb;pdb.set_trace() |
---|
562 | try: |
---|
563 | x = course_id in registered_courses |
---|
564 | except TypeError: |
---|
565 | registered_courses = [] |
---|
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 |
---|
571 | elif event_type == "sys_del_object": |
---|
572 | while course_id in registered_courses: |
---|
573 | registered_courses.remove(course_id) |
---|
574 | data['id'] = student_id |
---|
575 | data['registered_courses'] = registered_courses |
---|
576 | self.modifyRecord(**data) |
---|
577 | return |
---|
578 | if pt not in self.affected_types.keys(): |
---|
579 | return |
---|
580 | if event_type not in ('sys_modify_object'): |
---|
581 | return |
---|
582 | if mt == 'CPS Proxy Folder': |
---|
583 | return |
---|
584 | for field in self.affected_types[pt]['fields']: |
---|
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] |
---|
590 | self.modifyRecord(**data) |
---|
591 | ###) |
---|
592 | |
---|
593 | |
---|
594 | InitializeClass(StudentsCatalog) |
---|
595 | |
---|
596 | ###) |
---|
597 | |
---|
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 | |
---|
646 | class CoursesCatalog(WAeUPTable): ###( |
---|
647 | security = ClassSecurityInfo() |
---|
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 | |
---|
655 | def manage_catalogReindex(self, REQUEST, RESPONSE, URL1): ###( |
---|
656 | """ clear the catalog, then re-index everything """ |
---|
657 | |
---|
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 """ |
---|
702 | if clear: |
---|
703 | self._catalog.clear() |
---|
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) |
---|
708 | #from pdb import set_trace;set_trace() |
---|
709 | for i in xrange(num_objects): |
---|
710 | if pghandler: pghandler.report(i) |
---|
711 | course_brain = courses[i] |
---|
712 | course_doc = course_brain.getObject().getContent() |
---|
713 | pl = course_brain.getPath().split('/') |
---|
714 | data = {} |
---|
715 | for field in self.schema(): |
---|
716 | data[field] = getattr(course_doc,field,None) |
---|
717 | data[self.key] = course_brain.getId |
---|
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) |
---|
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 |
---|
743 | if event_type == "sys_add_object" and mt == 'CPS Proxy Folder': |
---|
744 | try: |
---|
745 | self.addRecord(**data) |
---|
746 | except ValueError: |
---|
747 | return |
---|
748 | course_id = object.getId() |
---|
749 | doc = object.getContent() |
---|
750 | if doc is None: |
---|
751 | return |
---|
752 | for field in self.schema(): |
---|
753 | data[field] = getattr(doc,field,None) |
---|
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 |
---|
760 | if event_type == "sys_del_object": |
---|
761 | self.deleteRecord(course_id) |
---|
762 | return |
---|
763 | if event_type == "sys_modify_object" and mt == 'Course': |
---|
764 | #from pdb import set_trace;set_trace() |
---|
765 | for field in self.schema(): |
---|
766 | data[field] = getattr(object,field,None) |
---|
767 | course_id = object.aq_parent.getId() |
---|
768 | data[self.key] = course_id |
---|
769 | ai = rpl.index('academics') |
---|
770 | data['faculty'] = rpl[ai +1] |
---|
771 | data['department'] = rpl[ai +2] |
---|
772 | self.modifyRecord(**data) |
---|
773 | ###) |
---|
774 | |
---|
775 | |
---|
776 | InitializeClass(CoursesCatalog) |
---|
777 | ###) |
---|
778 | |
---|
779 | class OnlinePaymentsImport(WAeUPTable): ###( |
---|
780 | |
---|
781 | meta_type = 'WAeUP Online Payment Transactions' |
---|
782 | name = "online_payments_import" |
---|
783 | key = "order_id" |
---|
784 | def __init__(self): |
---|
785 | WAeUPTable.__init__(self, self.name) |
---|
786 | |
---|
787 | |
---|
788 | InitializeClass(CoursesCatalog) |
---|
789 | ###) |
---|
790 | |
---|
791 | class ReturningImport(WAeUPTable): ###( |
---|
792 | |
---|
793 | meta_type = 'Returning Import Table' |
---|
794 | name = "returning_import" |
---|
795 | key = "matric_no" |
---|
796 | def __init__(self): |
---|
797 | WAeUPTable.__init__(self, 'returning_import') |
---|
798 | |
---|
799 | |
---|
800 | InitializeClass(ReturningImport) |
---|
801 | ###) |
---|
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 | |
---|
829 | # BBB: |
---|
830 | AccomodationTable = AccommodationTable |
---|