Ignore:
Timestamp:
2 Dec 2014, 14:38:31 (10 years ago)
Author:
Henrik Bettermann
Message:

Implement HREFDisplayWidget which renders a persistent object title inside an anchor element
referring to the object.

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

Legend:

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

    r12112 r12119  
    4747from waeup.ikoba.browser.interfaces import ICaptchaManager
    4848from waeup.ikoba.mandates.mandate import PasswordMandate
     49from waeup.ikoba.widgets.hrefwidget import HREFDisplayWidget
    4950from waeup.ikoba.utils.helpers import get_current_principal, to_timezone, now
    5051from waeup.ikoba.customers.interfaces import (
     
    6869    if changed_fields:
    6970        changed_fields = reduce(lambda x,y: x+y, changed_fields.values())
    70     if 'product' in changed_fields and data['product'] is not None:
    71         view.context.last_product_id = data['product'].product_id
     71    if 'product_object' in changed_fields and data['product_object'] is not None:
     72        view.context.last_product_id = data['product_object'].product_id
    7273        notify(grok.ObjectModifiedEvent(view.context))
    7374    fields_string = ' + '.join(changed_fields)
     
    11551156    @property
    11561157    def form_fields(self):
    1157         return grok.AutoFields(self.context.form_fields_interface).omit(
     1158        form_fields = grok.AutoFields(self.context.form_fields_interface).omit(
    11581159            'last_transition_date')
     1160        for field in form_fields:
     1161            if field.__name__.endswith('_object'):
     1162                form_fields[field.__name__].custom_widget = HREFDisplayWidget
     1163        return form_fields
    11591164
    11601165    @property
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/interfaces.py

    r12103 r12119  
    288288        )
    289289
    290     product = schema.Choice(
     290    product_object = schema.Choice(
    291291        title = _(u'Product'),
    292292        source = ConCatProductSource(),
     
    300300    """
    301301
    302     product = schema.Choice(
     302    product_object = schema.Choice(
    303303        title = _(u'Product'),
    304304        source = ConCatProductSource(),
     
    312312    """
    313313
    314     document = schema.Choice(
     314    document_object = schema.Choice(
    315315        title = _(u'Document'),
    316316        source = CustomerDocumentSource(),
     
    324324    """
    325325
    326     product = schema.Choice(
     326    product_object = schema.Choice(
    327327        title = _(u'Product'),
    328328        source = ConCatProductSource(),
     
    330330        )
    331331
    332     document = schema.Choice(
     332    document_object = schema.Choice(
    333333        title = _(u'Document'),
    334334        source = CustomerDocumentSource(),
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_browser.py

    r12112 r12119  
    10741074        self.browser.getLink("c102").click()
    10751075        self.browser.getLink("Manage").click()
    1076         self.browser.getControl(name="form.product").value = ['SAM']
     1076        self.browser.getControl(name="form.product_object").value = ['SAM']
    10771077        self.browser.getControl(name="form.title").value = 'My second contract'
    10781078        self.browser.getControl("Save").click()
     
    11341134        contract = self.customer['contracts']['c102']
    11351135        # Contract can be edited ...
    1136         self.browser.getLink("c102").click()
    11371136        self.browser.open(self.contracts_path + '/c102/edit')
    11381137        #self.browser.getLink("Edit").click()
     
    11481147        # So far last_product_id is None.
    11491148        self.assertTrue(self.customer['contracts']['c102'].last_product_id is None)
    1150         self.browser.getControl(name="form.product").value = ['SAM']
     1149        self.browser.getControl(name="form.product_object").value = ['SAM']
    11511150        self.browser.getControl("Save").click()
    11521151        # Document is a required field on edit form page.
     
    11571156        IWorkflowState(self.document).setState(SUBMITTED)
    11581157        self.browser.open(self.contracts_path + '/c102/edit')
    1159         self.browser.getControl(name="form.product").value = ['SAM']
    1160         self.browser.getControl(name="form.document").value = ['d101']
     1158        self.browser.getControl(name="form.product_object").value = ['SAM']
     1159        self.browser.getControl(name="form.document_object").value = ['d101']
    11611160        self.browser.getControl(name="form.title").value = 'My second contract'
    11621161        self.browser.getControl("Save").click()
     
    11651164        self.assertEqual(self.customer['contracts']['c102'].last_product_id, 'SAM')
    11661165        self.assertEqual(contract.title, 'My second contract')
    1167         self.assertEqual(contract.product, self.product)
    1168         self.assertEqual(contract.document, self.document)
     1166        self.assertEqual(contract.product_object, self.product)
     1167        self.assertEqual(contract.document_object, self.document)
    11691168        # Saving the form again does not unset last_product_id
    11701169        self.browser.getControl(name="form.title").value = 'My third contract'
     
    11741173        self.browser.getLink("View").click()
    11751174        self.assertEqual(self.browser.url, self.contracts_path + '/c102/index')
     1175        # An href attribute is referring to the document and product objects
     1176        self.assertTrue('<a href="http://localhost/app/products/SAM">SAM -'
     1177            in self.browser.contents)
     1178        self.assertTrue(
     1179            '<a href="http://localhost/app/customers/K1000000/documents/d101">d101 -'
     1180            in self.browser.contents)
    11761181        # Customer can submit the form. The form is also saved.
    11771182        self.browser.getLink("Edit").click()
Note: See TracChangeset for help on using the changeset viewer.