Changeset 1620


Ignore:
Timestamp:
22 Mar 2007, 20:52:27 (18 years ago)
Author:
joachim
Message:

created new catalog online_payment_transactions
importOnlinePaymentTransactions in WAeUPTool
there must be a OnlineTransactions?.csv in import
check_transactions checks online_payment_transactions against payments
check_online_payments checks the online_payments against the online_payment_transactions

Location:
WAeUP_SRP/trunk
Files:
3 added
7 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/trunk/PatchCatalogToolXMLAdapter.py

    r1062 r1620  
    2626    new_indexes = []
    2727    new_columns = []
    28     if na[0][1] in ("WAeUP Table"):
    29         not_found = False
    30     elif na[0][1] == "CMF Catalog":
     28    #from pdb import set_trace; set_trace()
     29    if na[0][1] == "CMF Catalog":
    3130        #print na[1][1]
    3231        not_found = False
     
    4948            not_found = True
    5049    if not_found:
    51         self._initProperties(node)
    52         self._initObjects(node)
     50        #self._initProperties(node)
     51        #self._initObjects(node)
    5352        self._initIndexes(node)
    5453        self._initColumns(node)
    55         self._refreshCatalog()
     54        #self._refreshCatalog()
    5655
    5756    self._logger.info("Catalog tool imported.")
  • WAeUP_SRP/trunk/WAeUPTables.py

    r1571 r1620  
    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():
     
    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')
    218 
     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)
     437           
    219438
    220439InitializeClass(StudentsCatalog)
     
    234453###)
    235454
     455class OnlinePaymentTransactions(WAeUPTable): ###(
     456
     457    meta_type = 'WAeUP Online Payment Transactions'
     458    name = "online_payment_transactions"
     459    key = "order_id"
     460    def __init__(self):
     461        WAeUPTable.__init__(self, self.name)
     462
     463
     464InitializeClass(CoursesCatalog)
     465###)
     466
    236467class ReturningImport(WAeUPTable): ###(
    237468
  • WAeUP_SRP/trunk/WAeUPTool.py

    r1580 r1620  
    3838p_home = package_home(globals())
    3939i_home = INSTANCE_HOME
    40 import logging,os
     40import DateTime
     41import logging
    4142import transaction
    42 
    43 
    44 
     43import csv,re,os
    4544
    4645class WAeUPTool(UniqueObject, SimpleItem, ActionProviderBase):
     
    532531    ###)
    533532
     533    security.declareProtected(ModifyPortalContent,"importOnlinePaymentTransactions")###(
     534    def importOnlinePaymentTransactions(self):
     535        """load Online Payment Transactions from CSV values"""
     536        import transaction
     537        import random
     538        #from pdb import set_trace
     539        current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S")
     540        opt = self.online_payment_transactions
     541        students_folder = self.portal_url.getPortalObject().campus.students
     542        start = True
     543        tr_count = 1
     544        total = 0
     545        #name = 'pume_results'
     546        name = 'OnlineTransactions'
     547        no_import = []
     548        imported = []
     549        logger = logging.getLogger('WAeUPTool.importOnlinePaymentTransactions')
     550        try:
     551            transactions = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
     552        except:
     553            logger.error('Error reading %s.csv' % name)
     554            return
     555        for pay_transaction in transactions:
     556            if start:
     557                start = False
     558                logger.info('Start loading from %s.csv' % name)
     559                s = ','.join(['"%s"' % fn for fn in pay_transaction.keys()])
     560                no_import.append('%s,"Error"' % s)
     561                format = ','.join(['"%%(%s)s"' % fn for fn in pay_transaction.keys()])
     562                format_error = format + ',"%(Error)s"'
     563            data = {}
     564            data['datetime'] = date = DateTime.DateTime(pay_transaction['Date'])
     565            data['student_id'] = student_id = pay_transaction['Payer ID']
     566            data['order_id'] = order_id = pay_transaction['Order ID (Tranx Ref)']
     567            data['response_code'] = response_code = pay_transaction['Resp Code']
     568            data['amount'] = amount = pay_transaction['Amount']
     569            dup = False
     570            if response_code == "12":
     571                continue
     572            try:
     573                opt.addRecord(**data)
     574            except ValueError:
     575                dup = True
     576            #from pdb import set_trace;set_trace()
     577            if dup:
     578                if response_code == "00":
     579                    opt.modifyRecord(**data)
     580                else:
     581                    pay_transaction['Error'] = "Duplicate order Id"
     582                    no_import.append( format_error % pay_transaction)
     583                    logger.info("dupplicate order_id %(order_id)s for %(student_id)s %(response_code)s" % data)
     584                    continue
     585            tr_count += 1
     586            if tr_count > 1000:
     587                if len(no_import) > 0:
     588                    open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write(
     589                             '\n'.join(no_import) + '\n')
     590                    no_import = []
     591                em = '%d transactions commited total %s\n' % (tr_count,total)
     592                transaction.commit()
     593                regs = []
     594                logger.info(em)
     595                total += tr_count
     596                tr_count = 0
     597        open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write(
     598                                                '\n'.join(no_import))
     599        return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
     600    ###)
     601
    534602InitializeClass(WAeUPTool)
  • WAeUP_SRP/trunk/exportimport.py

    r1515 r1620  
    120120    importWAeUPTable(site.courses_catalog, '', context,'courses_catalog')
    121121    importWAeUPTable(site.payments_catalog, '', context,'payments_catalog')
     122    importWAeUPTable(site.online_payment_transactions, '', context,'online_payment_transactions')
    122123    importWAeUPTable(site.portal_pins, '', context,'pins')
    123124    importWAeUPTable(site.portal_pumeresults, '', context,'pumeresults')
  • WAeUP_SRP/trunk/profiles/default/toolset.xml

    r1151 r1620  
    77 <required tool_id="payments_catalog"
    88           class="Products.WAeUP_SRP.WAeUPTables.PaymentsCatalog"/>
     9 <required tool_id="online_payment_transactions"
     10           class="Products.WAeUP_SRP.WAeUPTables.OnlinePaymentTransactions"/>
    911 <required tool_id="portal_pins"
    1012           class="Products.WAeUP_SRP.WAeUPTables.PinTable"/>
  • WAeUP_SRP/trunk/skins/waeup_epayment/requery_payment.py

    r1613 r1620  
    1010# $Id$
    1111"""
    12 pay online
     12requery online-payment
    1313"""
    1414from urllib import urlencode
    1515import logging
    16 logger = logging.getLogger('Skins.pay_online')
     16logger = logging.getLogger('Skins.requery_payment')
    1717import DateTime
    1818
     
    4545
    4646
    47 info['callback_url'] = "%s/payments/%s/epayment_requery_cb" % (student.absolute_url(),p_id)
    4847payment = context
    4948if payment.portal_type != 'Payment':
     
    5150payment_doc = payment.getContent()
    5251#from Products.zdb import set_trace;set_trace()
    53 info['order_id'] = payment_doc.order_id
     52info['order_id'] = p_id = payment_doc.order_id
     53info['callback_url'] = "%s/payments/%s/epayment_requery_cb" % (student.absolute_url(),p_id)
    5454info['type_description'] = payment_doc.type_description
    55 info['pay_bill_to'] = payment_doc.pay_bill_to
    5655info['amount'] = payment_doc.amount
     56info['student_id'] = student_id
    5757logger.info('%(student_id)s requeried online school fee payment for order_id %(order_id)s' % info)
    5858payment_fields = (('x_SiteID','site_id'),
  • WAeUP_SRP/trunk/skins/waeup_epayment/requery_payment_form.pt

    r1613 r1620  
    33                tal:define="info options/info">
    44               
    5         <h3>Authorize Online Payment! </h3>
     5        <h3>Requery Online Payment! </h3>
    66        <br />
    77               
     
    1212          <input type="hidden" tal:attributes="name python:arg[0];value python:arg[1]" />
    1313      </span>         
    14       <div>Requery this payment</div>
    1514        <table>
    1615          <tr>
     
    1817            Payment:</td>
    1918            <td tal:content="info/type_description"></td>
    20           </tr>
    21           <tr>
    22             <td>
    23             Name:
    24             </td>
    25             <td tal:content="info/pay_bill_to" />
    2619          </tr>
    2720          <tr>
Note: See TracChangeset for help on using the changeset viewer.