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.

File:
1 edited

Legend:

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

    r12212 r12213  
    1919"""
    2020import grok
    21 from datetime import datetime
    2221from zope.component import getUtility
    2322from hurry.workflow.workflow import Transition, WorkflowState, NullCondition
     
    2726    IObjectHistory, IIkobaWorkflowInfo,
    2827    SimpleIkobaVocabulary,
    29     CREATED, SUBMITTED, VERIFIED, REJECTED, EXPIRED, PUBLISHED)
     28    CREATED, PUBLISHED)
    3029from waeup.ikoba.interfaces import MessageFactory as _
    3130from waeup.ikoba.workflow import IkobaWorkflow, IkobaWorkflowInfo
    32 from waeup.ikoba.utils.helpers import get_current_principal
    33 from waeup.ikoba.documents.interfaces import IDocument
     31from waeup.ikoba.documents.interfaces import IPublicDocument
    3432
    35 VERIFICATION_TRANSITIONS = (
     33
     34PUBLISHING_TRANSITIONS = (
    3635    Transition(
    3736        transition_id = 'create',
     
    4140        msg = _('Document created'),
    4241        destination = CREATED),
    43 
    44     Transition(
    45         transition_id = 'submit',
    46         title = _('Submit for verification'),
    47         msg = _('Submitted for verification'),
    48         source = CREATED,
    49         destination = SUBMITTED),
    50 
    51     Transition(
    52         transition_id = 'verify',
    53         title = _('Verify'),
    54         msg = _('Verified'),
    55         source = SUBMITTED,
    56         destination = VERIFIED),
    57 
    58     Transition(
    59         transition_id = 'reject',
    60         title = _('Reject'),
    61         msg = _('REJECTED'),
    62         source = SUBMITTED,
    63         destination = REJECTED),
    64 
    65     Transition(
    66         transition_id = 'reset1',
    67         title = _('Reset to initial state'),
    68         msg = _('Reset to initial state'),
    69         source = REJECTED,
    70         destination = CREATED),
    71 
    72     Transition(
    73         transition_id = 'reset2',
    74         title = _('Reset to initial state'),
    75         msg = _('Reset to initial state'),
    76         source = VERIFIED,
    77         destination = CREATED),
    78 
    79     Transition(
    80         transition_id = 'reset3',
    81         title = _('Reset to initial state'),
    82         msg = _('Reset to initial state'),
    83         source = SUBMITTED,
    84         destination = CREATED),
    85 
    86     Transition(
    87         transition_id = 'expire',
    88         title = _('Set to expired'),
    89         msg = _('Set to expired'),
    90         source = VERIFIED,
    91         destination = EXPIRED),
    92 
    93     Transition(
    94         transition_id = 'reset4',
    95         title = _('Reset to initial state'),
    96         msg = _('Reset to initial state'),
    97         source = EXPIRED,
    98         destination = CREATED),
    99 
    100     Transition(
    101         transition_id = 'publish',
    102         title = _('Publish'),
    103         msg = _('Published'),
    104         source = CREATED,
    105         destination = PUBLISHED),
    10642    )
    10743
     44publishing_workflow = IkobaWorkflow(PUBLISHING_TRANSITIONS)
    10845
    109 verification_workflow = IkobaWorkflow(VERIFICATION_TRANSITIONS)
    110 
    111 class VerificationWorkflowState(WorkflowState, grok.Adapter):
     46class PublishingWorkflowState(WorkflowState, grok.Adapter):
    11247    """An adapter to adapt Document objects to workflow states.
    11348    """
    114     grok.context(IDocument)
     49    grok.context(IPublicDocument)
    11550    grok.provides(IWorkflowState)
    11651
    117     state_key = 'wf.verification.state'
    118     state_id = 'wf.verification.id'
     52    state_key = 'wf.publishing.state'
     53    state_id = 'wf.publishing.id'
    11954
    120 class VerificationWorkflowInfo(IkobaWorkflowInfo, grok.Adapter):
    121     """Adapter to adapt Document objects to workflow info objects.
     55
     56class PublishingWorkflowInfo(IkobaWorkflowInfo, grok.Adapter):
     57    """Adapter to adapt CustomerDocument objects to workflow info objects.
    12258    """
    123     grok.context(IDocument)
     59    grok.context(IPublicDocument)
    12460    grok.provides(IIkobaWorkflowInfo)
    12561
    12662    def __init__(self, context):
    12763        self.context = context
    128         self.wf = verification_workflow
     64        self.wf = publishing_workflow
    12965
    130 @grok.subscribe(IDocument, IWorkflowTransitionEvent)
    131 def handle_document_transition_event(obj, event):
     66
     67@grok.subscribe(IPublicDocument, IWorkflowTransitionEvent)
     68def handle_public_document_transition_event(obj, event):
    13269    """Append message to document history and log file.
    13370
    134     Undo the verification of document and raise an exception if document
    135     does not meet the requirements for verification.
    13671    """
    137     if event.transition.destination == VERIFIED:
    138         verifiable, error = obj.is_verifiable
    139         if not verifiable:
    140             # Undo transition and raise an exception.
    141             IWorkflowState(obj).setState(event.transition.source)
    142             raise InvalidTransitionError(error)
    143     if event.transition.transition_id == 'verify':
    144         obj.setMD5()
    14572    msg = event.transition.user_data['msg']
    14673    history = IObjectHistory(obj)
    14774    history.addMessage(msg)
    14875    try:
    149         customers_container = grok.getSite()['customers']
    150         customers_container.logger.info('%s - %s' % (obj.customer_id,msg))
     76        grok.getSite().logger.info('%s' % msg)
    15177    except (TypeError, AttributeError):
    15278        pass
Note: See TracChangeset for help on using the changeset viewer.