- Timestamp:
- 7 Feb 2013, 09:51:37 (12 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/students
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/students/export.py
r9936 r9937 18 18 """Exporters for student related stuff. 19 19 """ 20 import os 20 21 import grok 21 22 from datetime import datetime 23 from zope.component import getUtility 24 from waeup.kofa.interfaces import IExtFileStore, IFileStoreNameChooser 22 25 from waeup.kofa.interfaces import MessageFactory as _ 23 26 from waeup.kofa.students.catalog import StudentsQuery, CourseTicketsQuery … … 402 405 #: Fieldnames considered by this exporter 403 406 fields = ('display_fullname', 404 ' matric_number',405 'certificate', 'faculty', 'department' )407 'student_id','matric_number', 408 'certificate', 'faculty', 'department', 'passport_path') 406 409 407 410 #: The title under which this exporter will be displayed … … 416 419 if name == 'faculty' and certificate is not None: 417 420 value = certificate.__parent__.__parent__.__parent__.longtitle() 421 if name == 'passport_path' and certificate is not None: 422 file_id = IFileStoreNameChooser(context).chooseName(attr='passport.jpg') 423 os_path = getUtility(IExtFileStore)._pathFromFileID(file_id) 424 if not os.path.exists(os_path): 425 value = None 426 else: 427 value = '/'.join(os_path.split('/')[-4:]) 418 428 return super( 419 429 ComboCardDataExporter, self).mangle_value( -
main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_export.py
r9936 r9937 1 import os 1 2 import grok 2 3 import datetime 3 from zope.component import queryUtility 4 from cStringIO import StringIO 5 from zope.component import queryUtility, getUtility 4 6 from zope.event import notify 5 7 from zope.interface.verify import verifyObject, verifyClass 6 from waeup.kofa.interfaces import ICSVExporter 8 from waeup.kofa.interfaces import ( 9 ICSVExporter, IExtFileStore, IFileStoreNameChooser) 7 10 from waeup.kofa.students.catalog import StudentsQuery 8 11 from waeup.kofa.students.export import ( … … 941 944 return 942 945 946 def create_passport_img(self, student): 947 # create some passport file for `student` 948 storage = getUtility(IExtFileStore) 949 image_path = os.path.join(os.path.dirname(__file__), 'test_image.jpg') 950 self.image_contents = open(image_path, 'rb').read() 951 file_id = IFileStoreNameChooser(student).chooseName( 952 attr='passport.jpg') 953 storage.createFile(file_id, StringIO(self.image_contents)) 954 943 955 def test_export_all(self): 944 956 self.setup_student(self.student) 957 self.create_passport_img(self.student) 945 958 exporter = ComboCardDataExporter() 946 959 exporter.export_all(self.app, self.outfile) 947 960 result = open(self.outfile, 'rb').read() 948 961 self.assertTrue( 949 'display_fullname,matric_number,certificate,faculty,department\r\n' 950 'Anna M. Tester,234,Unnamed Certificate,Faculty of Unnamed ' 951 'Faculty (NA),Department of Unnamed Department (NA)' 962 'display_fullname,student_id,matric_number,certificate,faculty,' 963 'department,passport_path\r\nAnna M. Tester,A111111,234,' 964 'Unnamed Certificate,Faculty of Unnamed Faculty (NA),' 965 'Department of Unnamed Department (NA),' 966 'students/00110/A111111/passport_A111111.jpg\r\n' 952 967 in result 953 968 )
Note: See TracChangeset for help on using the changeset viewer.