Ignore:
Timestamp:
7 Feb 2013, 09:51:37 (12 years ago)
Author:
Henrik Bettermann
Message:

Export passport file path.

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  
    1818"""Exporters for student related stuff.
    1919"""
     20import os
    2021import grok
    2122from datetime import datetime
     23from zope.component import getUtility
     24from waeup.kofa.interfaces import IExtFileStore, IFileStoreNameChooser
    2225from waeup.kofa.interfaces import MessageFactory as _
    2326from waeup.kofa.students.catalog import StudentsQuery, CourseTicketsQuery
     
    402405    #: Fieldnames considered by this exporter
    403406    fields = ('display_fullname',
    404               'matric_number',
    405               'certificate', 'faculty', 'department')
     407              'student_id','matric_number',
     408              'certificate', 'faculty', 'department', 'passport_path')
    406409
    407410    #: The title under which this exporter will be displayed
     
    416419        if name == 'faculty' and certificate is not None:
    417420            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:])
    418428        return super(
    419429            ComboCardDataExporter, self).mangle_value(
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_export.py

    r9936 r9937  
     1import os
    12import grok
    23import datetime
    3 from zope.component import queryUtility
     4from cStringIO import StringIO
     5from zope.component import queryUtility, getUtility
    46from zope.event import notify
    57from zope.interface.verify import verifyObject, verifyClass
    6 from waeup.kofa.interfaces import ICSVExporter
     8from waeup.kofa.interfaces import (
     9    ICSVExporter, IExtFileStore, IFileStoreNameChooser)
    710from waeup.kofa.students.catalog import StudentsQuery
    811from waeup.kofa.students.export import (
     
    941944        return
    942945
     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
    943955    def test_export_all(self):
    944956        self.setup_student(self.student)
     957        self.create_passport_img(self.student)
    945958        exporter = ComboCardDataExporter()
    946959        exporter.export_all(self.app, self.outfile)
    947960        result = open(self.outfile, 'rb').read()
    948961        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'
    952967            in result
    953968            )
Note: See TracChangeset for help on using the changeset viewer.