Changeset 8884 for main/waeup.kofa/trunk/src/waeup
- Timestamp:
- 3 Jul 2012, 07:13:59 (12 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/applicants/utils.py
r8664 r8884 45 45 """Set the payment data of an applicant. 46 46 """ 47 timestamp = "%d" % int(time()*1000)47 timestamp = ("%d" % int(time()*10000))[1:] 48 48 container_fee = container.application_fee 49 49 if container_fee: -
main/waeup.kofa/trunk/src/waeup/kofa/students/batching.py
r8736 r8884 26 26 import grok 27 27 import csv 28 from time import time 28 29 from zope.interface import Interface 29 30 from zope.schema import getFields … … 291 292 grok.baseclass() 292 293 293 #: required fields beside 'student_id', 'reg_number' and 'matric_number' 294 # additional available fields 295 # beside 'student_id', 'reg_number' and 'matric_number' 294 296 additional_fields = [] 295 297 296 #: header fields additional required298 #: header fields additionally required 297 299 additional_headers = [] 298 300 … … 558 560 location_fields = [] 559 561 additional_fields = ['p_id'] 560 additional_headers = ['p_id'] 562 additional_headers = [] 563 564 def checkHeaders(self, headerfields, mode='ignore'): 565 super(StudentOnlinePaymentProcessor, self).checkHeaders(headerfields) 566 if mode == 'update' and not 'p_id' in headerfields: 567 raise FatalCSVError( 568 "Need p_id for import in update mode!") 569 return True 561 570 562 571 def parentsExist(self, row, site): … … 573 582 if payments is None: 574 583 return None 584 p_id = row.get('p_id', None) 585 if p_id is None: 586 return None 575 587 # We can use the hash symbol at the end of p_id in import files 576 588 # to avoid annoying automatic number transformation 577 589 # by Excel or Calc 578 p_id = row['p_id'].strip('#') 579 if p_id.startswith('p'): 580 entry = payments.get(p_id) 581 else: 582 # For data migration from old SRP 583 entry = payments.get('p' + p_id[6:]) 590 p_id = p_id.strip('#') 591 if not p_id.startswith('p'): 592 # For data migration from old SRP only 593 p_id = 'p' + p_id[7:] + '0' 594 entry = payments.get(p_id) 584 595 return entry 585 596 … … 600 611 if not p_id.startswith('p'): 601 612 # For data migration from old SRP 602 obj.p_id = 'p' + p_id[ 6:]613 obj.p_id = 'p' + p_id[7:] + '0' 603 614 parent[obj.p_id] = obj 604 615 else: … … 613 624 614 625 # We have to check p_id. 615 p_id = row['p_id'].strip('#') 626 p_id = row.get('p_id', None) 627 if p_id is None: 628 timestamp = ("%d" % int(time()*10000))[1:] 629 p_id = "p%s" % timestamp 630 conv_dict['p_id'] = p_id 631 return errs, inv_errs, conv_dict 632 else: 633 p_id = p_id.strip('#') 616 634 if p_id.startswith('p'): 617 635 if not len(p_id) == 14: -
main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_batching.py
r8626 r8884 124 124 125 125 PAYMENT_HEADER_FIELDS = PAYMENT_SAMPLE_DATA.split( 126 '\n')[0].split(',') 127 128 PAYMENT_CREATE_SAMPLE_DATA = open( 129 os.path.join(os.path.dirname(__file__), 'sample_create_payment_data.csv'), 130 'rb').read() 131 132 PAYMENT_CREATE_HEADER_FIELDS = PAYMENT_CREATE_SAMPLE_DATA.split( 126 133 '\n')[0].split(',') 127 134 … … 784 791 self.student = self.app['students'][student.student_id] 785 792 payment = createObject(u'waeup.StudentOnlinePayment') 786 payment.p_id = 'p12 3'793 payment.p_id = 'p120' 787 794 self.student['payments'][payment.p_id] = payment 788 795 … … 798 805 self.workdir, 'sample_payment_data.csv') 799 806 open(self.csv_file, 'wb').write(PAYMENT_SAMPLE_DATA) 807 self.csv_file2 = os.path.join( 808 self.workdir, 'sample_create_payment_data.csv') 809 open(self.csv_file2, 'wb').write(PAYMENT_CREATE_SAMPLE_DATA) 800 810 801 811 def test_interface(self): … … 809 819 dict(student_id='ID_NONE', p_id='nonsense'), self.app) is None 810 820 assert self.processor.getEntry( 811 dict(student_id=self.student.student_id, p_id='p12 3'),812 self.app) is self.student['payments']['p12 3']821 dict(student_id=self.student.student_id, p_id='p120'), 822 self.app) is self.student['payments']['p120'] 813 823 assert self.processor.getEntry( 814 dict(student_id=self.student.student_id, p_id='XXXXXX1 23'),815 self.app) is self.student['payments']['p12 3']824 dict(student_id=self.student.student_id, p_id='XXXXXX112'), 825 self.app) is self.student['payments']['p120'] 816 826 817 827 def test_addEntry(self): … … 831 841 self.app) 832 842 self.assertEqual(len(self.student['payments'].keys()),3) 833 self.assertEqual(self.student['payments']['p 456'].p_id, 'p456')843 self.assertEqual(self.student['payments']['p560'].p_id, 'p560') 834 844 835 845 def test_checkConversion(self): 836 846 errs, inv_errs, conv_dict = self.processor.checkConversion( 837 dict( reg_number='1',p_id='3816951266236341955'))847 dict(p_id='3816951266236341955')) 838 848 self.assertEqual(len(errs),0) 839 849 errs, inv_errs, conv_dict = self.processor.checkConversion( 840 dict( reg_number='1',p_id='p1266236341955'))850 dict(p_id='p1266236341955')) 841 851 self.assertEqual(len(errs),0) 842 852 errs, inv_errs, conv_dict = self.processor.checkConversion( 843 dict( reg_number='1',p_id='nonsense'))853 dict(p_id='nonsense')) 844 854 self.assertEqual(len(errs),1) 845 timestamp = "%d" % int(time()*1000)855 timestamp = ("%d" % int(time()*10000))[1:] 846 856 p_id = "p%s" % timestamp 847 857 errs, inv_errs, conv_dict = self.processor.checkConversion( 848 dict( reg_number='1',p_id=p_id))858 dict(p_id=p_id)) 849 859 self.assertEqual(len(errs),0) 850 860 … … 854 864 self.assertEqual(num_warns,0) 855 865 payment = self.processor.getEntry(dict(reg_number='1', 856 p_id='p 1290797973744'), self.app)857 self.assertEqual(payment.p_id, 'p 1290797973744')866 p_id='p2907979737440'), self.app) 867 self.assertEqual(payment.p_id, 'p2907979737440') 858 868 cdate = payment.creation_date.strftime("%Y-%m-%d %H:%M:%S") 859 869 self.assertEqual(cdate, "2010-11-26 18:59:33") … … 881 891 self.assertEqual(num_warns,0) 882 892 shutil.rmtree(os.path.dirname(fin_file)) 893 894 def test_import_wo_pid(self): 895 num, num_warns, fin_file, fail_file = self.processor.doImport( 896 self.csv_file2, PAYMENT_CREATE_HEADER_FIELDS,'create') 897 self.assertEqual(num_warns,0) 898 shutil.rmtree(os.path.dirname(fin_file)) 899 self.assertEqual(len(self.app['students']['X666666']['payments']), 50) 900 883 901 884 902 def test_suite():
Note: See TracChangeset for help on using the changeset viewer.