Ignore:
Timestamp:
30 Nov 2014, 09:12:44 (10 years ago)
Author:
Henrik Bettermann
Message:

Add event subscriber handle_product_removed which ensures that also referrers to customer application objects are removed when a product is deleted.

Location:
main/waeup.ikoba/trunk/src/waeup/ikoba/customers
Files:
4 edited

Legend:

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

    r12094 r12095  
    2929from waeup.ikoba.customers.interfaces import (
    3030    IApplicationsContainer, ICustomerNavigation,
    31     IApplication, ICustomersUtils,
     31    IApplication, IApplicationEdit, ICustomersUtils,
    3232    )
    3333from waeup.ikoba.customers.utils import generate_application_id
     
    5959    """This is a customer application baseclass.
    6060    """
    61     grok.implements(IApplication, ICustomerNavigation)
     61    grok.implements(IApplication, IApplicationEdit, ICustomerNavigation)
    6262    grok.provides(IApplication)
    6363    grok.baseclass()
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/browser.py

    r12094 r12095  
    5151    ICustomer, ICustomersContainer, ICustomerRequestPW, ICustomersUtils,
    5252    ICustomerDocument, ICustomerDocumentsContainer, ICustomerCreate,
    53     ICustomerPDFDocument, IApplicationsContainer, IApplication
     53    ICustomerPDFDocument, IApplicationsContainer, IApplication, IApplicationEdit
    5454    )
    5555from waeup.ikoba.customers.catalog import search
     
    11831183    grok.name('edit')
    11841184    grok.require('waeup.handleCustomer')
     1185    form_fields = grok.AutoFields(IApplicationEdit).omit('last_transition_date')
    11851186
    11861187    def update(self):
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/interfaces.py

    r12094 r12095  
    290290        title = _(u'Product'),
    291291        source = AppCatProductSource(),
    292         required = True,
    293         )
     292        required = False,
     293        )
     294
     295class IApplicationEdit(IApplication):
     296    """Interface for editing application data by customers.
     297
     298    """
     299
     300    product = schema.Choice(
     301        title = _(u'Product'),
     302        source = AppCatProductSource(),
     303        required = True,
     304        )
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_catalog.py

    r12094 r12095  
    1616## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    1717##
     18import os
    1819import grok
    1920import shutil
     
    167168        assert results[0] is self.customer['applications'][self.application_id]
    168169        assert results[0].product is self.product
     170
     171    def test_product_removal(self):
     172        # This test does not only test catalog components, it also ensures
     173        # that the product attribute of an application is cleared
     174        # but the last_product_id is not.
     175        del self.app['products'][self.product_id]
     176        self.assertTrue(self.application.product is None)
     177        self.assertEqual(self.application.last_product_id, 'SAM')
     178        cat = queryUtility(ICatalog, name='applications_catalog')
     179        results = cat.searchResults(last_product_id=('SAM', 'SAM'))
     180        results = [x for x in results]
     181        assert len(results) == 1
     182        assert results[0] is self.customer['applications'][self.application_id]
     183        assert results[0].product is None
     184        # Product removal is being logged in customers.log
     185        logfile = os.path.join(
     186            self.app['datacenter'].storage, 'logs', 'customers.log')
     187        logcontent = open(logfile).read()
     188        self.assertTrue(
     189            'INFO - system - ObjectRemovedEvent - K1000000 - a101 - removed: product\n'
     190            in logcontent)
     191
Note: See TracChangeset for help on using the changeset viewer.