Changeset 12266 for main


Ignore:
Timestamp:
19 Dec 2014, 16:17:17 (10 years ago)
Author:
Henrik Bettermann
Message:

Add exporter tests and fix exporter.

Location:
main/waeup.ikoba/trunk/src/waeup/ikoba/documents
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/export.py

    r12249 r12266  
    2727
    2828
    29 class PDFDocumentExporter(grok.GlobalUtility, ExporterBase):
     29class DocumentExporterBase(grok.GlobalUtility, ExporterBase):
    3030    """Exporter for documents.
    3131    """
    3232    grok.implements(ICSVExporter)
    33     grok.name('pdfdocuments')
     33    grok.baseclass()
     34    class_name = None
     35    iface = None
     36    title = None
    3437
    35     #: Fieldnames considered by this exporter
    36     fields = tuple(sorted(iface_names(IPDFDocument))) + (
     38    @property
     39    def fields(self):
     40        return tuple(sorted(iface_names(self.iface))) + (
    3741        'users_with_local_roles',)
    38 
    39     #: The title under which this exporter will be displayed
    40     title = _(u'Public PDF Documents')
    4142
    4243    def mangle_value(self, value, name, context=None):
     
    4849            for local_role, user_name, setting in role_map.getPrincipalsAndRoles():
    4950                value.append({'user_name':user_name,'local_role':local_role})
    50         return super(PDFDocumentExporter, self).mangle_value(
     51        return super(DocumentExporterBase, self).mangle_value(
    5152            value, name, context)
    5253
     
    6667        If `filepath` is ``None``, a raw string with CSV data is returned.
    6768        """
    68         documents = site.get('documents', {})
    69         return self.export(documents.values(), filepath)
     69        documents = site.get('documents', {}).values()
     70        documents = [doc for doc in documents
     71                     if doc.class_name == self.class_name]
     72        return self.export(documents, filepath)
    7073
    7174
    72 class HTMLDocumentExporter(PDFDocumentExporter):
     75class PDFDocumentExporter(DocumentExporterBase):
     76    """Exporter for documents.
     77    """
     78    grok.name('pdfdocuments')
     79    iface = IPDFDocument
     80    class_name = 'PDFDocument'
     81    title = _(u'Public PDF Documents')
     82
     83
     84class HTMLDocumentExporter(DocumentExporterBase):
    7385    """Exporter for documents.
    7486    """
    7587    grok.name('htmldocuments')
    76 
    77     #: Fieldnames considered by this exporter
    78     fields = tuple(sorted(iface_names(IHTMLDocument))) + (
    79         'users_with_local_roles',)
    80 
    81     #: The title under which this exporter will be displayed
     88    iface = IHTMLDocument
     89    class_name = 'HTMLDocument'
    8290    title = _(u'Public HTML Documents')
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/tests/test_batching.py

    r12257 r12266  
    7979
    8080    def setup_for_export(self):
    81         document = PDFDocument()
    82         self.app['documents'][document.document_id] = self.document = document
     81        document1 = PDFDocument()
     82        document1.document_id = u'DOC1'
     83        self.app['documents'].addDocument(document1)
     84        self.pdfdocument = document1
    8385        self.outfile = os.path.join(self.workdir, 'myoutput.csv')
    84         role_manager = IPrincipalRoleManager(document)
     86        role_manager = IPrincipalRoleManager(document1)
     87        role_manager.assignRoleToPrincipal(u'johnsrole', u'john')
     88
     89        document2 = HTMLDocument()
     90        document2.document_id = u'DOC2'
     91        self.app['documents'].addDocument(document2)
     92        self.htmldocument = document2
     93        self.outfile = os.path.join(self.workdir, 'myoutput.csv')
     94        role_manager = IPrincipalRoleManager(document2)
    8595        role_manager.assignRoleToPrincipal(u'johnsrole', u'john')
    8696        return
Note: See TracChangeset for help on using the changeset viewer.