Ignore:
Timestamp:
28 Nov 2014, 21:35:09 (10 years ago)
Author:
Henrik Bettermann
Message:

Implement application content components and rework workflows.

File:
1 edited

Legend:

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

    r11997 r12089  
    1 ## $Id: batching.py 11891 2014-10-28 20:02:45Z henrik $
     1## $Id$
    22##
    33## Copyright (C) 2014 Uli Fouquet & Henrik Bettermann
     
    2525from waeup.ikoba.interfaces import (
    2626    IObjectHistory, IIkobaWorkflowInfo, IIkobaUtils,
    27     STARTED, CREATED, REQUESTED, APPROVED)
     27    STARTED, CREATED, REQUESTED, APPROVED,
     28    SUBMITTED, VERIFIED, REJECTED, EXPIRED)
    2829from waeup.ikoba.interfaces import MessageFactory as _
    2930from waeup.ikoba.workflow import IkobaWorkflow, IkobaWorkflowInfo
    30 from waeup.ikoba.customers.interfaces import ICustomer, ICustomersUtils
     31from waeup.ikoba.customers.interfaces import (
     32    ICustomer, ICustomersUtils,
     33    IApplication)
    3134from waeup.ikoba.utils.helpers import get_current_principal
    32 
    33 
    34 IMPORTABLE_STATES = (STARTED, REQUESTED, APPROVED)
     35from waeup.ikoba.documents.workflow import VERIFICATION_TRANSITIONS
     36
     37# Customer workflow
     38
     39IMPORTABLE_REGISTRATION_STATES = (STARTED, REQUESTED, APPROVED)
    3540
    3641REGISTRATION_TRANSITIONS = (
     
    96101
    97102
    98 IMPORTABLE_TRANSITIONS = [i.transition_id for i in REGISTRATION_TRANSITIONS]
     103IMPORTABLE_REGISTRATION_TRANSITIONS = [i.transition_id for i in REGISTRATION_TRANSITIONS]
    99104
    100105registration_workflow = IkobaWorkflow(REGISTRATION_TRANSITIONS)
     
    136141        pass
    137142    return
     143
     144# Application workflow (the same as verification workflow)
     145
     146IMPORTABLE_APPLICATION_STATES = (CREATED, SUBMITTED, APPROVED, REJECTED, EXPIRED)
     147
     148APPLICATION_TRANSITIONS = (
     149    Transition(
     150        transition_id = 'create',
     151        title = _('Create application record'),
     152        source = None,
     153        condition = NullCondition,
     154        msg = _('Application record created'),
     155        destination = CREATED),
     156
     157    Transition(
     158        transition_id = 'submit',
     159        title = _('Submit for approval'),
     160        msg = _('Submitted for approval'),
     161        source = CREATED,
     162        destination = SUBMITTED),
     163
     164    Transition(
     165        transition_id = 'approve',
     166        title = _('Approve'),
     167        msg = _('Approved'),
     168        source = SUBMITTED,
     169        destination = APPROVED),
     170
     171    Transition(
     172        transition_id = 'reject',
     173        title = _('Reject'),
     174        msg = _('REJECTED'),
     175        source = SUBMITTED,
     176        destination = REJECTED),
     177
     178    Transition(
     179        transition_id = 'reset1',
     180        title = _('Reset to initial state'),
     181        msg = _('Reset to initial state'),
     182        source = REJECTED,
     183        destination = CREATED),
     184
     185    Transition(
     186        transition_id = 'reset2',
     187        title = _('Reset to initial state'),
     188        msg = _('Reset to initial state'),
     189        source = APPROVED,
     190        destination = CREATED),
     191
     192    Transition(
     193        transition_id = 'reset3',
     194        title = _('Reset to initial state'),
     195        msg = _('Reset to initial state'),
     196        source = SUBMITTED,
     197        destination = CREATED),
     198
     199    Transition(
     200        transition_id = 'expire',
     201        title = _('Set to expired'),
     202        msg = _('Set to expired'),
     203        source = APPROVED,
     204        destination = EXPIRED),
     205
     206    Transition(
     207        transition_id = 'reset4',
     208        title = _('Reset to initial state'),
     209        msg = _('Reset to initial state'),
     210        source = EXPIRED,
     211        destination = CREATED),
     212    )
     213
     214
     215IMPORTABLE_APPLICATION_TRANSITIONS = [
     216    i.transition_id for i in REGISTRATION_TRANSITIONS]
     217
     218application_workflow = IkobaWorkflow(APPLICATION_TRANSITIONS)
     219
     220class ApplicationWorkflowState(WorkflowState, grok.Adapter):
     221    """An adapter to adapt Application objects to workflow states.
     222    """
     223    grok.context(IApplication)
     224    grok.provides(IWorkflowState)
     225
     226    state_key = 'wf.application.state'
     227    state_id = 'wf.application.id'
     228
     229class ApplicationWorkflowInfo(IkobaWorkflowInfo, grok.Adapter):
     230    """Adapter to adapt Application objects to workflow info objects.
     231    """
     232    grok.context(IApplication)
     233    grok.provides(IIkobaWorkflowInfo)
     234
     235    def __init__(self, context):
     236        self.context = context
     237        self.wf = application_workflow
     238
     239@grok.subscribe(IApplication, IWorkflowTransitionEvent)
     240def handle_document_transition_event(obj, event):
     241    """Append message to application history and log file and update
     242    last_transition_date when transition happened.
     243    """
     244    msg = event.transition.user_data['msg']
     245    history = IObjectHistory(obj)
     246    history.addMessage(msg)
     247    obj.last_transition_date = datetime.utcnow()
     248    try:
     249        customers_container = grok.getSite()['customers']
     250        customers_container.logger.info('%s - %s' % (obj.customer_id,msg))
     251    except (TypeError, AttributeError):
     252        pass
     253    return
Note: See TracChangeset for help on using the changeset viewer.