Changeset 12214 for main


Ignore:
Timestamp:
13 Dec 2014, 15:46:41 (10 years ago)
Author:
Henrik Bettermann
Message:

Adjust UI components in documents and customers package.

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

Legend:

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

    r12210 r12214  
    769769            mapping = {'a':self.context.__parent__.display_fullname})
    770770
     771    @action(_('Add document'), validator=NullValidator, style='primary')
     772    def addDocument(self, **data):
     773        self.redirect(self.url(self.context, 'adddoc'))
     774        return
     775
    771776    @jsaction(_('Remove selected documents'))
    772777    def delDocument(self, **data):
     
    803808    grok.template('documentaddform')
    804809    grok.require('waeup.editCustomerDocuments')
    805     form_fields = grok.AutoFields(ICustomerDocument)
    806810    label = _('Add document')
    807811    pnav = 4
     
    812816        return sorted(doctypes.items())
    813817
    814     @action(_('Create document'), style='primary')
     818    @action(_('Add document'), style='primary')
    815819    def createDocument(self, **data):
    816820        form = self.request.form
     
    820824        # classes depending on the doctype parameter given in form.
    821825        document = createObject('waeup.%s' % doctype)
     826        self.applyData(document, **data)
    822827        self.context.addDocument(document)
    823828        doctype = getUtility(ICustomersUtils).SELECTABLE_DOCTYPES_DICT[doctype]
    824         self.flash(_('${a} created.',
    825             mapping = {'a': doctype}))
     829        self.flash(_('${a} added.', mapping = {'a': doctype}))
    826830        self.context.writeLogMessage(
    827831            self,'added: %s %s' % (doctype, document.document_id))
     
    841845    grok.require('waeup.viewCustomer')
    842846    grok.template('documentpage')
    843     form_fields = grok.AutoFields(ICustomerDocument)
    844     pnav = 4
     847    pnav = 4
     848
     849    @property
     850    def form_fields(self):
     851        return grok.AutoFields(self.context.form_fields_interface)
    845852
    846853    @property
     
    856863    grok.require('waeup.manageCustomer')
    857864    grok.template('documenteditpage')
    858     form_fields = grok.AutoFields(ICustomerDocument)
    859865    pnav = 4
    860866    deletion_warning = _('Are you sure?')
     867
     868    @property
     869    def form_fields(self):
     870        return grok.AutoFields(self.context.form_fields_interface)
    861871
    862872    def update(self):
     
    11021112            mapping = {'a':self.context.__parent__.display_fullname})
    11031113
     1114    @action(_('Add contract'), validator=NullValidator, style='primary')
     1115    def addContract(self, **data):
     1116        self.redirect(self.url(self.context, 'addcontract'))
     1117        return
     1118
    11041119    @jsaction(_('Remove selected contracts'))
    11051120    def delContract(self, **data):
     
    11331148    """
    11341149    grok.context(IContractsContainer)
    1135     grok.name('addapp')
     1150    grok.name('addcontract')
    11361151    grok.template('contractaddform')
    11371152    grok.require('waeup.editContracts')
    1138     form_fields = grok.AutoFields(IContract)
    11391153    label = _('Add contract')
    11401154    pnav = 4
     
    11451159        return sorted(contypes.items())
    11461160
    1147     @action(_('Create contract'), style='primary')
     1161    @action(_('Add contract'), style='primary')
    11481162    def createContract(self, **data):
    11491163        form = self.request.form
     
    11551169        self.context.addContract(contract)
    11561170        contype = getUtility(ICustomersUtils).SELECTABLE_CONTYPES_DICT[contype]
    1157         self.flash(_('${a} created.',
    1158             mapping = {'a': contype}))
     1171        self.flash(_('${a} added.', mapping = {'a': contype}))
    11591172        self.context.writeLogMessage(
    11601173            self,'added: %s %s' % (contype, contract.contract_id))
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/documents.py

    r12213 r12214  
    8686        try:
    8787            TRANSLATED_STATES = getUtility(
    88                 IDocumentsUtils).TRANSLATED_DOCUMENT_STATES
     88                ICustomersUtils).TRANSLATED_DOCUMENT_STATES
    8989            return TRANSLATED_STATES[self.state]
    9090        except KeyError:
     
    187187    filenames = ('sample',)
    188188
     189    form_fields_interface = ICustomerDocument
     190
    189191CustomerSampleDocument = attrs_to_fields(CustomerSampleDocument)
    190192
     
    201203    # tuple should contain only a single filename string.
    202204    filenames = ('sample.pdf',)
     205
     206    form_fields_interface = ICustomerPDFDocument
    203207
    204208CustomerPDFDocument = attrs_to_fields(CustomerPDFDocument)
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/interfaces.py

    r12210 r12214  
    242242    is_editable_by_customer = Attribute('Document editable by customer')
    243243    is_editable_by_manager = Attribute('Document editable by manager')
    244     translated_class_name = Attribute('Translatable class name')
    245244
    246245
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_browser.py

    r12213 r12214  
    471471    def test_login_as_customer(self):
    472472        # CustomerImpersonators can login as customer
    473         # Create clearance officer
    474473        self.app['users'].addUser('mrofficer', 'mrofficersecret')
    475474        self.app['users']['mrofficer'].email = 'mrofficer@foo.ng'
     
    827826        self.browser.open(self.customer_path)
    828827        self.browser.getLink("Documents", index=1).click()
    829         self.browser.getLink("Add document").click()
     828        self.browser.getControl("Add document").click()
    830829        self.browser.getControl(name="doctype").value = ['CustomerPDFDocument']
    831         self.browser.getControl("Create document").click()
    832         self.assertTrue('PDF Document created.' in self.browser.contents)
     830        self.browser.getControl("Add document").click()
     831        self.assertTrue('PDF Document added.' in self.browser.contents)
    833832        document = self.customer['documents']['d102']
    834833
     
    898897            '...You logged in...', self.browser.contents)
    899898        self.browser.getLink("Documents").click()
    900         self.browser.getLink("Add document").click()
     899        self.browser.getControl("Add document").click()
    901900        self.browser.getControl(name="doctype").value = ['CustomerSampleDocument']
    902         self.browser.getControl("Create document").click()
    903         self.assertTrue('Sample Document created.' in self.browser.contents)
     901        self.browser.getControl("Add document").click()
     902        self.assertTrue('Sample Document added.' in self.browser.contents)
    904903        document = self.customer['documents']['d102']
    905904
     
    10361035        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    10371036        self.browser.open(self.customer_path + '/documents')
    1038         self.browser.getLink("Add document").click()
     1037        self.browser.getControl("Add document").click()
    10391038        self.browser.getControl(name="doctype").value = ['CustomerPDFDocument']
    1040         self.browser.getControl("Create document").click()
     1039        self.browser.getControl("Add document").click()
    10411040        self.browser.open(self.documents_path + '/d102/manage')
    10421041        # Create a pseudo image file and select it to be uploaded
     
    11371136        self.browser.open(self.customer_path)
    11381137        self.browser.getLink("Contracts").click()
    1139         self.browser.getLink("Add contract").click()
     1138        self.browser.getControl("Add contract").click()
    11401139        self.browser.getControl(name="contype").value = ['SampleContract']
    1141         self.browser.getControl("Create contract").click()
    1142         self.assertTrue('Sample Contract created.' in self.browser.contents)
     1140        self.browser.getControl("Add contract").click()
     1141        self.assertTrue('Sample Contract added.' in self.browser.contents)
    11431142        contract = self.customer['contracts']['c102']
    11441143
     
    12001199            '...You logged in...', self.browser.contents)
    12011200        self.browser.getLink("Contracts").click()
    1202         self.browser.getLink("Add contract").click()
     1201        self.browser.getControl("Add contract").click()
    12031202        self.browser.getControl(name="contype").value = ['SampleContract']
    1204         self.browser.getControl("Create contract").click()
    1205         self.assertTrue('Sample Contract created.' in self.browser.contents)
     1203        self.browser.getControl("Add contract").click()
     1204        self.assertTrue('Sample Contract added.' in self.browser.contents)
    12061205        contract = self.customer['contracts']['c102']
    12071206        # Contract can be edited ...
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/utils.py

    r12199 r12214  
    306306        }
    307307
    308 
    309308    TRANSLATED_CONTRACT_STATES = {
    310309        CREATED: _('created'),
    311310        SUBMITTED: _('submitted for approval'),
    312311        APPROVED: _('approved'),
     312        REJECTED: _('rejected'),
     313        EXPIRED:_('expired')
     314        }
     315
     316    TRANSLATED_DOCUMENT_STATES = {
     317        CREATED: _('created'),
     318        SUBMITTED: _('submitted for verification'),
     319        VERIFIED: _('verified'),
    313320        REJECTED: _('rejected'),
    314321        EXPIRED:_('expired')
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/viewlets.py

    r12167 r12214  
    300300# Viewlets for customer documents
    301301
    302 class AddDocumentActionButton(AddActionButton):
    303     grok.order(1)
    304     grok.context(ICustomerDocumentsContainer)
    305     grok.view(DocumentsManageFormPage)
    306     grok.require('waeup.editCustomerDocuments')
    307     text = _('Add document')
    308     target = 'adddoc'
    309 
    310 
    311302class PDFDocumentOverviewActionButton(ManageActionButton):
    312303    grok.order(2)
     
    378369    target = 'document_slip.pdf'
    379370
     371
    380372# Viewlets for customer contracts
    381 
    382 class AddContractActionButton(AddActionButton):
    383     grok.order(1)
    384     grok.context(IContractsContainer)
    385     grok.view(ContractsManageFormPage)
    386     grok.require('waeup.editContracts')
    387     text = _('Add contract')
    388     target = 'addapp'
    389 
    390373
    391374class PDFContractOverviewActionButton(ManageActionButton):
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/browser.py

    r12213 r12214  
    4646
    4747from waeup.ikoba.documents.interfaces import (
    48     IDocumentsContainer, IDocument)
     48    IDocumentsContainer, IPublicDocument, IDocumentsUtils)
    4949
    5050grok.context(IIkobaObject) # Make IKofaObject the default context
     
    6262    """A breadcrumb for the customer container.
    6363    """
    64     grok.context(IDocument)
     64    grok.context(IPublicDocument)
    6565
    6666    def title(self):
     
    9090    label = _('Manage document section')
    9191
    92     taboneactions = [_('Save'),_('Cancel')]
    93     tabtwoactions = [_('Add document'), _('Remove selected'),_('Cancel')]
     92    @action(_('Add document'), validator=NullValidator, style='primary')
     93    def addSubunit(self, **data):
     94        self.redirect(self.url(self.context, 'adddoc'))
     95        return
    9496
    95     @jsaction(_('Remove selected'))
     97    @jsaction(_('Remove selected documents'))
    9698    def delDocuments(self, **data):
    9799        delSubobjects(self, redirect='manage', tab='2')
    98100        return
    99101
    100     @action(_('Save'), style='primary')
    101     def save(self, **data):
    102         return msave(self, **data)
    103 
    104102    @action(_('Cancel'), validator=NullValidator)
    105103    def cancel(self, **data):
    106104        self.redirect(self.url(self.context))
    107         return
    108 
    109     @action(_('Add document'), validator=NullValidator)
    110     def addSubunit(self, **data):
    111         self.redirect(self.url(self.context, 'adddocument'))
    112105        return
    113106
     
    118111    grok.context(IDocumentsContainer)
    119112    grok.require('waeup.manageDocuments')
    120     grok.name('adddocument')
    121     form_fields = grok.AutoFields(IDocument).omit('document_id')
     113    grok.name('adddoc')
     114    grok.template('documentaddform')
    122115    label = _('Add document')
    123116    pnav = 2
    124117
     118    @property
     119    def selectable_doctypes(self):
     120        doctypes = getUtility(IDocumentsUtils).SELECTABLE_DOCTYPES_DICT
     121        return sorted(doctypes.items())
     122
    125123    @action(_('Create document'), style='primary')
    126     def addDocument(self, **data):
    127         document = createObject(u'waeup.PublicDocument')
     124    def createDocument(self, **data):
     125        form = self.request.form
     126        doctype = form.get('doctype', None)
     127        # Here we can create various instances of PublicDocument derived
     128        # classes depending on the doctype parameter given in form.
     129        document = createObject('waeup.%s' % doctype)
    128130        self.applyData(document, **data)
    129         try:
    130             self.context.addDocument(document)
    131         except KeyError:
    132             self.flash(_('The Id chosen already exists.'),
    133                        type='danger')
    134             return
    135         self.flash(
    136             _("Document ${a} added.", mapping = {'a':document.document_id}))
     131        self.context.addDocument(document)
     132        doctype = getUtility(IDocumentsUtils).SELECTABLE_DOCTYPES_DICT[doctype]
     133        self.flash(_('${a} added.', mapping = {'a': doctype}))
    137134        ob_class = self.__implemented__.__name__.replace('waeup.ikoba.','')
    138135        self.context.__parent__.logger.info(
    139             '%s - added: %s' % (ob_class, document.document_id))
    140         self.redirect(self.url(self.context, u'manage')+'#tab2')
     136            '%s - added: %s %s' % (ob_class, doctype, document.document_id))
     137        self.redirect(self.url(self.context))
    141138        return
     139
     140    @action(_('Cancel'), validator=NullValidator)
     141    def cancel(self, **data):
     142        self.redirect(self.url(self.context))
    142143
    143144
     
    145146    """ Page to display document data
    146147    """
    147     grok.context(IDocument)
     148    grok.context(IPublicDocument)
    148149    grok.name('index')
    149150    grok.require('waeup.viewDocuments')
    150151    #grok.template('basepage')
    151     form_fields = grok.AutoFields(IDocument)
    152152    pnav = 2
     153
     154    @property
     155    def form_fields(self):
     156        return grok.AutoFields(self.context.form_fields_interface)
    153157
    154158    @property
     
    161165    """ View to manage document data
    162166    """
    163     grok.context(IDocument)
     167    grok.context(IPublicDocument)
    164168    grok.name('manage')
    165169    grok.require('waeup.manageDocuments')
    166     form_fields = grok.AutoFields(IDocument).omit('document_id')
    167170    grok.template('documentmanagepage')
    168171    pnav = 2
     
    171174    tabtwoactions1 = [_('Remove selected local roles')]
    172175    tabtwoactions2 = [_('Add local role')]
     176
     177    @property
     178    def form_fields(self):
     179        return grok.AutoFields(self.context.form_fields_interface)
    173180
    174181    def label(self):
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/browser_templates/containermanagepage.pt

    r12206 r12214  
    11<form action="." tal:attributes="action request/URL"
    22  i18n:domain="waeup.ikoba" method="POST" enctype="multipart/form-data">
    3   <ul class="tabs nav nav-tabs" data-tabs="tabs">
    4     <li class="active">
    5     <a href="#tab1" data-toggle="tab">
    6       <span i18n:translate="">Settings
    7       </span></a>
    8     </li>
    9     <li>
    10     <a href="#tab2" data-toggle="tab">
    11       <span i18n:translate="">Documents
    12       </span> </a>
    13     </li>
    14   </ul>
    15   <div class="tab-content">
    16     <div id="tab1" class="active tab-pane">
    17       <table class="form-table">
    18         <tbody>
    19           <tal:widgets content="structure provider:widgets" />
    20         </tbody>
    21       </table>
    22       <div tal:condition="view/availableActions">
    23         <span tal:repeat="action view/actions" tal:omit-tag="">
    24           <input tal:condition="python:action.label in view.taboneactions"
    25                  tal:replace="structure action/render"/>
    26         </span>
    27       </div>
    28     </div>
    29     <div id="tab2" class="tab-pane">
    30       <h3 i18n:translate="">Documents</h3>
    31       <table class="ikoba-data-table dataTableManage">
    32         <thead>
    33           <tr>
    34             <th>&nbsp;
    35             </th>
    36             <th i18n:translate="">Document Id
    37             </th>
    38             <th i18n:translate="">Title
    39             </th>
    40           </tr>
    41         </thead>
    42         <tbody>
    43           <tr tal:repeat="doc context/values"> <td>
    44               <input type="checkbox" name="val_id"
    45                      tal:attributes="value doc/document_id" /> </td> <td>
    46               <a tal:attributes="href python: view.url(doc)"
    47                  tal:content="doc/__name__"> ID</a> </td> <td>
    48               <span tal:content="doc/title">TITLE
    49               </span> </td>
    50           </tr>
    51         </tbody>
    52       </table>
    53       <div tal:condition="view/availableActions">
    54         <span tal:repeat="action view/actions" tal:omit-tag="">
    55           <input tal:condition="python:action.label in view.tabtwoactions"
    56                  tal:replace="structure action/render"/>
    57         </span>
    58       </div>
    59     </div>
     3  <h3 i18n:translate="">Documents</h3>
     4  <table class="ikoba-data-table dataTableManage">
     5    <thead>
     6      <tr>
     7        <th>&nbsp;
     8        </th>
     9        <th i18n:translate="">Id</th>
     10        <th i18n:translate="">Title</th>
     11        <th i18n:translate="">Type</th>
     12        <th i18n:translate="">State</th>
     13      </tr>
     14    </thead>
     15    <tbody>
     16      <tr tal:repeat="doc context/values"> <td>
     17          <input type="checkbox" name="val_id"
     18                 tal:attributes="value doc/document_id" /> </td> <td>
     19          <a tal:attributes="href python: view.url(doc)"
     20             tal:content="doc/__name__"> ID</a> </td>
     21          <td tal:content="doc/title">TITLE</td>
     22          <td tal:content="doc/translated_class_name">CLASSNAME</td>
     23          <td tal:content="doc/translated_state">STATE</td>
     24      </tr>
     25    </tbody>
     26  </table>
     27  <div tal:condition="view/availableActions">
     28    <span tal:repeat="action view/actions" tal:omit-tag="">
     29      <input tal:replace="structure action/render"/>
     30    </span>
    6031  </div>
    6132</form>
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/browser_templates/containerpage.pt

    r12206 r12214  
    66  <thead>
    77    <tr>
    8       <th i18n:translate="">Document Id</th>
     8      <th i18n:translate="">Id</th>
    99      <th i18n:translate="">Title</th>
     10      <th i18n:translate="">Type</th>
     11      <th i18n:translate="">State</th>
    1012    </tr>
    1113  </thead>
     
    1315    <tr tal:repeat="value context/values">
    1416      <td> <a tal:attributes="href python: view.url(value)">
    15           <span tal:content="value/document_id">ID</span></a></td>
     17          <span tal:content="value/document_id">ID</span></a>
     18      </td>
    1619      <td tal:content="value/title">TITLE</td>
     20      <td tal:content="value/translated_class_name">CLASSNAME</td>
     21      <td tal:content="value/translated_state">STATE</td>
    1722    </tr>
    1823  </tbody>
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/document.py

    r12213 r12214  
    4949    grok.baseclass()
    5050
     51    form_fields_interface = None
     52
    5153    local_roles = [
    5254        'waeup.local.DocumentManager',
     
    5658    state = None
    5759    translated_state = None
     60    translated_class_name = None
    5861
    5962    def __init__(self):
     
    117120            return
    118121
     122    @property
     123    def translated_class_name(self):
     124        try:
     125            DOCTYPES_DICT = getUtility(IDocumentsUtils).DOCTYPES_DICT
     126            return DOCTYPES_DICT[self.class_name]
     127        except KeyError:
     128            return
     129
    119130
    120131class PDFDocument(PublicDocumentBase):
     
    124135    grok.provides(IPDFDocument)
    125136
     137    form_fields_interface = IPDFDocument
     138
    126139PDFDocument = attrs_to_fields(PDFDocument)
    127140
     
    133146    grok.provides(IHTMLDocument)
    134147
     148    form_fields_interface = IHTMLDocument
     149
    135150HTMLDocument = attrs_to_fields(HTMLDocument)
    136 
    137 
    138 class DocumentFactory(grok.GlobalUtility):
    139     """A factory for documents.
    140     """
    141     grok.implements(IFactory)
    142     grok.name(u'waeup.PublicDocument')
    143     title = u"Create a new public document.",
    144     description = u"This factory instantiates new public documents."
    145 
    146     def __call__(self, *args, **kw):
    147         return PublicDocument(*args, **kw)
    148 
    149     def getInterfaces(self):
    150         return implementedBy(PublicDocument)
    151151
    152152
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/interfaces.py

    r12213 r12214  
    4444        'Returns a translated, more verbose verification state of a document')
    4545    class_name = Attribute('Name of the document class')
     46    translated_class_name = Attribute('Translatable class name')
    4647    formatted_transition_date = Attribute('Last transition formatted date string')
    4748    user_id = Attribute('Id of a user')
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/utils.py

    r12089 r12214  
    2222from waeup.ikoba.interfaces import (
    2323    CREATED, SUBMITTED,
    24     VERIFIED, REJECTED, EXPIRED)
     24    VERIFIED, REJECTED, EXPIRED, PUBLISHED)
    2525from waeup.ikoba.documents.interfaces import IDocumentsUtils
    2626
     
    3131
    3232
    33 class DocumentssUtils(grok.GlobalUtility):
     33class DocumentsUtils(grok.GlobalUtility):
    3434    """A collection of methods subject to customization.
    3535    """
     
    3838    TRANSLATED_DOCUMENT_STATES = {
    3939        CREATED: _('created'),
    40         SUBMITTED: _('submitted for verification'),
    41         VERIFIED: _('verified'),
    42         REJECTED: _('rejected'),
    43         EXPIRED:_('expired')
     40        PUBLISHED:_('published')
    4441        }
     42
     43    DOCTYPES_DICT = {
     44        'PDFDocument': _('PDF Document'),
     45        'HTMLDocument': _('HTML Document'),
     46        }
     47
     48    SELECTABLE_DOCTYPES_DICT = DOCTYPES_DICT
Note: See TracChangeset for help on using the changeset viewer.