Changeset 12006


Ignore:
Timestamp:
20 Nov 2014, 08:32:17 (10 years ago)
Author:
Henrik Bettermann
Message:

Add customer documents exporter.

Location:
main/waeup.ikoba/trunk/src/waeup/ikoba
Files:
5 edited

Legend:

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

    r11949 r12006  
    124124            if idx_name == 'catalog':
    125125                continue
    126             if value is not None:
    127                 if 'session' in idx_name or 'level' in idx_name:
    128                     value = int(value)
    129                 if idx_name in ('level', 'current_level'):
    130                     value = int(value)
    131                     if value not in (10, 999):
    132                         value = (value, value + 90)
    133126            if not isinstance(value, tuple):
    134127                value = (value, value)
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/catalog.py

    r11997 r12006  
    1 ## $Id: catalog.py 10465 2013-08-07 11:18:43Z henrik $
     1## $Id$
    22##
    33## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/export.py

    r11997 r12006  
    1 ## $Id: export.py 11757 2014-07-10 12:20:30Z henrik $
     1## $Id$
    22##
    33## Copyright (C) 2014 Uli Fouquet & Henrik Bettermann
     
    2727from waeup.ikoba.customers.catalog import CustomersQuery
    2828from waeup.ikoba.customers.interfaces import (
    29     ICustomer, ICSVCustomerExporter)
     29    ICustomer, ICSVCustomerExporter, ICustomerDocument)
    3030from waeup.ikoba.utils.batching import ExporterBase
    3131from waeup.ikoba.utils.helpers import iface_names, to_timezone
     
    3333#: A tuple containing all exporter names referring to customers or
    3434#: subobjects thereof.
    35 EXPORTER_NAMES = ('customers', )
     35EXPORTER_NAMES = ('customers', 'customerdocuments')
    3636
    3737
     
    4040    """
    4141    return cust_filter.query()
     42
     43def get_documents(customers):
     44    """Get all documents of `customers`.
     45    """
     46    documents = []
     47    for customer in customers:
     48        for document in customer.get('documents', {}).values():
     49            documents.append(document)
     50    return documents
    4251
    4352
     
    127136            CustomersExporter, self).mangle_value(
    128137            value, name, context=context)
     138
     139class CustomerDocumentsExporter(grok.GlobalUtility, CustomerExporterBase):
     140    """Exporter for CustomerDocument instances.
     141    """
     142    grok.name('customerdocuments')
     143
     144    #: Fieldnames considered by this exporter
     145    fields = tuple(
     146        sorted(iface_names(
     147            ICustomerDocument, exclude_attribs=False))) + (
     148            'customer_id',)
     149
     150    #: The title under which this exporter will be displayed
     151    title = _(u'Customer Documents')
     152
     153    def filter_func(self, x, **kw):
     154        return get_documents(x, **kw)
     155
     156    def mangle_value(self, value, name, context=None):
     157        """Treat location values special.
     158        """
     159        if context is not None:
     160            customer = context.customer
     161            if name in ('customer_id',) and customer is not None:
     162                value = getattr(customer, name, None)
     163        return super(
     164            CustomerDocumentsExporter, self).mangle_value(
     165            value, name, context=context)
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_batching.py

    r12005 r12006  
    3838    CustomerProcessor, CustomerDocumentProcessor)
    3939from waeup.ikoba.customers.customer import Customer
     40from waeup.ikoba.customers.documents import CustomerDocument
    4041from waeup.ikoba.testing import FunctionalLayer, FunctionalTestCase
    4142
     
    116117        customer.nationality = u'NG'
    117118
     119        document = CustomerDocument()
     120        document.title = u'My Document'
     121        customer['documents'].addDocument(document)
    118122        return customer
    119123
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_customer.py

    r11997 r12006  
    1 ## $Id: test_customer.py 10059 2013-04-05 08:11:29Z henrik $
     1## $Id$
    22##
    33## Copyright (C) 2014 Uli Fouquet & Henrik Bettermann
Note: See TracChangeset for help on using the changeset viewer.