source: WAeUP_SRP/branches/joachim-event-branch/WAeUPTool.py @ 17975

Last change on this file since 17975 was 1673, checked in by joachim, 18 years ago

merge up to 1672

  • Property svn:keywords set to Id
File size: 26.2 KB
Line 
1#-*- mode: python; mode: fold -*-
2# (C) Copyright 2005 The WAeUP group  <http://www.waeup.org>
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: WAeUPTool.py 1673 2007-04-09 16:01:51Z joachim $
20"""The WAeUP Tool Box.
21"""
22
23from AccessControl import ClassSecurityInfo
24from Acquisition import aq_inner
25from Acquisition import aq_parent
26from Globals import DTMLFile
27from Globals import InitializeClass
28from OFS.SimpleItem import SimpleItem
29
30from Products.CMFCore.ActionProviderBase import ActionProviderBase
31from Products.CMFCore.permissions import View
32from Products.ZCatalog.ZCatalog import ZCatalog
33from Products.CMFCore.permissions import ModifyPortalContent
34from Products.CMFCore.utils import UniqueObject
35from Products.CMFCore.URLTool import URLTool
36from Students import makeCertificateCode
37from Globals import package_home,INSTANCE_HOME
38p_home = package_home(globals())
39i_home = INSTANCE_HOME
40import logging,os
41import transaction
42
43
44
45
46class WAeUPTool(UniqueObject, SimpleItem, ActionProviderBase):
47    """WAeUP tool"""
48
49    id = 'waeup_tool'
50    meta_type = 'WAeUP Tool'
51    _actions = ()
52
53    security = ClassSecurityInfo()
54    security.declareObjectProtected(View)
55
56    manage_options = ( ActionProviderBase.manage_options
57                     + SimpleItem.manage_options
58                     )
59
60
61    def generateStudentId(self,letter): ###(
62        import random
63        r = random
64        ##if letter not in ('ABCDEFGIHKLMNOPQRSTUVWXY'):
65        if letter == '?':
66            letter= r.choice('ABCDEFGHKLMNPQRSTUVWXY')
67        sid = "%c%d" % (letter,r.randint(99999,1000000))
68##        students = self.portal_url.getPortalObject().campus.students
69##        while hasattr(students, sid):
70##            sid = "%c%d" % (letter,r.randint(99999,1000000))
71        while self.students_catalog(id = sid):
72            sid = "%c%d" % (letter,r.randint(99999,1000000))
73        return sid
74    ###)
75
76    def generatePassword(self,s=None): ###(
77        import random
78        r = random
79        ##if letter not in ('ABCDEFGIHKLMNOPQRSTUVWXY'):
80        if s is None:
81            s = 'abcdefghklmnpqrstuvwxy23456789'
82        pw = ''
83        while len(pw) < 6:
84            pw += r.choice(s)
85        return pw
86    ###)
87
88    security.declareProtected(ModifyPortalContent,'getCredential') ###(
89    def getCredential(self,student_id):
90        "return a student password"
91        student_entry = getattr(self.portal_directories.students,student_id,None)
92        if student_entry is None:
93            return None
94        return getattr(student_entry,"password","not set")
95    ###)
96
97    security.declarePublic('checkPassword') ###(
98    def checkPassword(self,student_id,password):
99        "return a student password"
100        student_entry = getattr(self.portal_directories.students,student_id,None)
101        if student_entry is None:
102            return False
103        return getattr(student_entry,"password","not set") == password
104    ###)
105
106    security.declarePublic('editPassword') ###(
107    def editPassword(self,student_id,password):
108        "edit a student password"
109        student_entry = getattr(self.portal_directories.students,student_id,None)
110        if student_entry is None:
111            return
112        setattr(student_entry,'password',password)
113    ###)
114
115    security.declareProtected(ModifyPortalContent,'doCommit') ###(
116    def doCommit(self,logger=None):
117        "commit some transactions"
118        transaction.commit()
119    ###)
120
121    security.declarePublic('loadStudentFoto') ###(
122    def loadStudentFoto(self,student):
123        "return a student passport picture"
124        app_doc = student.application.getContent()
125        clear = student.clearance
126        clear_doc = clear.getContent()
127        matric_no = clear_doc.matric_no.upper()
128        picture1 ="%s/import/pictures_returning/%s.jpg" % (i_home,matric_no)
129        picture2 ="%s/import/pictures_returning/%s.JPG" % (i_home,matric_no)
130        #import pdb;pdb.set_trace()
131        if os.path.exists(picture1):
132            file = open(picture1)
133        elif os.path.exists(picture2):
134            file = open(picture2)
135        else:
136            return "passport picture not found %s" % picture1
137
138        outfile = file.read()
139        app_doc.manage_addFile('passport',
140                               file=outfile,
141                               title="%s.jpg" % matric_no)
142        return "successfully loaded passport picture"
143    ###)
144
145    security.declareProtected(ModifyPortalContent,'createOne') ###(
146    def createOne(self,students_folder,student_brain,letter,commit=False):
147        sid = self.waeup_tool.generateStudentId(letter)
148        students_folder.invokeFactory('Student', sid)
149        student = getattr(students_folder,sid)
150        self.portal_workflow.doActionFor(student,'return')
151        student.manage_setLocalRoles(sid, ['Owner',])
152        matric_no = student_brain.matric_no
153        jamb_reg_no = student_brain.Entryregno
154        self.students_catalog.addRecord(id = sid,
155                                           matric_no = matric_no,
156                                           jamb_reg_no = jamb_reg_no,
157                                           sex = student_brain.Sex == "F",
158                                           name = "%s %s %s" % (student_brain.Firstname,
159                                                                student_brain.Middlename,
160                                                                student_brain.Lastname)
161                                        )
162        if commit:
163            transaction.commit()
164        return sid,jamb_reg_no
165    ###)
166
167    security.declareProtected(ModifyPortalContent,'createStudent') ###(
168    def createStudent(self,dict):
169        students_folder = self.portal_url.getPortalObject().campus.students
170        sid = self.waeup_tool.generateStudentId('?')
171        students_folder.invokeFactory('Student', sid)
172        student_obj = getattr(students_folder,sid)
173        password = self.generatePassword()
174        self.makeStudentMember(sid,password)
175        status,entry_mode = dict.get('entry_mode').split('_')
176        wfaction = 'return'
177        if status == "NEW":
178            wfaction = 'admit'
179        matric_no = dict.get('matric_no')
180        email = dict.get('email')
181        level = dict.get('level')
182        jamb_reg_no = dict.get('jamb_reg_no')
183        study_course = dict.get('study_course')
184        self.portal_workflow.doActionFor(student_obj,wfaction)
185        student_obj.manage_setLocalRoles(sid, ['Owner',])
186        student_obj.invokeFactory('StudentApplication','application')
187        application = student_obj.application
188        self.portal_workflow.doActionFor(application,'open',dest_container=application)
189        da = {'Title': 'Application Data'}
190        student_obj.invokeFactory('StudentPersonal','personal')
191        da['entry_mode'] = entry_mode
192        personal = student_obj.personal
193        self.portal_workflow.doActionFor(personal,'open',dest_container=personal)
194        dp = {'Title': 'Personal Data'}
195        student_obj.invokeFactory('StudentClearance','clearance')
196        clearance = student_obj.clearance
197        self.portal_workflow.doActionFor(clearance,'open',dest_container=clearance)
198        dc = {'Title': 'Clearance/Eligibility Record'}
199        dc['matric_no'] = matric_no
200        da['app_email'] = dp['email'] = email
201        da['jamb_reg_no'] = jamb_reg_no
202        dp['firstname'] = dict.get('firstname')
203        dp['middlename'] = dict.get('middlename')
204        dp['lastname'] = dict.get('lastname')
205        da['jamb_lastname'] = "%(firstname)s %(middlename)s %(lastname)s" % dict
206        sex = dict.get('sex')
207        if sex:
208            da['jamb_sex'] = 'F'
209        else:
210            da['jamb_sex'] = 'M'
211        dp['sex'] = sex
212        application.getContent().edit(mapping=da)
213        self.portal_workflow.doActionFor(application,'close',dest_container=application)
214        personal.getContent().edit(mapping=dp)
215        clearance.getContent().edit(mapping=dc)
216        self.portal_workflow.doActionFor(clearance,'close',dest_container=clearance)
217        catd = {}
218        catd['id'] = sid
219        catd['entry_mode']= entry_mode
220        catd['email'] = email
221        catd['jamb_reg_no'] = jamb_reg_no
222        catd['matric_no'] = matric_no
223        catd['name'] = "%(firstname)s %(middlename)s %(lastname)s" % dp
224        catd['sex'] = dp['sex']
225        catd['level'] = level
226        certificate_brain = self.getCertificateBrain(study_course)
227        if certificate_brain:
228            cpath = certificate_brain.getPath().split('/')
229            catd['faculty'] = cpath[-4]
230            catd['department'] = cpath[-3]
231            catd['course'] = study_course
232        self.students_catalog.addRecord(**catd)
233        #
234        # Study Course
235        #
236        student_obj.invokeFactory('StudentStudyCourse','study_course')
237        sc = student_obj.study_course
238        self.portal_workflow.doActionFor(sc,'open',dest_container=sc)
239        dsc = {}
240        dsc['study_course'] = study_course
241        dsc['current_level'] = level
242        sc.getContent().edit(mapping=dsc)
243
244        return sid,password
245    ###)
246
247    security.declarePublic('getCertificateBrain') ###(
248    def getCertificateBrain(self,cert_id):
249        "do it"
250        res = ZCatalog.searchResults(self.portal_catalog,
251                                {'portal_type':"Certificate",
252                                      'id': cert_id})
253        if res:
254            return res[0]
255        return None
256    ###)
257
258    security.declarePublic('findStudentByMatricelNo') ###(
259    def findStudentByMatricelNo(self,matric_no):
260        "do it"
261        res = ZCatalog.searchResults(self.portal_catalog,
262                                {'portal_type':"StudentClearance",
263                                 'SearchableText': matric_no})
264        if res:
265            return res[0]
266        return None
267    ###)
268
269    security.declarePublic('makeStudentMember') ###(
270    def makeStudentMember(self,sid,password='uNsEt'):
271        """make the student a member"""
272        membership = self.portal_membership
273        membership.addMember(sid,
274                             password ,
275                             roles=('Member',
276                                     'Student',
277                                     ),
278                             domains='',
279                             properties = {'memberareaCreationFlag': False,
280                                           'homeless': True},)
281        member = membership.getMemberById(sid)
282        self.portal_registration.afterAdd(member, sid, password, None)
283        #self.manage_setLocalRoles(sid, ['Owner',])
284    ###)
285
286    security.declarePublic('makeStudentData') ###(
287    def makeStudentData(self,student_id,email=None,phone_nr=None):
288        "create Datastructure for a returning Student"
289        #import pdb;pdb.set_trace()
290        logger = logging.getLogger('WAeUPTool.makeStudentData')
291        students_folder = self.portal_url.getPortalObject().campus.students
292        res = self.students_catalog(id=student_id)
293        if res:
294            st = res[0]
295        res = self.returning_import(matric_no = st.matric_no)
296        if res:
297            student = res[0]
298        logger.info('%s creates data structure' % student_id)
299        s_results = self.results_import(matric_no = st.matric_no)
300        lnr = self.getLevelFromResultsCosCode(s_results)
301        level = "%d00" % lnr
302        verdict,elegible = self.getVerdict(s_results[0].Verdict)
303        if elegible:
304            level = "%d00" % (lnr + 1)
305##        level = s_results[0].Level
306##        for result in s_results:
307##            if level != result.Level:
308##                logger.info('"%s", "Levels differ","%s != %s"' % (student_id,level,result.Level))
309        #student should not be allowed to perform this transition
310        #wftool = self.portal_workflow
311        #wftool.doActionFor(student,'return')
312        certcode_org = student.Coursemajorcode
313        certcode = makeCertificateCode(certcode_org)
314        certificate_brain = self.getCertificateBrain(certcode)
315        if not certificate_brain:
316            em = 'Certificate %s org-code %s not found\n' % (certcode, certcode_org)
317            logger.info(em)
318        matric_no = student.matric_no
319        sid = student_id
320        student_obj = getattr(students_folder,sid)
321        student_obj.invokeFactory('StudentApplication','application')
322        application = student_obj.application
323        self.portal_workflow.doActionFor(application,'open',dest_container=application)
324        da = {'Title': 'Application Data'}
325        student_obj.invokeFactory('StudentPersonal','personal')
326        da['jamb_reg_no'] = student.Entryregno
327        em = self.getEntryMode(student.Entryregno)
328##        em = student.Mode_of_Entry
329##        if em in ('DIRECT', 'DIRECT ENTRY',):
330##            em = 'DE'
331##        elif em in ('U.M.E', 'UNE',):
332##            em = 'UME'
333##        elif not em:
334##            em = "unknown"
335        da['entry_mode'] = em
336        personal = student_obj.personal
337        self.portal_workflow.doActionFor(personal,'open',dest_container=personal)
338        dp = {'Title': 'Personal Data'}
339        student_obj.invokeFactory('StudentClearance','clearance')
340        clearance = student_obj.clearance
341        self.portal_workflow.doActionFor(clearance,'open',dest_container=clearance)
342        dc = {'Title': 'Clearance/Eligibility Record'}
343        dc['matric_no'] = matric_no
344        state = student.State
345        lga = student.LGA
346        if state and lga:
347            lga =  state + ' / ' + lga
348        else:
349            lga = "None"
350        da['jamb_lga'] = dc['lga'] = lga
351        da['app_email'] = dp['email'] = email
352        da['app_mobile'] = dp['phone'] = phone_nr
353        dp['firstname'] = student.Firstname
354        dp['middlename'] = student.Middlename
355        dp['lastname'] = student.Lastname
356        da['jamb_lastname'] = "%s %s %s" % (student.Firstname,student.Middlename,student.Lastname)
357        da['jamb_sex'] = student.Sex
358        dp['sex'] = student.Sex == 'F'
359        dp['perm_address'] = student.Permanent_Address
360        application.getContent().edit(mapping=da)
361        self.portal_workflow.doActionFor(application,'close',dest_container=application)
362        personal.getContent().edit(mapping=dp)
363        clearance.getContent().edit(mapping=dc)
364        self.portal_workflow.doActionFor(clearance,'close',dest_container=clearance)
365        catd = {}
366        catd['id'] = sid
367        catd['entry_mode']= da['entry_mode']
368        catd['matric_no'] = matric_no
369        catd['jamb_reg_no'] = da['jamb_reg_no']
370        catd['name'] = "%(firstname)s %(middlename)s %(lastname)s" % dp
371        catd['sex'] = dp['sex']
372        catd['level'] = level
373        catd['verdict'] = verdict
374        if certificate_brain:
375            cpath = certificate_brain.getPath().split('/')
376            catd['faculty'] = cpath[-4]
377            catd['department'] = cpath[-3]
378            catd['course'] = certcode
379        self.students_catalog.modifyRecord(**catd)
380        #
381        # Study Course
382        #
383        student_obj.invokeFactory('StudentStudyCourse','study_course')
384        studycourse = student_obj.study_course
385        self.portal_workflow.doActionFor(studycourse,'open',dest_container=studycourse)
386        dsc = {}
387        dsc['study_course'] = certcode
388        dsc['current_level'] = level
389        dsc['current_verdict'] = verdict
390        studycourse.getContent().edit(mapping=dsc)
391        #
392        # Level
393        #
394##        l = getattr(studycourse,level,None)
395##        if l is None:
396##            studycourse.invokeFactory('StudentStudyLevel', level)
397##            l = getattr(studycourse, level)
398##            self.portal_workflow.doActionFor(l,'open',dest_container=l)
399##            l.getContent().edit(mapping={'Title': "Level %s" % level})
400###)
401
402    security.declarePublic('makeStudentLevel') ###(
403    def makeStudentLevel(self,student_id):
404        "create the StudyLevel for a returning Student"
405        #import pdb;pdb.set_trace()
406        logger = logging.getLogger('WAeUPTool.makeStudentLevel')
407        students_folder = self.portal_url.getPortalObject().campus.students
408        res = self.students_catalog(id=student_id)
409        if res:
410            st = res[0]
411        course = st.course
412        matric_no = st.matric_no
413        level = st.level
414        res = self.results_import(matric_no = matric_no)
415        if res:
416            results = res
417        logger.info('%s creating Level %s' % (student_id,level))
418        #
419        # Level
420        #
421        student_obj = getattr(self.portal_url.getPortalObject().campus.students,student_id)
422        studycourse = getattr(student_obj,"study_course",None)
423        self.portal_workflow.doActionFor(studycourse,'close_for_edit',dest_container=studycourse)
424        l = getattr(studycourse,level,None)
425        if l is None:
426            studycourse.invokeFactory('StudentStudyLevel', level)
427            l = getattr(studycourse, level)
428            self.portal_workflow.doActionFor(l,'open',dest_container=l)
429            l.getContent().edit(mapping={'Title': "Level %s" % level})
430        ###)
431
432    security.declarePublic('getAccommodationInfo') ###(
433    def getAccommodationInfo(self,bed):
434        """return Accommodation Info"""
435        info = {}
436        hall,block,room,letter = bed.split('_')
437        res = ZCatalog.searchResults(self.portal_catalog,portal_type="AccoHall",id=hall)
438        if res and len(res) == 1:
439            hall_brain = res[0]
440            hall_doc = hall_brain.getObject().getContent()
441        else:
442            return info
443        info['hall_title'] = hall_brain.Title
444        info['maintenance_code'] = hall_doc.maintenance_code
445        res = ZCatalog.searchResults(self.portal_catalog,portal_type="ScratchCardBatch")
446        batch_doc = None
447        for brain in res:
448            if brain.id.startswith(info['maintenance_code']):
449                batch_doc = brain.getObject().getContent()
450                break
451        if batch_doc is None:
452            info['maintenance_fee'] = None
453        else:
454            info['maintenance_fee'] = batch_doc.cost
455        return info
456    ###)
457
458    security.declareProtected(ModifyPortalContent,'deleteAllCourses') ###(
459    def deleteAllCourses(self,department="All"):
460        ''' delete the courses'''
461        pm = self.portal_membership
462        member = pm.getAuthenticatedMember()
463
464        if str(member) not in ("henrik","joachim"):
465            return "not possible"
466        if department == "All":
467            res = self.portal_catalog({'meta_type': 'Department'})
468        if len(res) < 1:
469            return "No Departments found"
470
471        deleted = []
472        for dep in res:
473            cf = dep.getObject().courses
474            if cf:
475                cf.manage_delObjects(ids=cf.objectIds())
476                deleted.append("deleted Courses in %s" % dep.getId)
477        return "\r".join(deleted)
478    ###)
479
480    security.declareProtected(ModifyPortalContent,'getLogfileLines') ###(
481    def getLogfileLines(self,filename="event.log",numlines=20):
482        """Get last NUMLINES lines of logfile FILENAME.
483
484        Return last lines' of a file in the instances logfile directory as
485        a list. The number of returned lines equals `numlines' or less. If
486        less than `numlines' lines are available, the whole file ist
487        returned. If the file can not be opened or some other error
488        occurs, empty list is returend.
489        """
490        result = []
491        lines_hit = 0
492
493        # We only handle files in instances' log directory...
494        logpath = os.path.join(i_home, "log")
495        filename = str(os.path.abspath( os.path.join( logpath, filename )))
496        if not filename.startswith( logpath ):
497            # Attempt to access file outside log-dir...
498            return []
499
500        try:
501            fd = file( filename, "rb" )
502        except IOError:
503            return []
504        if not fd:
505            return []
506
507        if os.linesep == None:
508            linesep = '\n'
509        else:
510            linesep = os.linesep
511
512        # Try to find 'numlines' times a lineseparator, searching from end
513        # and moving to the beginning of file...
514        fd.seek( 0, 2) # Move to end of file...
515        while lines_hit < numlines:
516            if fd.read(1) == linesep[-1]: # This moves filedescriptor
517                                          # one step forward...
518                lines_hit += 1
519            try:
520                fd.seek( -2, 1) # Go two bytes back from current pos...
521            except IOError:
522                # We cannot go back two bytes. Maybe the file is too small...
523                break
524        fd.seek(2,1)
525
526        # Read all lines from current position...
527        result = fd.readlines()
528        # Remove line endings...
529        result = [x.strip() for x in result]
530        fd.close()
531        return result
532    ###)
533
534    security.declareProtected(ModifyPortalContent,"getInvalidCallbackTransactions")###(
535    def getCallbacksFromLog(self,filename):
536        """fix Online Payment Transactions from Z2.log entries"""
537        import transaction
538        import random
539        from cgi import parse_qs
540        from urlparse import urlparse
541        #from pdb import set_trace
542        wftool = self.portal_workflow
543        current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S")
544        students_folder = self.portal_url.getPortalObject().campus.students
545        s = r'(?P<client_ip>\S+) - (?P<member_id>\S+) \['
546        s += r'(?P<date>.*)\] "(?P<get>.*)" (?P<codes>\d+ \d+) "'
547        s += r'(?P<intersw>.*)" "(?P<agent>.*)"'
548        data = re.compile(s)
549        start = True
550        tr_count = 1
551        total = 0
552        #name = 'pume_results'
553        #name = 'epaymentsuccessful_z2log2'
554        name = filename
555        no_import = []
556        imported = []
557        logger = logging.getLogger('WAeUPTool.getFailedTransactions')
558        try:
559            transactions = open("%s/import/%s" % (i_home,name),"rb").readlines()
560        except:
561            logger.error('Error reading %s' % name)
562            return
563        tas = []
564        for line in transactions:
565            dict = {}
566            items = data.search(line)
567            dict['idict'] = idict = items.groupdict()
568            #print idict
569            #from pdb import set_trace;set_trace()
570            urlparsed = urlparse(idict['get'][4:])
571            #print urlparsed
572            path = urlparsed[2].split('/')
573            dict['student_id'] = student_id = path[8]
574            dict['payment_id'] = payment_id = path[10]
575            dict['qs_dict'] = qs_dict = parse_qs(urlparsed[4])
576            tas.append(dict)
577            tr_count += 1
578        return tas
579    ###)
580
581    security.declareProtected(ModifyPortalContent,"importOnlinePaymentTransactions")###(
582    def importOnlinePaymentTransactions(self):
583        """load Online Payment Transactions from CSV values"""
584        import transaction
585        import random
586        #from pdb import set_trace
587        current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S")
588        opt = self.online_payments_import
589        students_folder = self.portal_url.getPortalObject().campus.students
590        start = True
591        tr_count = 1
592        total = 0
593        #name = 'pume_results'
594        name = 'OnlineTransactions'
595        no_import = []
596        imported = []
597        logger = logging.getLogger('WAeUPTool.importOnlinePaymentTransactions')
598        try:
599            transactions = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
600        except:
601            logger.error('Error reading %s.csv' % name)
602            return
603        for pay_transaction in transactions:
604            if start:
605                start = False
606                logger.info('Start loading from %s.csv' % name)
607                s = ','.join(['"%s"' % fn for fn in pay_transaction.keys()])
608                no_import.append('%s,"Error"' % s)
609                format = ','.join(['"%%(%s)s"' % fn for fn in pay_transaction.keys()])
610                format_error = format + ',"%(Error)s"'
611            data = {}
612
613            # format of the first file sent from Tayo
614            #data['datetime'] = date = DateTime.DateTime(pay_transaction['Date'])
615            #data['student_id'] = student_id = pay_transaction['Payer ID']
616            #data['order_id'] = order_id = pay_transaction['Order ID (Tranx Ref)']
617            #data['response_code'] = response_code = pay_transaction['Resp Code']
618            #data['amount'] = amount = pay_transaction['Amount']
619
620            # format of the second file sent from Tayo
621            data['datetime'] = date = 0
622            data['student_id'] = student_id = pay_transaction['Payer ID']
623            data['order_id'] = order_id = pay_transaction['Order ID (Tranx Ref)']
624            data['response_code'] = response_code = '00'
625            data['amount'] = amount = pay_transaction['Amount']
626
627            dup = False
628            if response_code == "12":
629                continue
630            try:
631                opt.addRecord(**data)
632            except ValueError:
633                dup = True
634            #from pdb import set_trace;set_trace()
635            if dup:
636                if response_code == "00":
637                    opt.modifyRecord(**data)
638                else:
639                    pay_transaction['Error'] = "Duplicate order Id"
640                    no_import.append( format_error % pay_transaction)
641                    logger.info("dupplicate order_id %(order_id)s for %(student_id)s %(response_code)s" % data)
642                    continue
643            tr_count += 1
644            if tr_count > 1000:
645                if len(no_import) > 0:
646                    open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write(
647                             '\n'.join(no_import) + '\n')
648                    no_import = []
649                em = '%d transactions committed\n' % (tr_count)
650                transaction.commit()
651                regs = []
652                logger.info(em)
653                total += tr_count
654                tr_count = 0
655        open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write(
656                                                '\n'.join(no_import))
657        return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
658    ###)
659
660InitializeClass(WAeUPTool)
Note: See TracBrowser for help on using the repository browser.