Changeset 12053


Ignore:
Timestamp:
25 Nov 2014, 08:19:54 (10 years ago)
Author:
Henrik Bettermann
Message:

Add second customer document class.
Select document factory when adding documents.
Add last_transition_date attribute and further property attributes to documents.

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

Legend:

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

    r12052 r12053  
    3939    IkobaPage, IkobaEditFormPage, IkobaAddFormPage, IkobaDisplayFormPage,
    4040    IkobaForm, NullValidator, jsaction, action, UtilityView)
     41from waeup.ikoba.widgets.datewidget import (
     42    FriendlyDateWidget, FriendlyDateDisplayWidget,
     43    FriendlyDatetimeDisplayWidget)
    4144from waeup.ikoba.browser.pages import ContactAdminForm
    4245from waeup.ikoba.browser.breadcrumbs import Breadcrumb
     
    796799    @property
    797800    def selectable_doctypes(self):
    798         doctypes = getUtility(IIkobaUtils).DOCUMENT_TYPES
     801        doctypes = getUtility(ICustomersUtils).SELECTABLE_DOCTYPES_DICT
    799802        return sorted(doctypes.items())
    800803
     
    806809        # Here we can create various instances of CustomerDocument derived
    807810        # classes depending on the doctype parameter given in form.
    808         # So far we only have one CustomerDocument class and no derived
    809         # classes.
    810         document = createObject(u'waeup.CustomerDocument')
     811        document = createObject('waeup.%s' % doctype)
    811812        self.context.addDocument(document)
    812         doctype = getUtility(IIkobaUtils).DOCUMENT_TYPES[doctype]
     813        doctype = getUtility(ICustomersUtils).SELECTABLE_DOCTYPES_DICT[doctype]
    813814        self.flash(_('${a} created.',
    814815            mapping = {'a': doctype}))
     
    831832    grok.template('documentpage')
    832833    form_fields = grok.AutoFields(ICustomerDocument)
     834    form_fields[
     835        'last_transition_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
    833836    pnav = 4
    834837
     
    851854    grok.require('waeup.manageCustomer')
    852855    grok.template('documenteditpage')
    853     form_fields = grok.AutoFields(ICustomerDocument)
     856    form_fields = grok.AutoFields(ICustomerDocument).omit('last_transition_date')
    854857    pnav = 4
    855858    deletion_warning = _('Are you sure?')
     
    960963    def render(self):
    961964        portal_language = getUtility(IIkobaUtils).PORTAL_LANGUAGE
    962         Id = translate(_('Document Id'), 'waeup.ikoba', target_language=portal_language)
     965        Id = translate(_('Id'), 'waeup.ikoba', target_language=portal_language)
    963966        Title = translate(_('Title'), 'waeup.ikoba', target_language=portal_language)
     967        Type = translate(_('Type'), 'waeup.ikoba', target_language=portal_language)
    964968        State = translate(_('State'), 'waeup.ikoba', target_language=portal_language)
     969        LT = translate(_('Last Transition'), 'waeup.ikoba', target_language=portal_language)
     970        tableheader = []
    965971        tabledata = []
    966         tableheader = []
    967972        contenttitle = []
    968973        for i in range(1,3):
    969974            tabledata.append(sorted(
    970975                [value for value in self.context['documents'].values()]))
    971             tableheader.append([(Id, 'document_id', 3),
    972                              (Title, 'title', 8),
    973                              (State, 'translated_state', 3),
     976            tableheader.append([(Id, 'document_id', 2),
     977                             (Title, 'title', 6),
     978                             (Type, 'translated_classname', 6),
     979                             (State, 'translated_state', 2),
     980                             (LT, 'formatted_transition_date', 3),
    974981                             ])
    975982        customerview = CustomerBasePDFFormPage(self.context,
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/browser_templates/documentsmanagepage.pt

    r12016 r12053  
    88      <th i18n:translate="">Document Id</th>
    99      <th i18n:translate="">Title</th>
     10      <th i18n:translate="">Type</th>
     11      <th i18n:translate="">State</th>
     12      <th i18n:translate="">Last Transition</th>
    1013    </tr>
    1114    </thead>
     
    2528          <span tal:content="cl/title">TITLE</span>
    2629        </td>
     30        <td>
     31          <span tal:content="cl/translated_classname">CLASSNAME</span>
     32        </td>
     33        <td>
     34          <span tal:content="cl/translated_state">STATE</span>
     35        </td>
     36        <td>
     37          <span tal:content="cl/formatted_transition_date">
     38              LASTTRANSITIONDATE
     39          </span>
     40        </td>
    2741      </tr>
    2842    </tbody>
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/documents.py

    r12035 r12053  
    3333from waeup.ikoba.customers.interfaces import (
    3434    ICustomerDocumentsContainer, ICustomerNavigation, ICustomerDocument,
    35     ICustomersUtils)
     35    ICustomersUtils, ICustomerPDFDocument)
    3636from waeup.ikoba.documents import DocumentsContainer, Document
    3737from waeup.ikoba.documents.interfaces import IDocumentsUtils
     
    6060
    6161class CustomerDocument(Document):
    62     """This is an document.
     62    """This is a customer document.
    6363    """
    6464    grok.implements(ICustomerDocument, ICustomerNavigation)
     
    9494        return True
    9595
     96    @property
     97    def translated_classname(self):
     98        try:
     99            DOCTYPES_DICT = getUtility(ICustomersUtils).DOCTYPES_DICT
     100            return DOCTYPES_DICT[self.classname]
     101        except KeyError:
     102            return
     103
    96104CustomerDocument = attrs_to_fields(CustomerDocument)
     105
     106class CustomerPDFDocument(CustomerDocument):
     107    """This is a customer document for a single pdf upload file only.
     108    """
     109    grok.implements(ICustomerPDFDocument, ICustomerNavigation)
     110    grok.provides(ICustomerPDFDocument)
     111
     112CustomerPDFDocument = attrs_to_fields(CustomerPDFDocument)
    97113
    98114
     
    104120    grok.name(u'waeup.CustomerDocument')
    105121    title = u"Create a new document.",
    106     description = u"This factory instantiates new document instances."
     122    description = u"This factory instantiates new sample document instances."
    107123
    108124    def __call__(self, *args, **kw):
     
    111127    def getInterfaces(self):
    112128        return implementedBy(CustomerDocument)
     129
     130# Customer documents must be importable. So we might need a factory.
     131class CustomerPDFDocumentFactory(grok.GlobalUtility):
     132    """A factory for customer pdf documents.
     133    """
     134    grok.implements(IFactory)
     135    grok.name(u'waeup.CustomerPDFDocument')
     136    title = u"Create a new document.",
     137    description = u"This factory instantiates new pdf document instances."
     138
     139    def __call__(self, *args, **kw):
     140        return CustomerPDFDocument(*args, **kw)
     141
     142    def getInterfaces(self):
     143        return implementedBy(CustomerPDFDocument)
    113144
    114145#: The file id marker for customer files
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/export.py

    r12032 r12053  
    147147            ICustomerDocument,
    148148            exclude_attribs=False,
    149             omit=['is_editable', 'translated_state']))) + (
     149            omit=['is_editable',
     150                  'translated_state',
     151                  'formatted_transition_date',
     152                  'translated_classname']))) + (
    150153            'customer_id',)
    151154
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/interfaces.py

    r12039 r12053  
    270270
    271271    is_editable = Attribute('Document editable by customer')
     272    translated_classname = Attribute('Translatable classname')
     273
     274
     275class ICustomerPDFDocument(IDocument):
     276    """A customer document.
     277
     278    """
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_browser.py

    r12051 r12053  
    812812        self.browser.getLink("Documents").click()
    813813        self.browser.getLink("Add document").click()
    814         self.browser.getControl(name="doctype").value = ['sample']
     814        self.browser.getControl(name="doctype").value = ['CustomerPDFDocument']
    815815        self.browser.getControl("Create document").click()
    816         self.assertTrue('Sample Document created.' in self.browser.contents)
     816        self.assertTrue('PDF Document created.' in self.browser.contents)
    817817        document = self.customer['documents']['d102']
    818818
     
    853853        self.assertTrue(
    854854            'INFO - zope.mgr - customers.browser.DocumentAddFormPage '
    855             '- K1000000 - added: Sample Document %s'
     855            '- K1000000 - added: PDF Document %s'
    856856            % document.document_id in logcontent)
    857857
     
    871871        self.browser.getLink("Documents").click()
    872872        self.browser.getLink("Add document").click()
    873         self.browser.getControl(name="doctype").value = ['sample']
     873        self.browser.getControl(name="doctype").value = ['CustomerDocument']
    874874        self.browser.getControl("Create document").click()
    875875        self.assertTrue('Sample Document created.' in self.browser.contents)
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_document.py

    r12004 r12053  
    6161        self.assertEqual(container[id], document)
    6262        self.assertRaises(TypeError, container.addDocument, object())
     63        self.assertEqual(document.classname, 'CustomerDocument')
    6364        return
    6465
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_export.py

    r12017 r12053  
    138138        self.assertEqual(
    139139            result,
    140             'document_id,history,state,title,customer_id\r\n'
    141             'd101,[],,,\r\n'
     140            'classname,document_id,history,last_transition_date,state,title,customer_id\r\n'
     141            'CustomerDocument,d101,[],,,,\r\n'
    142142            )
    143143        return
     
    152152        result = open(self.outfile, 'rb').read()
    153153        self.assertTrue(
    154             'document_id,history,state,title,customer_id\r\n'
     154            'classname,document_id,history,last_transition_date,state,title,customer_id\r\n'
    155155            in result
    156156            )
    157         self.assertTrue(
    158             'Document created by system\'],created,My Document,A111111\r\n'
    159             in result
     157        self.assertMatches(
     158            '...CustomerDocument,d101,[u\'2014-11-25 06:57:24 UTC - '
     159            'Document created by system\'],2014-11-25 06:57:24.990308#,'
     160            'created,My Document,A111111...',
     161            result
    160162            )
    161163        return
     
    169171        result = open(self.outfile, 'rb').read()
    170172        self.assertTrue(
    171             'document_id,history,state,title,customer_id\r\n'
     173            'classname,document_id,history,last_transition_date,state,title,customer_id\r\n'
    172174            in result)
    173         self.assertTrue(
    174             ' Document created by system\'],created,My Document,A111111\r\n'
    175             in result)
     175        self.assertMatches(
     176            '...CustomerDocument,d101,[u\'2014-11-25 06:57:24 UTC - '
     177            'Document created by system\'],2014-11-25 06:57:24.990308#,'
     178            'created,My Document,A111111...',
     179            result
     180            )
    176181        return
    177182
     
    184189        result = open(self.outfile, 'rb').read()
    185190        self.assertTrue(
    186             'document_id,history,state,title,customer_id\r\n'
     191            'classname,document_id,history,last_transition_date,state,title,customer_id\r\n'
    187192            in result)
    188         self.assertTrue(
    189             ' Document created by system\'],created,My Document,A111111\r\n'
    190             in result)
     193        self.assertMatches(
     194            '...CustomerDocument,d101,[u\'2014-11-25 06:57:24 UTC - '
     195            'Document created by system\'],2014-11-25 06:57:24.990308#,'
     196            'created,My Document,A111111...',
     197            result
     198            )
    191199        return
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/utils.py

    r12051 r12053  
    288288        }
    289289
     290    DOCTYPES_DICT = {
     291        'CustomerDocument': 'Sample Document',
     292        'CustomerPDFDocument': 'PDF Document',
     293        }
     294
     295    SELECTABLE_DOCTYPES_DICT = DOCTYPES_DICT
     296
    290297    def getPDFCreator(self, context=None):
    291298        """Get a pdf creator suitable for `context`.
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/document.py

    r12032 r12053  
    7676        try:
    7777            TRANSLATED_STATES = getUtility(IDocumentsUtils).TRANSLATED_STATES
    78             ts = TRANSLATED_STATES[self.state]
    79             return ts
     78            return TRANSLATED_STATES[self.state]
    8079        except KeyError:
    8180            return
     81
     82    @property
     83    def classname(self):
     84        return self.__class__.__name__
     85
     86    @property
     87    def formatted_transition_date(self):
     88        try:
     89            return self.last_transition_date.strftime('%Y-%m-%d %H:%M:%S')
     90        except AttributeError:
     91            return
     92       
    8293
    8394Document = attrs_to_fields(Document)
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/interfaces.py

    r12032 r12053  
    4949    translated_state = Attribute(
    5050        'Returns a translated, more verbose verification state of a document')
     51    classname = Attribute('Name of the document class')
     52    formatted_transition_date = Attribute('Last transition formatted date string')
    5153
    5254    title = schema.TextLine(
     
    5557        )
    5658
     59    last_transition_date = schema.Datetime(
     60        title = _(u'Last Transition Date'),
     61        required = False,
     62        readonly = False,
     63        )
     64
     65
    5766class IDocumentsUtils(Interface):
    5867    """A collection of methods which are subject to customization.
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/workflow.py

    r12032 r12053  
    124124@grok.subscribe(IDocument, IWorkflowTransitionEvent)
    125125def handle_document_transition_event(obj, event):
    126     """Append message to document history and log file when transition happened.
     126    """Append message to document history and log file and update
     127    last_transition_date when transition happened.
    127128    """
    128129    msg = event.transition.user_data['msg']
    129130    history = IObjectHistory(obj)
    130131    history.addMessage(msg)
     132    obj.last_transition_date = datetime.utcnow()
    131133    try:
    132134        customers_container = grok.getSite()['customers']
  • main/waeup.ikoba/trunk/src/waeup/ikoba/utils/utils.py

    r12038 r12053  
    114114        ('C', 'Good'),
    115115        )
    116 
    117     # Should be overridden in custom packages
    118     DOCUMENT_TYPES = {
    119         'sample': 'Sample Document',
    120         }
    121116
    122117    PAYMENT_CATEGORIES = {
Note: See TracChangeset for help on using the changeset viewer.