Ignore:
Timestamp:
14 Apr 2007, 13:21:49 (18 years ago)
Author:
joachim
Message:

some enhancements to the css.
update to newest WAeUPTable

File:
1 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/branches/regebro-noskins/WAeUPTables.py

    r1306 r1686  
    2222from Globals import InitializeClass
    2323from Products.ZCatalog.ZCatalog import ZCatalog
     24from Products.ZCatalog.ProgressHandler import ZLogHandler
    2425from AccessControl import ClassSecurityInfo
    2526from Products.CMFCore.permissions import ModifyPortalContent
    2627
    27 import DateTime
     28import DateTime,time
    2829import csv,re
    2930import logging
     
    4849    implements(IWAeUPTable)
    4950    security = ClassSecurityInfo()
     51
     52    def refreshCatalog(self, clear=0, pghandler=None):
     53        """ don't refresh for a normal table """
     54
     55        if self.REQUEST and self.REQUEST.RESPONSE:
     56            self.REQUEST.RESPONSE.redirect(
     57              URL1 +
     58              '/manage_catalogAdvanced?manage_tabs_message=Catalog%20refresh%20not%20implemented')
     59
     60    def manage_catalogClear(self, REQUEST=None, RESPONSE=None, URL1=None):
     61        """ clears the whole enchilada """
     62        #self._catalog.clear()
     63
     64        if REQUEST and RESPONSE:
     65            RESPONSE.redirect(
     66              URL1 +
     67              '/manage_catalogAdvanced?manage_tabs_message=Catalog%20Clearing%20disabled')
    5068
    5169    def addRecord(self, **data):
     
    7593            raise KeyError("No record for uid %s" % uid)
    7694        record = records[0]
    77         record_data = {}
    78         for field in self.schema() + self.indexes():
    79             record_data[field] = getattr(record, field)
    8095        record_data = {}
    8196        for field in self.schema() + self.indexes():
     
    142157        rec = records[0]
    143158        self.modifyRecord(bed=rec.bed,student=student_id)
    144         s_logger = logging.getLogger('Accommodation.SearchAndReserveBed')
    145         s_logger.info("%s reserved bed %s" % (student_id,rec.bed))
     159        s_logger = logging.getLogger('WAeUPTables.AccommodationTable.searchAndReserveBed')
     160        s_logger.info('%s reserved bed %s' % (student_id,rec.bed))
    146161        return 1,rec.bed
    147162
     
    210225
    211226class StudentsCatalog(WAeUPTable): ###(
     227    security = ClassSecurityInfo()
    212228
    213229    meta_type = 'WAeUP Students Catalog'
    214230    name = "students_catalog"
    215231    key = "id"
     232    interesting_types = ('Student',
     233                         'StudentApplication',
     234                         'StudentCLearance',
     235                         'StudentPersonal',
     236                         'StudentStudyCourse',
     237                         )
     238
    216239    def __init__(self):
    217240        WAeUPTable.__init__(self, 'students_catalog')
     241        return
     242
     243    def get_review_state(self,sid,application_doc,clearance_doc,personal_doc,study_course_doc): ###(
     244        "return the students review_state from portal_catalog"
     245        cat_res = self.portal_catalog(id = sid)
     246        if len(cat_res) != 1:
     247            return None
     248        return cat_res[0].review_state
     249
     250    def get_course(self,sid,application_doc,clearance_doc,personal_doc,study_course_doc):
     251        "return the students study_course"
     252        if study_course_doc is None:
     253            return None
     254        return getattr(study_course_doc,'study_course',None)
     255
     256    def get_department(self,sid,application_doc,clearance_doc,personal_doc,study_course_doc):
     257        "return the students department"
     258        if study_course_doc is None:
     259            return None
     260        certificate_res = self.portal_catalog(id = study_course_doc.study_course)
     261        if len(certificate_res) != 1:
     262            return None
     263        return certificate_res[0].getPath().split('/')[-3]
     264
     265    def get_email(self,sid,application_doc,clearance_doc,personal_doc,study_course_doc):
     266        "return the students email from the personal"
     267        if personal_doc is None:
     268            return None
     269        return getattr(personal_doc,'email',None)
     270
     271    def get_entry_mode(self,sid,application_doc,clearance_doc,personal_doc,study_course_doc):
     272        "return the students entry_mode from the application"
     273        if application_doc is None:
     274            return None
     275        return getattr(application_doc,'entry_mode',None)
     276
     277    def get_jamb_reg_no(self,sid,application_doc,clearance_doc,personal_doc,study_course_doc):
     278        "return the students jamb_reg_no from the application"
     279        if application_doc is None:
     280            return None
     281        return getattr(application_doc,'jamb_reg_no',None)
     282
     283    def get_faculty(self,sid,application_doc,clearance_doc,personal_doc,study_course_doc):
     284        "return the students faculty"
     285        if study_course_doc is None:
     286            return None
     287        certificate_res = self.portal_catalog(id = study_course_doc.study_course)
     288        if len(certificate_res) != 1:
     289            return None
     290        return certificate_res[0].getPath().split('/')[-4]
     291
     292    def get_level(self,sid,application_doc,clearance_doc,personal_doc,study_course_doc):
     293        "return the students study_course"
     294        if study_course_doc is None:
     295            return None
     296        #from pdb import set_trace;set_trace()
     297        return getattr(study_course_doc,'current_level',None)
     298
     299    def get_matric_no(self,sid,application_doc,clearance_doc,personal_doc,study_course_doc):
     300        "return the students matric_no from the clearance "
     301        if clearance_doc is None:
     302            return None
     303        return getattr(clearance_doc,'matric_no',None)
     304
     305    def get_name(self,sid,application_doc,clearance_doc,personal_doc,study_course_doc):
     306        "return the students name from the personal"
     307        if personal_doc is None:
     308            return None
     309        doc = personal_doc
     310        return "%s %s %s" % (doc.firstname,doc.middlename,doc.lastname)
     311
     312    def get_phone(self,sid,application_doc,clearance_doc,personal_doc,study_course_doc):
     313        "return the students phone from the personal"
     314        if personal_doc is None:
     315            return None
     316        return getattr(personal_doc,'phone',None)
     317
     318    def get_sex(self,sid,application_doc,clearance_doc,personal_doc,study_course_doc):
     319        "return the students sex from the personal"
     320        if personal_doc is None:
     321            return None
     322        return getattr(personal_doc,'sex',None)
     323
     324    def get_verdict(self,sid,application_doc,clearance_doc,personal_doc,study_course_doc):
     325        "return the students study_course"
     326        if study_course_doc is None:
     327            return None
     328        return getattr(study_course_doc,'current_verdict',None)
     329    ###)
     330
     331    def refreshCatalog(self, clear=0, pghandler=None): ###(
     332        """ re-index everything we can find """
     333        students_folder = self.portal_url.getPortalObject().campus.students
     334
     335        cat = self._catalog
     336        paths = self._catalog.uids.items()
     337        if clear:
     338            paths = tuple(paths)
     339            cat.clear()
     340
     341        num_objects = len(paths)
     342        if pghandler:
     343            pghandler.init('Refreshing catalog: %s' % self.absolute_url(1), num_objects)
     344        for i in xrange(num_objects):
     345            if pghandler: pghandler.report(i)
     346            p = paths[i]
     347            sid = p[0]
     348            pcat_res = self.portal_catalog(id=sid)
     349            if len(pcat_res) != 1:
     350                continue
     351            student_brain = pcat_res[0]
     352            student_obj = student_brain.getObject()
     353            if student_obj.hasObject('application'):
     354                application_doc = getattr(student_obj,'application').getContent()
     355            else:
     356                application_doc = None
     357            if student_obj.hasObject('clearance'):
     358                clearance_doc = getattr(student_obj,'clearance').getContent()
     359            else:
     360                clearance_doc = None
     361            if student_obj.hasObject('personal'):
     362                personal_doc = getattr(student_obj,'personal').getContent()
     363            else:
     364                personal_doc = None
     365            if student_obj.hasObject('study_course'):
     366                study_course_doc = getattr(student_obj,'study_course').getContent()
     367            else:
     368                study_course_doc = None
     369            data = {}
     370            data['id'] = sid
     371            for field in self.schema():
     372                function = getattr(self,"get_%s" % field, None)
     373                if function is None:
     374                    continue
     375                value = function(sid,application_doc,clearance_doc,personal_doc,study_course_doc)
     376                if value is not None:
     377                    data[field] = value
     378            self.modifyRecord(**data)
     379        if pghandler: pghandler.finish()
     380    ###)
     381
     382    def manage_catalogReindex(self, REQUEST, RESPONSE, URL1):
     383        """ clear the catalog, then re-index everything """
     384
     385        elapse = time.time()
     386        c_elapse = time.clock()
     387
     388        pgthreshold = self._getProgressThreshold()
     389        handler = (pgthreshold > 0) and ZLogHandler(pgthreshold) or None
     390        self.refreshCatalog(clear=0, pghandler=handler)
     391
     392        elapse = time.time() - elapse
     393        c_elapse = time.clock() - c_elapse
     394
     395        RESPONSE.redirect(
     396            URL1 +
     397            '/manage_catalogAdvanced?manage_tabs_message=' +
     398            urllib.quote('Catalog Updated \n'
     399                         'Total time: %s\n'
     400                         'Total CPU time: %s' % (`elapse`, `c_elapse`)))
     401
     402
     403    security.declarePrivate('notify_event_listener')
     404    def notify_event_listener(self,event_type,object,infos):
     405        "listen for events"
     406        pt = object.portal_type
     407        mt = object.meta_type
     408        students_catalog = self.students_catalog
     409        #if pt not in self.interesting_types:
     410        #    return
     411        #print "%(pt)s\n %(event_type)s \n %(infos)s\n" % vars()
     412        if not infos.has_key('rpath'):
     413            return
     414        if pt == 'Student' and event_type == "workflow":
     415            pass
     416        elif mt == 'StudentApplication':
     417            if event_type not in ('sys_modify_object'):
     418                return
     419            print "%(pt)s\n %(event_type)s \n %(infos)s\n" % vars()
     420            from pdb import set_trace;set_trace()
     421            jamb_reg_no = getattr(object,'jamb_reg_no',None)
     422            if jamb_reg_no is None:
     423                return
     424            student_id = infos['rpath'].split('/')[2]
     425            self.fixName(student_id)
     426            student_entry = students_catalog(id = student_id)[0]
     427            if student_entry.jamb_reg_no == jamb_reg_no:
     428                return
     429            students_catalog.modifyRecord(id = student_id,
     430                                          jamb_reg_no = jamb_reg_no)
     431        elif mt == 'StudentPersonal':
     432            if event_type not in ('sys_modify_object'):
     433                return
     434            print "%(pt)s\n %(event_type)s \n %(infos)s\n" % vars()
     435            student_id = infos['rpath'].split('/')[2]
     436            self.fixName(student_id)
    218437
    219438
     
    234453###)
    235454
     455class OnlinePaymentsImport(WAeUPTable): ###(
     456
     457    meta_type = 'WAeUP Online Payment Transactions'
     458    name = "online_payments_import"
     459    key = "order_id"
     460    def __init__(self):
     461        WAeUPTable.__init__(self, self.name)
     462
     463
     464InitializeClass(CoursesCatalog)
     465###)
     466
    236467class ReturningImport(WAeUPTable): ###(
    237468
Note: See TracChangeset for help on using the changeset viewer.