Ignore:
Timestamp:
13 Dec 2014, 10:51:17 (10 years ago)
Author:
Henrik Bettermann
Message:

We need different workflows for customer documents and central 'public' documents.

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

Legend:

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

    r12211 r12213  
    2222import grok
    2323from hashlib import md5
     24from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState
    2425from zope.component import queryUtility, getUtility
    2526from zope.component.interfaces import IFactory
     
    7677    filenames = ()
    7778
     79    @property
     80    def state(self):
     81        state = IWorkflowState(self).getState()
     82        return state
     83
     84    @property
     85    def translated_state(self):
     86        try:
     87            TRANSLATED_STATES = getUtility(
     88                IDocumentsUtils).TRANSLATED_DOCUMENT_STATES
     89            return TRANSLATED_STATES[self.state]
     90        except KeyError:
     91            return
    7892    @property
    7993    def customer(self):
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_browser.py

    r12207 r12213  
    5050from waeup.ikoba.authentication import LocalRoleSetEvent
    5151from waeup.ikoba.tests.test_async import FunctionalAsyncTestCase
    52 from waeup.ikoba.documents.workflow import VERIFIED
     52from waeup.ikoba.interfaces import VERIFIED
    5353from waeup.ikoba.browser.tests.test_pdf import samples_dir
    5454
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/workflow.py

    r12212 r12213  
    3333from waeup.ikoba.customers.interfaces import (
    3434    ICustomer, ICustomersUtils,
    35     IContract)
     35    IContract, ICustomerDocument)
    3636from waeup.ikoba.utils.helpers import get_current_principal
    37 from waeup.ikoba.documents.workflow import VERIFICATION_TRANSITIONS
    3837
    3938# Customer workflow
     
    214213    )
    215214
    216 
    217215contract_workflow = IkobaWorkflow(CONTRACT_TRANSITIONS)
     216
    218217
    219218class ContractWorkflowState(WorkflowState, grok.Adapter):
     
    225224    state_key = 'wf.contract.state'
    226225    state_id = 'wf.contract.id'
     226
    227227
    228228class ContractWorkflowInfo(IkobaWorkflowInfo, grok.Adapter):
     
    258258        pass
    259259    return
     260
     261# Customer document workflow
     262
     263VERIFICATION_TRANSITIONS = (
     264    Transition(
     265        transition_id = 'create',
     266        title = _('Create document'),
     267        source = None,
     268        condition = NullCondition,
     269        msg = _('Document created'),
     270        destination = CREATED),
     271
     272    Transition(
     273        transition_id = 'submit',
     274        title = _('Submit for verification'),
     275        msg = _('Submitted for verification'),
     276        source = CREATED,
     277        destination = SUBMITTED),
     278
     279    Transition(
     280        transition_id = 'verify',
     281        title = _('Verify'),
     282        msg = _('Verified'),
     283        source = SUBMITTED,
     284        destination = VERIFIED),
     285
     286    Transition(
     287        transition_id = 'reject',
     288        title = _('Reject'),
     289        msg = _('REJECTED'),
     290        source = SUBMITTED,
     291        destination = REJECTED),
     292
     293    Transition(
     294        transition_id = 'reset1',
     295        title = _('Reset to initial state'),
     296        msg = _('Reset to initial state'),
     297        source = REJECTED,
     298        destination = CREATED),
     299
     300    Transition(
     301        transition_id = 'reset2',
     302        title = _('Reset to initial state'),
     303        msg = _('Reset to initial state'),
     304        source = VERIFIED,
     305        destination = CREATED),
     306
     307    Transition(
     308        transition_id = 'reset3',
     309        title = _('Reset to initial state'),
     310        msg = _('Reset to initial state'),
     311        source = SUBMITTED,
     312        destination = CREATED),
     313
     314    Transition(
     315        transition_id = 'expire',
     316        title = _('Set to expired'),
     317        msg = _('Set to expired'),
     318        source = VERIFIED,
     319        destination = EXPIRED),
     320
     321    Transition(
     322        transition_id = 'reset4',
     323        title = _('Reset to initial state'),
     324        msg = _('Reset to initial state'),
     325        source = EXPIRED,
     326        destination = CREATED),
     327    )
     328
     329verification_workflow = IkobaWorkflow(VERIFICATION_TRANSITIONS)
     330
     331
     332class VerificationWorkflowState(WorkflowState, grok.Adapter):
     333    """An adapter to adapt CustomerDocument objects to workflow states.
     334    """
     335    grok.context(ICustomerDocument)
     336    grok.provides(IWorkflowState)
     337
     338    state_key = 'wf.verification.state'
     339    state_id = 'wf.verification.id'
     340
     341
     342class VerificationWorkflowInfo(IkobaWorkflowInfo, grok.Adapter):
     343    """Adapter to adapt CustomerDocument objects to workflow info objects.
     344    """
     345    grok.context(ICustomerDocument)
     346    grok.provides(IIkobaWorkflowInfo)
     347
     348    def __init__(self, context):
     349        self.context = context
     350        self.wf = verification_workflow
     351
     352@grok.subscribe(ICustomerDocument, IWorkflowTransitionEvent)
     353def handle_customer_document_transition_event(obj, event):
     354    """Append message to document history and log file.
     355
     356    Undo the verification of document and raise an exception if document
     357    does not meet the requirements for verification.
     358    """
     359    if event.transition.destination == VERIFIED:
     360        verifiable, error = obj.is_verifiable
     361        if not verifiable:
     362            # Undo transition and raise an exception.
     363            IWorkflowState(obj).setState(event.transition.source)
     364            raise InvalidTransitionError(error)
     365    if event.transition.transition_id == 'verify':
     366        obj.setMD5()
     367    msg = event.transition.user_data['msg']
     368    history = IObjectHistory(obj)
     369    history.addMessage(msg)
     370    try:
     371        customers_container = grok.getSite()['customers']
     372        customers_container.logger.info('%s - %s' % (obj.customer_id,msg))
     373    except (TypeError, AttributeError):
     374        pass
     375    return
Note: See TracChangeset for help on using the changeset viewer.