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