Changeset 12089


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

Implement application content components and rework workflows.

Location:
main/waeup.ikoba/trunk/src/waeup/ikoba
Files:
2 added
9 edited

Legend:

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

    r12065 r12089  
    4343    _curr_doc_id = 101
    4444
     45    _curr_app_id = 101
     46
    4547    # Setup authentication for this app. Note: this is only
    4648    # initialized, when a new instance of this app is created.
     
    5860        """A unique document id for all documents in company.
    5961
    60         The document id returned is guaranteed to be unique. It
    61         consists of some prefix (normally a single letter) followed by
    62         a number with at least 7 digits.
     62        The document id returned is guaranteed to be unique.
    6363
    6464        Once a document id was issued, it won't be issued again.
     
    7070        new_id = u'd%s' % (self._curr_doc_id)
    7171        self._curr_doc_id += 1
     72        # self._p_changed = True
     73        # commit()
     74        # lock.release() # end of lock
     75        return new_id
     76
     77    @property
     78    def unique_application_id(self):
     79        """A unique application id for all application objects in customers.
     80
     81        The application id returned is guaranteed to be unique.
     82
     83        Once a application id was issued, it won't be issued again.
     84
     85        Obtaining an application id is currently not thread-safe but can be
     86        made easily by enabling commented lines.
     87        """
     88        # lock.acquire() # lock data
     89        new_id = u'd%s' % (self._curr_app_id)
     90        self._curr_app_id += 1
    7291        # self._p_changed = True
    7392        # commit()
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/batching.py

    r12057 r12089  
    4545    ICustomerDocument)
    4646from waeup.ikoba.customers.workflow import  (
    47     IMPORTABLE_STATES, IMPORTABLE_TRANSITIONS)
     47    IMPORTABLE_REGISTRATION_STATES, IMPORTABLE_REGISTRATION_TRANSITIONS,
     48    IMPORTABLE_APPLICATION_STATES, IMPORTABLE_APPLICATION_TRANSITIONS)
    4849from waeup.ikoba.utils.batching import BatchProcessor
    4950
     
    256257            row, self.factory_name, mode=mode)
    257258        if 'transition' in row:
    258             if row['transition'] not in IMPORTABLE_TRANSITIONS:
     259            if row['transition'] not in IMPORTABLE_REGISTRATION_TRANSITIONS:
    259260                if row['transition'] not in (IGNORE_MARKER, ''):
    260261                    errs.append(('transition', 'not allowed'))
    261262        if 'state' in row:
    262             if row['state'] not in IMPORTABLE_STATES:
     263            if row['state'] not in IMPORTABLE_REGISTRATION_STATES:
    263264                if row['state'] not in (IGNORE_MARKER, ''):
    264265                    errs.append(('state', 'not allowed'))
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/browser.py

    r12088 r12089  
    3535from waeup.ikoba.interfaces import (
    3636    IContactForm, IObjectHistory, IIkobaObject, IIkobaUtils,
    37     IPasswordValidator, IUserAccount)
     37    IPasswordValidator, IUserAccount,
     38    VERIFIED, REJECTED, EXPIRED)
    3839from waeup.ikoba.browser.layout import (
    3940    IkobaPage, IkobaEditFormPage, IkobaAddFormPage, IkobaDisplayFormPage,
     
    4647from waeup.ikoba.browser.interfaces import ICaptchaManager
    4748from waeup.ikoba.mandates.mandate import PasswordMandate
    48 from waeup.ikoba.documents.workflow import VERIFIED, REJECTED, OUTDATED
    4949from waeup.ikoba.utils.helpers import get_current_principal, to_timezone, now
    5050from waeup.ikoba.customers.interfaces import (
     
    754754            return True
    755755        return (self.request.principal.user_type == 'customer' and \
    756             document.state in (VERIFIED, REJECTED, OUTDATED))
     756            document.state in (VERIFIED, REJECTED, EXPIRED))
    757757
    758758    @property
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/interfaces.py

    r12057 r12089  
    265265
    266266class ICustomerDocument(IDocument):
    267     """A customer document.
    268 
    269     """
    270 
    271     #is_editable = Attribute('Document editable by customer')
    272     #translated_class_name = Attribute('Translatable class name')
     267    """A customer document object.
     268
     269    """
     270
     271    is_editable = Attribute('Document editable by customer')
     272    translated_class_name = Attribute('Translatable class name')
    273273
    274274
     
    277277
    278278    """
     279
     280# Customer application interfaces
     281
     282class IApplicationsContainer(IIkobaObject):
     283    """A container for customer aplication objects.
     284
     285    """
     286
     287    def addApplication(application):
     288        """Add an application object.
     289        """
     290
     291
     292class IApplication(IIkobaObject):
     293    """A customer application.
     294
     295    """
     296    application_id = Attribute('Application Identifier')
     297    history = Attribute('Object history, a list of messages')
     298    state = Attribute('Returns the application state')
     299    translated_state = Attribute(
     300        'Returns a translated, more verbose appliction state')
     301    class_name = Attribute('Name of the application class')
     302    formatted_transition_date = Attribute('Last transition formatted date string')
     303
     304    title = schema.TextLine(
     305        title = _(u'Application Title'),
     306        required = True,
     307        )
     308
     309    last_transition_date = schema.Datetime(
     310        title = _(u'Last Transition Date'),
     311        required = False,
     312        readonly = False,
     313        )
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/utils.py

    r12088 r12089  
    266266        )
    267267
     268def generate_application_id():
     269    new_id = grok.getSite().unique_application_id
     270    return new_id
     271
    268272class CustomersUtils(grok.GlobalUtility):
    269273    """A collection of methods subject to customization.
     
    283287    APPMANAGE_CUSTOMER_STATES = DOCMANAGE_CUSTOMER_STATES
    284288
    285     APPMANAGE_APPLICATION_STATES = (CREATED,)
     289    APPMANAGE_APPLICATION_STATES = ()
    286290
    287291    SKIP_UPLOAD_VIEWLETS = ()
     
    292296        REQUESTED: _('requested'),
    293297        APPROVED: _('approved'),
     298        }
     299
     300
     301    TRANSLATED_APPLICATION_STATES = {
    294302        }
    295303
  • 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
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/utils.py

    r12088 r12089  
    2020import grok
    2121from waeup.ikoba.interfaces import MessageFactory as _
    22 from waeup.ikoba.documents.workflow import CREATED
     22from waeup.ikoba.interfaces import (
     23    CREATED, SUBMITTED,
     24    VERIFIED, REJECTED, EXPIRED)
    2325from waeup.ikoba.documents.interfaces import IDocumentsUtils
    24 from waeup.ikoba.documents.workflow import (
    25     CREATED, SUBMITTED,
    26     VERIFIED, REJECTED, OUTDATED)
    2726
    2827
     
    4241        VERIFIED: _('verified'),
    4342        REJECTED: _('rejected'),
    44         OUTDATED:_('outdated')
     43        EXPIRED:_('expired')
    4544        }
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/workflow.py

    r12053 r12089  
    2525from waeup.ikoba.interfaces import (
    2626    IObjectHistory, IIkobaWorkflowInfo,
    27     SimpleIkobaVocabulary)
     27    SimpleIkobaVocabulary,
     28    CREATED, SUBMITTED, VERIFIED, REJECTED, EXPIRED)
    2829from waeup.ikoba.interfaces import MessageFactory as _
    2930from waeup.ikoba.workflow import IkobaWorkflow, IkobaWorkflowInfo
     
    3132from waeup.ikoba.documents.interfaces import IDocument
    3233
    33 CREATED = 'created'
    34 SUBMITTED = 'submitted'
    35 VERIFIED = 'verified'
    36 REJECTED = 'rejected'
    37 OUTDATED = 'outdated'
     34IMPORTABLE_STATES = (CREATED, SUBMITTED, VERIFIED, REJECTED, EXPIRED)
    3835
    39 IMPORTABLE_STATES = (CREATED, SUBMITTED, VERIFIED, REJECTED)
    40 
    41 REGISTRATION_TRANSITIONS = (
     36VERIFICATION_TRANSITIONS = (
    4237    Transition(
    4338        transition_id = 'create',
     
    7166    Transition(
    7267        transition_id = 'reset1',
    73         title = _('Reset'),
     68        title = _('Reset to initial state'),
    7469        msg = _('Reset to initial state'),
    7570        source = REJECTED,
     
    7873    Transition(
    7974        transition_id = 'reset2',
    80         title = _('Reset'),
     75        title = _('Reset to initial state'),
    8176        msg = _('Reset to initial state'),
    8277        source = VERIFIED,
     
    8580    Transition(
    8681        transition_id = 'reset3',
    87         title = _('Reset'),
     82        title = _('Reset to initial state'),
    8883        msg = _('Reset to initial state'),
    8984        source = SUBMITTED,
     
    9186
    9287    Transition(
    93         transition_id = 'outdate',
    94         title = _('Set to outdated'),
    95         msg = _('Set to outdated'),
     88        transition_id = 'expire',
     89        title = _('Set to expired'),
     90        msg = _('Set to expired'),
    9691        source = VERIFIED,
    97         destination = OUTDATED),
     92        destination = EXPIRED),
     93
     94    Transition(
     95        transition_id = 'reset4',
     96        title = _('Reset to initial state'),
     97        msg = _('Reset to initial state'),
     98        source = EXPIRED,
     99        destination = CREATED),
    98100    )
    99101
    100102
    101 IMPORTABLE_TRANSITIONS = [i.transition_id for i in REGISTRATION_TRANSITIONS]
     103IMPORTABLE_TRANSITIONS = [i.transition_id for i in VERIFICATION_TRANSITIONS]
    102104
    103 verification_workflow = IkobaWorkflow(REGISTRATION_TRANSITIONS)
     105verification_workflow = IkobaWorkflow(VERIFICATION_TRANSITIONS)
    104106
    105107class VerificationWorkflowState(WorkflowState, grok.Adapter):
  • main/waeup.ikoba/trunk/src/waeup/ikoba/interfaces.py

    r12060 r12089  
    4545VIRT_JOBS_CONTAINER_NAME = 'jobs'
    4646
     47# States for various workflows
     48
    4749CREATED = 'created'
     50
    4851STARTED = 'started'
    4952REQUESTED = 'requested'
    5053APPROVED = 'approved'
     54
     55SUBMITTED = 'submitted'
     56VERIFIED = 'verified'
     57REJECTED = 'rejected'
     58EXPIRED = 'expired'
     59
    5160
    5261#: A dict giving job status as tuple (<STRING>, <TRANSLATED_STRING>),
Note: See TracChangeset for help on using the changeset viewer.