Changeset 3988


Ignore:
Timestamp:
28 Feb 2009, 10:17:03 (16 years ago)
Author:
Henrik Bettermann
Message:

implement payment import

PatchExtendedWidgetsCPSDateTimeWidget.py: enable import of long DateTime? strings which are exported by csv writer

Location:
WAeUP_SRP/trunk
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/trunk/Upload.py

    r3360 r3988  
    1212from Products.WAeUP_SRP.WAeUPTables import AccommodationTable,NOT_OCCUPIED
    1313from WAeUPImport import ApplicationImport,CertificateImport,CertificateCourseImport
    14 from WAeUPImport import CourseImport,CourseResultImport
     14from WAeUPImport import CourseImport,CourseResultImport,PaymentImport
    1515from WAeUPImport import DepartmentImport,FacultyImport,StudentImport,VerdictImport,StudentStudyLevelImport
    1616from WAeUPImport import NO_KEY,IGNORE
  • WAeUP_SRP/trunk/WAeUPImport.py

    r3987 r3988  
    989989                line_for_reimport.append(format_for_reimport % d)
    990990                open(reimport_file,"a").write('\n'.join(line_for_reimport) +'\n')               
    991                 self.course_results.getExportRemoveAllCourses(student_id = student_id, export = True, remove = True)
    992 #                self.course_results.getExportRemoveAllCourses(student_id = student_id, export = True, remove = False)
    993                 self.payments_catalog.getExportRemoveAllPayments(student_id = student_id, export = True, remove = True)
    994 #                self.payments_catalog.getExportRemoveAllPayments(student_id = student_id, export = True, remove = False)
     991                self.course_results.exportRemoveAllCourses(student_id = student_id, export = True, remove = True)
     992#                self.course_results.exportRemoveAllCourses(student_id = student_id, export = True, remove = False)
     993                self.payments_catalog.exportRemoveAllPayments(student_id = student_id, export = True, remove = True)
     994#                self.payments_catalog.exportRemoveAllPayments(student_id = student_id, export = True, remove = False)
    995995                self.waeup_tool.exportAllStudyLevels(student_id = student_id)
    996996                # end export
     
    11341134        "edit student levels and create StudentStudyLevel object if not existent"
    11351135        wftool = self.portal_workflow
    1136         logger = logging.getLogger('WAeUPTool.mass_create_level')
     1136        logger = logging.getLogger('WAeUPImport.StudentStudyLevelImport.create')
    11371137        students_folder = self.portal_url.getPortalObject().campus.students
    11381138        student_id = mapping.get('id',None)
     
    11771177        "edit student levels"
    11781178        wftool = self.portal_workflow
    1179         logger = logging.getLogger('WAeUPTool.mass_edit_level')
     1179        logger = logging.getLogger('WAeUPImport.StudentStudyLevelImport.edit')
    11801180        students_folder = self.portal_url.getPortalObject().campus.students
    11811181        student_id = mapping.get('id',None)
     
    12211221        "edit student verdicts and create StudentStudyLevel object if not existent"
    12221222        wftool = self.portal_workflow
    1223         logger = logging.getLogger('WAeUPTool.mass_edit_verdict')
     1223        logger = logging.getLogger('WAeUPImport.VerdictImport.create')
    12241224        students_folder = self.portal_url.getPortalObject().campus.students
    12251225        student_id = mapping.get('id',None)
     
    13101310        "edit student verdicts"
    13111311        wftool = self.portal_workflow
    1312         logger = logging.getLogger('WAeUPTool.mass_edit_verdict')
     1312        logger = logging.getLogger('WAeUPImport.VerdictImport.edit')
    13131313        students_folder = self.portal_url.getPortalObject().campus.students
    13141314        student_id = mapping.get('id',None)
     
    13891389    ###)
    13901390
    1391     def edit_old(self,mapping): ###(
    1392         "edit student verdicts"
     1391   
     1392   
     1393class PaymentImport(WAeUPImport):###(
     1394    """ PaymentImport """
     1395    name = "payment"
     1396    plural_name = "%ss" % name
     1397    commit_after = 1000000
     1398    required_modes = ('create',)
     1399
     1400    def create(self,mapping): ###(
     1401        "create payment object"
    13931402        wftool = self.portal_workflow
    1394         logger = logging.getLogger('WAeUPTool.mass_edit_verdict')
     1403        logger = logging.getLogger('WAeUPImport.PaymentImport.create')
    13951404        students_folder = self.portal_url.getPortalObject().campus.students
    13961405        student_id = mapping.get('id',None)
    1397         matric_no = mapping.get('matric_no',None)
     1406        order_id = key= mapping.get('order_id',None)
     1407        payment_type = mapping.get('type',None)
    13981408        editable_keys = mapping.keys()
    13991409        key = ''
    1400         while True:
    1401             msg = ''
    1402             if student_id:
    1403                 student_record = self.students_catalog.getRecordByKey(student_id)
    1404                 if student_record is None:
    1405                     #return '',"no student with id %s" % student_id
    1406                     msg = "no student with id %s" % student_id
     1410        msg = ''
     1411        while True:
     1412            result = self.findStudent('create',student_id=student_id)
     1413            msg = result['msg']
     1414            if msg:
     1415                break           
     1416            if payment_type == 'sc':
     1417                hyphen = order_id.rfind('-')
     1418                if not hyphen > -1:
     1419                    msg = '%s: wrong order_id of sc payment' % student_id
    14071420                    break
    1408                 if matric_no and student_record.matric_no and matric_no != student_record.matric_no:
    1409                     msg = 'student %s: matric_no %s does not match %s' % (student_record.id,
    1410                                                                           student_record.matric_no,
    1411                                                                           matric_no)
    1412                     break
    1413                 mapping['matric_no'] = student_record.matric_no
    1414             elif matric_no:
    1415                 res = self.students_catalog(matric_no = matric_no)
    1416                 if not res:
    1417                     msg = "no student with matric_no %s" % matric_no
    1418                     break
    1419                 student_record = res[0]
    1420                 editable_keys.remove('matric_no')
     1421                payment_object_id = 'p' + order_id[hyphen+1:]
     1422            elif payment_type == 'online':
     1423                payment_object_id = 'p' + order_id[6:]
    14211424            else:
    1422                 msg = "no id or matric_no specified"
    1423                 break
     1425                msg = '%s: no payment type defined' % student_id
     1426                break
     1427            student_record = result['student_record']
    14241428            student_id = student_record.id
     1429
    14251430            mapping['id'] = student_id
    1426             d = {}
    1427             #import pdb;pdb.set_trace()
    1428             any_change = False
    1429             #special treatment for StudentStudyLevel
    1430             current_session = d['session'] = mapping.get('current_session','')
    1431             if current_session and student_record.session != current_session:
    1432                 msg = 'student %s: imported session %s does not match current_session %s' % (student_id,
    1433                                                                                             current_session,
    1434                                                                                             student_record.session)
    1435                 break
    1436             current_level = mapping.get('current_level','')
    1437             if not current_level.isdigit():
    1438                 msg = 'student %s: imported level is empty' % (student_id,)
    1439                 break
    1440             if current_level and student_record.level != current_level:
    1441                 msg = 'student %s: imported level %s does not match current_level %s' % (student_id,
    1442                                                                                         current_level,
    1443                                                                                         student_record.level)
    1444                 break
    1445             student_review_state =  student_record.review_state
    1446             if student_review_state == 'deactivated':
    1447                 msg = "student %s in review_state %s" % (student_id, student_review_state)
    1448                 break
    1449             if student_review_state not in ('courses_validated','returning'):
    1450                 msg = "student %s in wrong review_state %s" % (student_id, student_review_state)
    1451                 break
    1452             student_obj = getattr(students_folder,student_id)
    1453             # f2t = self.field2types_student
    1454             study_course_obj = getattr(student_obj,'study_course',None)
    1455             if study_course_obj is None:
    1456                 msg = 'student %s: no study_course object' % student_id
    1457                 break
    1458             level_obj = getattr(study_course_obj,current_level,None)
    1459             if  level_obj is None:
    1460                 msg = 'student %s: no study_level object for level %s' % (student_id,
    1461                                                                                 current_level)
    1462                 break
    1463             verdict = d['verdict'] = d['current_verdict']  = mapping.get('current_verdict','')
    1464 
    1465             #if verdict == student_record.verdict:
    1466             #    msg = 'student %s: verdict already set to %s' % (student_id,
    1467             #                                                            verdict)
    1468 
    1469             level_review_state = wftool.getInfoFor(level_obj,'review_state',None)
    1470             if level_review_state != "closed":
    1471                 wftool.doActionFor(level_obj,'close')
    1472                 # msg = 'student %s: level %s is not closed' % (student_id,
    1473                 #                                                      current_level)
    1474 
    1475             study_course_obj.getContent().edit(mapping = d)
    1476             level_obj.getContent().edit(mapping = d)
    1477             if student_review_state != "returning":
    1478                 wftool.doActionFor(student_obj,'return')
    1479             # try:
    1480             #     wftool.doActionFor(level_obj,'close')
    1481             # except:
    1482             #     pass
    1483             break
    1484         return student_id,msg,mapping
    1485     ###)
     1431            payments_folder = getattr(getattr(students_folder,student_id),'payments',None)
     1432            if payments_folder is None:
     1433                msg = '%s: no payments folder' % student_id
     1434                break
     1435            if getattr(payments_folder,payment_object_id,False):
     1436                msg = '%s: payment object with id %s exists' % (student_id,payment_object_id)
     1437                break
     1438            try:
     1439                #import pdb;pdb.set_trace()
     1440                payments_folder.invokeFactory('Payment',"%s" % payment_object_id)
     1441                payment_obj = getattr(payments_folder,"%s" % payment_object_id)
     1442            except:
     1443                msg = '%s: payment object %s cannot be created' % (student_id,payment_object_id)
     1444                break
     1445            payment_obj.getContent().edit(mapping = mapping)
     1446            wftool.doActionFor(payment_obj,'close')
     1447            break
     1448        return key,msg,mapping
     1449    ###)
     1450   
     1451   
    14861452###)
  • WAeUP_SRP/trunk/WAeUPTables.py

    r3984 r3988  
    16681668    ###)
    16691669   
    1670     def getExportRemoveAllCourses(self,student_id,export=False,remove=False): ###(
     1670    def exportRemoveAllCourses(self,student_id,export=False,remove=False): ###(
    16711671        ""
    16721672        query = Eq('student_id',student_id)
     
    17971797
    17981798
    1799     def getExportRemoveAllPayments(self,student_id,export=False,remove=False): ###(
     1799    def exportRemoveAllPayments(self,student_id,export=False,remove=False): ###(
    18001800        ""
    18011801        query = Eq('student_id',student_id)
  • WAeUP_SRP/trunk/WAeUPTool.py

    r3984 r3988  
    4444from Globals import package_home,INSTANCE_HOME
    4545from WAeUPImport import ApplicationImport,CertificateImport,CertificateCourseImport
    46 from WAeUPImport import CourseImport,CourseResultImport,StudentStudyLevelImport
     46from WAeUPImport import CourseImport,CourseResultImport,StudentStudyLevelImport,PaymentImport
    4747from WAeUPImport import DepartmentImport,FacultyImport,StudentImport,VerdictImport
    4848from utils import makeDigest
  • WAeUP_SRP/trunk/patches/PatchExtendedWidgetsCPSDateTimeWidget.py

    r3673 r3988  
    1010    field_id = self.fields[0]
    1111    widget_id = self.getWidgetId()
    12     if datastructure.has_key(widget_id + '_date'):
    13         date = datastructure[widget_id + '_date'].strip()
    14     else:
    15         date = datastructure[widget_id].strip()
    16     if datastructure.has_key(widget_id + '_hour'):
    17         hour = datastructure[widget_id + '_hour'].strip()
    18     else:
    19         hour = self.time_hour_default
    20     if datastructure.has_key(widget_id + '_minute'):
    21         minute = datastructure[widget_id + '_minute'].strip()
    22     else:
    23         minute = self.time_minutes_default
    24 
    25     if not (date):
    26         if self.is_required:
    27             datastructure[widget_id] = ''
    28             datastructure.setError(widget_id, 'cpsschemas_err_required')
    29             return 0
    30         else:
    31             datamodel[field_id] = None
    32             return 1
    33     #import pdb;pdb.set_trace()
    34     if self.view_format.startswith('iso8601'):
    35         if re.match(r'^[0-9]+-[0-9]{2}-[0-9]{2}', date) is not None:
    36             y, m, d = date.split('-')
    37         else:
     12   
     13    if self.view_format == 'import':
     14        try:
     15            dt = datastructure[widget_id].strip()
     16            date,time,dummy = dt.split()
     17            y,m,d = date.split('/')
     18            hour,minute,second = time.split(':')
     19        except:
    3820            datastructure.setError(widget_id, 'cpsschemas_err_date')
    3921            return 0
     22        if not (date):
     23            if self.is_required:
     24                datastructure[widget_id] = ''
     25                datastructure.setError(widget_id, 'cpsschemas_err_required')
     26                return 0
     27            else:
     28                datamodel[field_id] = None
     29                return 1
    4030    else:
    41         if re.match(r'^[0-9]?[0-9][/,\-,\.][0-9]?[0-9][/,\-,\.][0-9]{2,4}$', date) is not None:
    42             d, m, y = re.split(r'[/,\-,\.]',date) # always use d/m/y and use /,- or . as separator
    43             #d, m, y = date.split('/') # always use d/m/y
    44             # locale = self.translation_service.getSelectedLanguage()
    45             # if False and locale in ('en', 'hu'):
    46             #     m, d, y = date.split('/')
    47             # else:
     31        if datastructure.has_key(widget_id + '_date'):
     32            date = datastructure[widget_id + '_date'].strip()
    4833        else:
    49             datastructure.setError(widget_id, 'cpsschemas_err_date')
    50             return 0
     34            date = datastructure[widget_id].strip()
     35        if datastructure.has_key(widget_id + '_hour'):
     36            hour = datastructure[widget_id + '_hour'].strip()
     37        else:
     38            hour = self.time_hour_default
     39        if datastructure.has_key(widget_id + '_minute'):
     40            minute = datastructure[widget_id + '_minute'].strip()
     41        else:
     42            minute = self.time_minutes_default
     43
     44        if not (date):
     45            if self.is_required:
     46                datastructure[widget_id] = ''
     47                datastructure.setError(widget_id, 'cpsschemas_err_required')
     48                return 0
     49            else:
     50                datamodel[field_id] = None
     51                return 1
     52               
     53        #import pdb;pdb.set_trace()
     54        if self.view_format.startswith('iso8601'):
     55            if re.match(r'^[0-9]+-[0-9]{2}-[0-9]{2}', date) is not None:
     56                y, m, d = date.split('-')
     57            else:
     58                datastructure.setError(widget_id, 'cpsschemas_err_date')
     59                return 0
     60        else:
     61            if re.match(r'^[0-9]?[0-9][/,\-,\.][0-9]?[0-9][/,\-,\.][0-9]{2,4}$', date) is not None:
     62                d, m, y = re.split(r'[/,\-,\.]',date) # always use d/m/y and use /,- or . as separator
     63                #d, m, y = date.split('/') # always use d/m/y
     64                # locale = self.translation_service.getSelectedLanguage()
     65                # if False and locale in ('en', 'hu'):
     66                #     m, d, y = date.split('/')
     67                # else:
     68            else:
     69                datastructure.setError(widget_id, 'cpsschemas_err_date')
     70                return 0
    5171
    5272    try:
  • WAeUP_SRP/trunk/profiles/default/layouts.xml

    r3858 r3988  
    7979  <object name="import_verdict" meta_type="CPS Layout"/>
    8080  <object name="import_student_study_level" meta_type="CPS Layout"/>
     81  <object name="import_payment" meta_type="CPS Layout"/>
    8182
    8283  <object name="department" meta_type="CPS Layout"/>
  • WAeUP_SRP/trunk/profiles/default/layouts/import_student.xml

    r3987 r3988  
    245245 </widget>
    246246 
    247  <widget name="app_ac_date" meta_type="String Widget">
     247 <widget name="app_ac_date" meta_type="DateTime Widget">
    248248  <property name="fields">
    249249   <element value="app_ac_date"/>
    250250  </property>
    251  </widget>
     251  <property name="view_format">import</property>
     252 </widget>
    252253 
    253254 <widget name="app_mobile" meta_type="String Widget">
     
    257258 </widget>
    258259 
    259  <widget name="request_date" meta_type="String Widget">
     260 <widget name="request_date" meta_type="DateTime Widget">
    260261  <property name="fields">
    261262   <element value="request_date"/>
    262263  </property>
     264  <property name="view_format">import</property>
    263265 </widget>
    264266 
     
    269271 </widget>
    270272 
    271  <widget name="cleared_date" meta_type="String Widget">
     273 <widget name="cleared_date" meta_type="DateTime Widget">
    272274  <property name="fields">
    273275   <element value="cleared_date"/>
    274276  </property>
     277  <property name="view_format">import</property>
    275278 </widget>
    276279 
  • WAeUP_SRP/trunk/profiles/default/schemas.xml

    r3858 r3988  
    6161 <object name="import_verdict" meta_type="CPS Schema"/>
    6262 <object name="import_student_study_level" meta_type="CPS Schema"/>
     63 <object name="import_payment" meta_type="CPS Schema"/>
    6364
    6465 <object name="course" meta_type="CPS Schema"/>
  • WAeUP_SRP/trunk/profiles/default/vocabularies/import_names.xml

    r3689 r3988  
    1616 <item key="certificate" msgid="">Certificate Data</item>
    1717 <item key="certificate_course" msgid="">Certificate Course Data</item>
     18 <item key="payment" msgid="">Payment Data</item>
    1819</object>
  • WAeUP_SRP/trunk/skins/waeup_epayment/payment_receipt.pt

    r3310 r3988  
    112112        <tr>       
    113113          <td width="220px">Transaction Date:</td>
    114           <td><span tal:content="python:pm.date.ISO()" /></td>
     114          <td><span tal:content='python:pm.date.strftime("%d/%m/%y %H:%M:%S")' /></td>
    115115        </tr>       
    116116        <tr>
Note: See TracChangeset for help on using the changeset viewer.