source: WAeUP_SRP/trunk/WAeUPTables.py @ 1917

Last change on this file since 1917 was 1916, checked in by Henrik Bettermann, 17 years ago

enable catalog clearing

  • Property svn:keywords set to Id
File size: 28.5 KB
Line 
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 1916 2007-06-17 16:51:53Z henrik $
20
21from zope.interface import implements
22from Globals import InitializeClass
23from Products.ZCatalog.ZCatalog import ZCatalog
24from Products.ZCatalog.ProgressHandler import ZLogHandler
25from AccessControl import ClassSecurityInfo
26from Products.CMFCore.permissions import ModifyPortalContent
27import urllib
28import DateTime,time
29import csv,re
30import logging
31import Globals
32p_home = Globals.package_home(globals())
33i_home = Globals.INSTANCE_HOME
34from Products.CMFCore.CatalogTool import CatalogTool
35from Products.AdvancedQuery import Eq, Between, Le,In
36
37from interfaces import IWAeUPTable
38
39class AttributeHolder(object):
40    pass
41
42def dict2ob(dict):
43    ob = AttributeHolder()
44    for key, value in dict.items():
45        setattr(ob, key, value)
46    return ob
47
48class RealCatalogTool(CatalogTool):
49    meta_type = 'Catalog Tool Real'
50    name = id = "portal_catalog_real"
51
52
53class WAeUPTable(ZCatalog): ###(
54
55    implements(IWAeUPTable)
56    security = ClassSecurityInfo()
57
58    def refreshCatalog(self, clear=0, pghandler=None):
59        """ don't refresh for a normal table """
60
61        if self.REQUEST and self.REQUEST.RESPONSE:
62            self.REQUEST.RESPONSE.redirect(
63              URL1 +
64              '/manage_catalogAdvanced?manage_tabs_message=Catalog%20refresh%20not%20implemented')
65
66    def manage_catalogClear(self, REQUEST=None, RESPONSE=None, URL1=None):
67        """ clears the whole enchilada """
68       
69        #if REQUEST and RESPONSE:
70        #    RESPONSE.redirect(
71        #      URL1 +
72        #      '/manage_catalogAdvanced?manage_tabs_message=Catalog%20Clearing%20disabled')
73
74
75        self._catalog.clear()
76        if REQUEST and RESPONSE:
77            RESPONSE.redirect(
78              URL1 +
79              '/manage_catalogAdvanced?manage_tabs_message=Catalog%20cleared')
80
81    def addRecord(self, **data):
82        # The uid is the same as "bed".
83        uid = data[self.key]
84        res = self.searchResults({"%s" % self.key : uid})
85        if len(res) > 0:
86            raise ValueError("More than one record with uid %s" % uid)
87        self.catalog_object(dict2ob(data), uid=uid)
88        return uid
89
90    def deleteRecord(self, uid):
91        self.uncatalog_object(uid)
92
93    def searchAndSetRecord(self, **data):
94        raise NotImplemented
95
96    def modifyRecord(self, **data):
97        #records = self.searchResults(uid=uid)
98        uid = data[self.key]
99        records = self.searchResults({"%s" % self.key : uid})
100        if len(records) > 1:
101            # Can not happen, but anyway...
102            raise ValueError("More than one record with uid %s" % uid)
103        if len(records) == 0:
104            raise KeyError("No record for uid %s" % uid)
105        record = records[0]
106        record_data = {}
107        for field in self.schema() + self.indexes():
108            record_data[field] = getattr(record, field)
109        # Add the updated data:
110        record_data.update(data)
111        self.catalog_object(dict2ob(record_data), uid)
112
113    def reindexIndex(self, name, REQUEST,pghandler=None):
114        if isinstance(name, str):
115            name = (name,)
116        paths = self._catalog.uids.items()
117        i = 0
118        #import pdb;pdb.set_trace()
119        for p,rid in paths:
120            i += 1
121            metadata = self.getMetadataForRID(rid)
122            record_data = {}
123            for field in name:
124                record_data[field] = metadata.get(field)
125            uid = metadata.get(self.key)
126            self.catalog_object(dict2ob(record_data), uid, idxs=name,
127                                update_metadata=0)
128
129    security.declareProtected(ModifyPortalContent,"exportAllRecords")
130    def exportAllRecords(self):
131        "export a WAeUPTable"
132        #import pdb;pdb.set_trace()
133        fields = [field for field in self.schema()]
134        format = ','.join(['"%%(%s)s"' % fn for fn in fields])
135        csv = []
136        csv.append(','.join(['"%s"' % fn for fn in fields]))
137        for uid in self._catalog.uids:
138            records = self.searchResults({"%s" % self.key : uid})
139            if len(records) > 1:
140                # Can not happen, but anyway...
141                raise ValueError("More than one record with uid %s" % uid)
142            if len(records) == 0:
143                raise KeyError("No record for uid %s" % uid)
144            rec = records[0]
145            csv.append(format % rec)
146        current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S")
147        open("%s/import/%s-%s.csv" % (i_home,self.getId(),current),"w+").write('\n'.join(csv))
148
149###)
150
151class AccommodationTable(WAeUPTable): ###(
152
153    meta_type = 'WAeUP Accommodation Tool'
154    name = "accommodation"
155    key = "bed"
156    def __init__(self):
157        WAeUPTable.__init__(self, 'portal_accommodation')
158
159    def searchAndReserveBed(self, student_id,bed_type):
160        records = self.searchResults({'student' : student_id})
161        if len(records) > 0:
162            return -1,"Student with Id %s already booked bed %s." % (student_id,records[0].bed)
163
164        records = [r for r in self.searchResults({'bed_type' : bed_type}) if not r.student]
165        #import pdb;pdb.set_trace()
166        if len(records) == 0:
167            return -2,"No bed available"
168        rec = records[0]
169        self.modifyRecord(bed=rec.bed,student=student_id)
170        s_logger = logging.getLogger('WAeUPTables.AccommodationTable.searchAndReserveBed')
171        s_logger.info('%s reserved bed %s' % (student_id,rec.bed))
172        return 1,rec.bed
173
174
175InitializeClass(AccommodationTable)
176
177###)
178
179class PinTable(WAeUPTable): ###(
180    from ZODB.POSException import ConflictError
181    meta_type = 'WAeUP Pin Tool'
182    name = "pins"
183    key = 'pin'
184    def __init__(self):
185        WAeUPTable.__init__(self, 'portal_pins')
186
187
188    def searchAndSetRecord(self, uid, student_id,prefix):
189        #records = self.searchResults(uid=uid)
190        records = self.searchResults(student = student_id)
191        #import pdb;pdb.set_trace()
192        if len(records) > 0 and prefix in ('CLR','APP'):
193            for r in records:
194                if r.pin != uid and r.prefix_batch.startswith(prefix):
195                    return -2
196        records = self.searchResults({"%s" % self.key : uid})
197        if len(records) > 1:
198            # Can not happen, but anyway...
199            raise ValueError("More than one record with uid %s" % uid)
200        if len(records) == 0:
201            return -1
202        record = records[0]
203        if record.student == "":
204            record_data = {}
205            for field in self.schema() + self.indexes():
206                record_data[field] = getattr(record, field)
207            # Add the updated data:
208            record_data['student'] = student_id
209            try:
210                self.catalog_object(dict2ob(record_data), uid)
211                return 1
212            except ConflictError:
213                return 2
214        if record.student.upper() != student_id.upper():
215            return 0
216        if record.student.upper() == student_id.upper():
217            return 2
218        return -3
219
220InitializeClass(PinTable)
221
222###)
223
224class PumeResultsTable(WAeUPTable): ###(
225
226    meta_type = 'WAeUP PumeResults Tool'
227    name = "pumeresults"
228    key = "jamb_reg_no"
229    def __init__(self):
230        WAeUPTable.__init__(self, 'portal_pumeresults')
231
232
233InitializeClass(PumeResultsTable)
234
235###)
236
237class StudentsCatalog(WAeUPTable): ###(
238    security = ClassSecurityInfo()
239
240    meta_type = 'WAeUP Students Catalog'
241    name = "students_catalog"
242    key = "id"
243    affected_types = {   ###(
244                      'StudentApplication':
245                          {'id': 'application',
246                           'fields':
247                             ('jamb_reg_no',
248                              'entry_mode',
249                              #'entry_level',
250                              'entry_session',
251                              )
252                              },
253                      'StudentClearance':
254                          {'id': 'clearance',
255                           'fields':
256                             ('matric_no',
257                              )
258                              },
259                         'StudentPersonal':
260                          {'id': 'personal',
261                           'fields':
262                             ('name',
263                              'sex',
264                              'email',
265                              'phone',
266                              )
267                              },
268                         'StudentStudyCourse':
269                          {'id': 'study_course',
270                           'fields':
271                             ('course',
272                              'faculty',
273                              'department',
274                              'level',
275                              'mode',
276                              'session',
277                              'verdict',
278                              )
279                              },
280                         }
281    ###)
282
283    def __init__(self):
284        WAeUPTable.__init__(self, 'students_catalog')
285        return
286
287    def manage_catalogClear(self, REQUEST=None, RESPONSE=None, URL1=None):
288        """ clears the whole enchilada """
289        self._catalog.clear()
290
291        if REQUEST and RESPONSE:
292            RESPONSE.redirect(
293              URL1 +
294              '/manage_catalogAdvanced?manage_tabs_message=Catalog%20Cleared')
295
296    def manage_catalogReindex(self, REQUEST, RESPONSE, URL1): ###(
297        """ clear the catalog, then re-index everything """
298
299        elapse = time.time()
300        c_elapse = time.clock()
301
302        pgthreshold = self._getProgressThreshold()
303        handler = (pgthreshold > 0) and ZLogHandler(pgthreshold) or None
304        self.refreshCatalog(clear=1, pghandler=handler)
305
306        elapse = time.time() - elapse
307        c_elapse = time.clock() - c_elapse
308
309        RESPONSE.redirect(
310            URL1 +
311            '/manage_catalogAdvanced?manage_tabs_message=' +
312            urllib.quote('Catalog Updated \n'
313                         'Total time: %s\n'
314                         'Total CPU time: %s' % (`elapse`, `c_elapse`)))
315    ###)
316
317    def get_from_doc_department(self,doc): ###(
318        "return the students department"
319        if doc is None:
320            return None
321        certificate_res = self.portal_catalog(id = doc.study_course)
322        if len(certificate_res) != 1:
323            return None
324        return certificate_res[0].getPath().split('/')[-3]
325
326    def get_from_doc_faculty(self,doc):
327        "return the students faculty"
328        if doc is None:
329            return None
330        certificate_res = self.portal_catalog(id = doc.study_course)
331        if len(certificate_res) != 1:
332            return None
333        return certificate_res[0].getPath().split('/')[-4]
334
335    def get_from_doc_level(self,doc):
336        "return the students level"
337        if doc is None:
338            return None
339        return getattr(doc,'current_level',None)
340
341    def get_from_doc_mode(self,doc):
342        "return the students mode"
343        if doc is None:
344            return None
345        cm = getattr(doc,'current_mode',None)
346        return cm
347
348
349    def get_from_doc_session(self,doc):
350        "return the students current_session"
351        if doc is None:
352            return None
353        return getattr(doc,'current_session',None)
354
355    def get_from_doc_entry_session(self,doc):
356        "return the students entry_session"
357        if doc is None:
358            return None
359        es = getattr(doc,'entry_session',None)
360        if es is not None and len(es) == 2:
361            return es
362        try:
363            digit = int(doc.jamb_reg_no[0])
364        except:
365            return "xx"
366        if digit < 8:
367            return "0%c" % doc.jamb_reg_no[0]
368        return "9%c" % doc.jamb_reg_no[0]
369
370    def get_from_doc_session(self,doc):
371        "return the students session"
372        if doc is None:
373            return None
374        return getattr(doc,'current_session',None)
375
376    def get_from_doc_course(self,doc):
377        "return the students study_course"
378        if doc is None:
379            return None
380        return getattr(doc,'study_course',None)
381
382    def get_from_doc_name(self,doc):
383        "return the students name from the personal"
384        if doc is None:
385            return None
386        return "%s %s %s" % (doc.firstname,doc.middlename,doc.lastname)
387
388    def get_from_doc_verdict(self,doc):
389        "return the students study_course"
390        if doc is None:
391            return None
392        return getattr(doc,'current_verdict',None)
393    ###)
394
395    def reindexIndex(self, name, REQUEST,pghandler=None): ###(
396        if isinstance(name, str):
397            name = (name,)
398        reindextypes = {}
399        reindex_special = []
400        #import pdb;pdb.set_trace()
401        for n in name:
402            if n in ("review_state","registered_courses"):
403                reindex_special.append(n)
404            else:
405                for pt in self.affected_types.keys():
406                    if n in self.affected_types[pt]['fields']:
407                        if reindextypes.has_key(pt):
408                            reindextypes[pt].append(n)
409                        else:
410                            reindextypes[pt]= [n]
411                        break
412        students = self.portal_catalog(portal_type="Student")
413        aq_portal = self.portal_catalog.evalAdvancedQuery
414        num_objects = len(students)
415        if pghandler:
416            pghandler.init('Refreshing catalog: %s' % self.absolute_url(1), num_objects)
417        noattr = set(('StudentClearance','StudentPersonal')) & set(reindextypes.keys())
418        for i in xrange(num_objects):
419            if pghandler: pghandler.report(i)
420            student_brain = students[i]
421            student_object = student_brain.getObject()
422            data = {}
423            modified = False
424            sid = data['id'] = student_brain.getId
425            if reindex_special and 'review_state' in reindex_special:
426                modified = True
427                data['review_state'] = student_brain.review_state
428            sub_objects = False
429            for pt in reindextypes.keys():
430                modified = True
431                try:
432                    doc = getattr(student_object,self.affected_types[pt]['id']).getContent()
433                    sub_objects = True
434                except:
435                    continue
436                for field in self.affected_types[pt]['fields']:
437                    if hasattr(self,'get_from_doc_%s' % field):
438                        data[field] = getattr(self,'get_from_doc_%s' % field)(doc)
439                    else:
440                        data[field] = getattr(doc,field)
441                #from pdb import set_trace;set_trace()
442            if not sub_objects and noattr:
443                import_res = self.returning_import(id = sid)
444                if not import_res:
445                    continue
446                import_record = import_res[0]
447                data['matric_no'] = import_record.matric_no
448                data['sex'] = import_record.Sex == 'F'
449                data['name'] = "%s %s %s" % (import_record.Firstname,
450                                             import_record.Middlename,
451                                             import_record.Lastname)
452                data['jamb_reg_no'] = import_record.Entryregno
453            if reindex_special and 'registered_courses' in reindex_special:
454                query = Eq('id','study_course') & Eq('path',student_brain.getPath())
455                brains = aq_portal(query)
456                while brains:
457                    study_course_path = brains[0].getPath()
458                    level_brains = self.portal_catalog(path = study_course_path,
459                                                       portal_type = "StudentStudyLevel")
460                    if not level_brains:
461                        break
462                    modified = True
463                    level_ids = [l.getId for l in level_brains]
464                    level_ids.sort()
465                    for l in level_brains:
466                        if l.getId == level_ids[-1]:
467                            level_path = l.getPath()
468                            break
469                    result_brains = self.portal_catalog(path = level_path,
470                                                        portal_type = "StudentCourseResult")
471                    course_ids = [cr.getId for cr in result_brains]
472                    courses = []
473                    for c in course_ids:
474                        if c.endswith('_co'):
475                            courses.append(c[:-3])
476                        else:
477                            courses.append(c)
478                    data['registered_courses'] = courses
479                    break
480            if modified:
481                self.modifyRecord(**data)
482        if pghandler: pghandler.finish()
483    ###)
484
485    def refreshCatalog(self, clear=0, pghandler=None): ###(
486        """ re-index everything we can find """
487        students_folder = self.portal_url.getPortalObject().campus.students
488        if clear:
489            self._catalog.clear()
490        students = self.portal_catalog(portal_type="Student")
491        num_objects = len(students)
492        if pghandler:
493            pghandler.init('Refreshing catalog: %s' % self.absolute_url(1), num_objects)
494        for i in xrange(num_objects):
495            if pghandler: pghandler.report(i)
496            student_brain = students[i]
497            spath = student_brain.getPath()
498            student_object = student_brain.getObject()
499            data = {}
500            sid = data['id'] = student_brain.getId
501            data['review_state'] = student_brain.review_state
502            sub_objects = False
503            for pt in self.affected_types.keys():
504                modified = True
505                try:
506                    doc = getattr(student_object,self.affected_types[pt]['id']).getContent()
507                    sub_objects = True
508                except:
509                    #from pdb import set_trace;set_trace()
510                    continue
511                for field in self.affected_types[pt]['fields']:
512                    if hasattr(self,'get_from_doc_%s' % field):
513                        data[field] = getattr(self,'get_from_doc_%s' % field)(doc)
514                    else:
515                        data[field] = getattr(doc,field,None)
516            if not sub_objects:
517                import_res = self.returning_import(id = sid)
518                if not import_res:
519                    continue
520                import_record = import_res[0]
521                data['matric_no'] = import_record.matric_no
522                data['sex'] = import_record.Sex == 'F'
523                data['name'] = "%s %s %s" % (import_record.Firstname,
524                                             import_record.Middlename,
525                                             import_record.Lastname)
526                data['jamb_reg_no'] = import_record.Entryregno
527            else:
528                study_course = getattr(student_object,'study_course',None)
529                current_level = data.get('level',None)
530                data['registered_courses'] = []
531                if study_course and current_level and current_level in study_course.objectIds():
532                    level_obj = getattr(study_course,current_level)
533                    courses = []
534                    for c in level_obj.objectIds():
535                        if c.endswith('_co'):
536                            courses.append(c[:-3])
537                        else:
538                            courses.append(c)
539                    data['registered_courses'] = courses
540            self.addRecord(**data)
541        if pghandler: pghandler.finish()
542    ###)
543
544    security.declarePrivate('notify_event_listener') ###(
545    def notify_event_listener(self,event_type,object,infos):
546        "listen for events"
547        if not infos.has_key('rpath'):
548            return
549        pt = getattr(object,'portal_type',None)
550        mt = getattr(object,'meta_type',None)
551        students_catalog = self.students_catalog
552        data = {}
553        if pt == 'Student' and\
554           mt == 'CPS Proxy Folder' and\
555           event_type.startswith('workflow'):
556            data['id'] = object.getId()
557            data['review_state'] = self.portal_workflow.getInfoFor(object,'review_state',None)
558            students_catalog.modifyRecord(**data)
559            return
560        rpl = infos['rpath'].split('/')
561        if pt == 'Student' and mt == 'CPS Proxy Folder'\
562           and event_type == "sys_add_object":
563            student_id = object.id
564            try:
565                self.addRecord(id = student_id)
566            except ValueError:
567                pass
568            return
569        elif pt == 'StudentCourseResult' and mt == 'CPS Proxy Folder':
570            if event_type not in ("sys_add_object","sys_del_object"):
571                return
572            course_id = object.getId()
573            student_id = object.absolute_url_path().split('/')[-4]
574            res = self(id = student_id)
575            if not res:
576                return
577            student_rec = res[0]
578            registered_courses = student_rec.registered_courses
579            if not registered_courses:
580                level_obj = object.aq_parent
581                courses = []
582                for c in level_obj.objectIds():
583                    if c.endswith('_co'):
584                        courses.append(c[:-3])
585                    else:
586                        courses.append(c)
587                #from pdb import set_trace;set_trace()
588                registered_courses = courses
589            else:
590                if event_type == "sys_add_object":
591                    registered_courses.append(course_id)
592                if event_type == "sys_del_object":
593                    if course_id in registered_courses:
594                        registered_courses.remove(course_id)
595            data['id'] = student_id
596            data['registered_courses'] = registered_courses
597            self.modifyRecord(**data)
598        if pt not in self.affected_types.keys():
599            return
600        if event_type not in ('sys_modify_object'):
601            return
602        if mt == 'CPS Proxy Folder':
603            return
604        for field in self.affected_types[pt]['fields']:
605            if hasattr(self,'get_from_doc_%s' % field):
606                data[field] = getattr(self,'get_from_doc_%s' % field)(object)
607            else:
608                data[field] = getattr(object,field)
609        data['id'] = rpl[2]
610        self.modifyRecord(**data)
611    ###)
612
613
614InitializeClass(StudentsCatalog)
615
616###)
617
618class CoursesCatalog(WAeUPTable): ###(
619    security = ClassSecurityInfo()
620
621    meta_type = 'WAeUP Courses Catalog'
622    name = "students_catalog"
623    key = "code"
624    def __init__(self):
625        WAeUPTable.__init__(self, 'courses_catalog')
626
627    def manage_catalogReindex(self, REQUEST, RESPONSE, URL1): ###(
628        """ clear the catalog, then re-index everything """
629
630        elapse = time.time()
631        c_elapse = time.clock()
632
633        pgthreshold = self._getProgressThreshold()
634        handler = (pgthreshold > 0) and ZLogHandler(pgthreshold) or None
635        self.refreshCatalog(clear=1, pghandler=handler)
636
637        elapse = time.time() - elapse
638        c_elapse = time.clock() - c_elapse
639
640        RESPONSE.redirect(
641            URL1 +
642            '/manage_catalogAdvanced?manage_tabs_message=' +
643            urllib.quote('Catalog Updated \n'
644                         'Total time: %s\n'
645                         'Total CPU time: %s' % (`elapse`, `c_elapse`)))
646    ###)
647
648    def reindexIndex(self, name, REQUEST,pghandler=None): ###(
649        if isinstance(name, str):
650            name = (name,)
651        courses = self.portal_catalog(portal_type="Course")
652        num_objects = len(courses)
653        if pghandler:
654            pghandler.init('Refreshing catalog: %s' % self.absolute_url(1), num_objects)
655        for i in xrange(num_objects):
656            if pghandler: pghandler.report(i)
657            course_brain = courses[i]
658            course_object = course_brain.getObject()
659            pl = course_brain.getPath().split('/')
660            data = {}
661            cid = data[self.key] = course_brain.getId
662            data['faculty'] = pl[-4]
663            data['department'] = pl[-3]
664            doc = course_object.getContent()
665            for field in name:
666                if field not in (self.key,'faculty','department'):
667                    data[field] = getattr(doc,field)
668            self.modifyRecord(**data)
669        if pghandler: pghandler.finish()
670    ###)
671
672    def refreshCatalog(self, clear=0, pghandler=None): ###(
673        """ re-index everything we can find """
674        if clear:
675            self._catalog.clear()
676        courses = self.portal_catalog(portal_type="Course")
677        num_objects = len(courses)
678        if pghandler:
679            pghandler.init('Refreshing catalog: %s' % self.absolute_url(1), num_objects)
680        #from pdb import set_trace;set_trace()
681        for i in xrange(num_objects):
682            if pghandler: pghandler.report(i)
683            course_brain = courses[i]
684            course_doc = course_brain.getObject().getContent()
685            pl = course_brain.getPath().split('/')
686            data = {}
687            for field in self.schema():
688                data[field] = getattr(course_doc,field,None)
689            data[self.key] = course_brain.getId
690            ai = pl.index('academics')
691            data['faculty'] = pl[ai +1]
692            data['department'] = pl[ai +2]
693            if clear:
694                self.addRecord(**data)
695            else:
696                self.modifyRecord(**data)
697        if pghandler: pghandler.finish()
698    ###)
699
700    security.declarePrivate('notify_event_listener') ###(
701    def notify_event_listener(self,event_type,object,infos):
702        "listen for events"
703        if not infos.has_key('rpath'):
704            return
705        pt = getattr(object,'portal_type',None)
706        mt = getattr(object,'meta_type',None)
707        if pt != 'Course':
708            return
709        data = {}
710        rpl = infos['rpath'].split('/')
711        if event_type not in ("sys_add_object","sys_modify_object","sys_del_object"):
712            return
713        course_id = object.getId()
714        data[self.key] = course_id
715        if event_type == "sys_add_object" and mt == 'CPS Proxy Folder':
716            try:
717                self.addRecord(**data)
718            except ValueError:
719                return
720            course_id = object.getId()
721            doc = object.getContent()
722            if doc is None:
723                return
724            for field in self.schema():
725                data[field] = getattr(doc,field,None)
726            data[self.key] = course_id
727            ai = rpl.index('academics')
728            data['faculty'] = rpl[ai +1]
729            data['department'] = rpl[ai +2]
730            self.modifyRecord(**data)
731            return
732        if event_type == "sys_del_object":
733            self.deleteRecord(course_id)
734            return
735        if event_type == "sys_modify_object" and mt == 'Course':
736            #from pdb import set_trace;set_trace()
737            for field in self.schema():
738                data[field] = getattr(object,field,None)
739            course_id = object.aq_parent.getId()
740            data[self.key] = course_id
741            ai = rpl.index('academics')
742            data['faculty'] = rpl[ai +1]
743            data['department'] = rpl[ai +2]
744            self.modifyRecord(**data)
745    ###)
746
747
748InitializeClass(CoursesCatalog)
749###)
750
751class OnlinePaymentsImport(WAeUPTable): ###(
752
753    meta_type = 'WAeUP Online Payment Transactions'
754    name = "online_payments_import"
755    key = "order_id"
756    def __init__(self):
757        WAeUPTable.__init__(self, self.name)
758
759
760InitializeClass(CoursesCatalog)
761###)
762
763class ReturningImport(WAeUPTable): ###(
764
765    meta_type = 'Returning Import Table'
766    name = "returning_import"
767    key = "matric_no"
768    def __init__(self):
769        WAeUPTable.__init__(self, 'returning_import')
770
771
772InitializeClass(ReturningImport)
773###)
774
775class ResultsImport(WAeUPTable): ###(
776
777    meta_type = 'Results Import Table'
778    name = "results_import"
779    key = "key"
780    def __init__(self):
781        WAeUPTable.__init__(self, 'results_import')
782
783
784InitializeClass(ResultsImport)
785
786###)
787
788class PaymentsCatalog(WAeUPTable): ###(
789
790    meta_type = 'WAeUP Payments Catalog'
791    name = "students_catalog"
792    key = "id"
793    def __init__(self):
794        WAeUPTable.__init__(self, 'payments_catalog')
795
796
797InitializeClass(PaymentsCatalog)
798
799###)
800
801# BBB:
802AccomodationTable = AccommodationTable
Note: See TracBrowser for help on using the repository browser.