Last active
August 29, 2015 14:17
-
-
Save datakurre/ef5f973383b740ae8f8e to your computer and use it in GitHub Desktop.
Example workflow for pyramid_workflow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from pyramid_workflow import ( | |
Workflow, | |
get_workflow | |
) | |
def incoming_start(context, request, transition, workflow): | |
pass | |
def incoming_complete(context, request, transition, workflow): | |
pass | |
def incoming_abort(context, request, transition, workflow): | |
pass | |
incoming_workflow = Workflow(type='incoming', state_attr='incoming_state', initial_state='new') | |
incoming_workflow.add_state('new') | |
incoming_workflow.add_state('working') | |
incoming_workflow.add_state('done') | |
incoming_workflow.add_transition('start', from_state='new', to_state='working', callback=incoming_start) | |
incoming_workflow.add_transition('complete', from_state='working', to_state='done', callback=incoming_complete) | |
incoming_workflow.add_transition('abort', from_state='working', to_state='new', callback=incoming_abort) | |
class _EnrollmentStatePredicate(object): | |
def __init__(self, val, config): | |
self.type, self.state = val.split(':') | |
self.registry = config.registry | |
def text(self): | |
return 'state = %s' % ':'.join((self.type, self.state)) | |
phash = text | |
def __call__(self, context, request): | |
wf = get_workflow(request, self.type, IEnrollee) | |
return wf.state_of(context) == self.state | |
def includeme(config): | |
config.add_view_predicate('enrollment_state', _EnrollmentStatePredicate) | |
config.add_workflow(incoming_workflow, content_types=(IEnrollment,)) | |
# def enrollment_factory(request): | |
# enrollment = Enrollment() | |
# wf = get_workflow(request, 'incoming', IEnrollment) | |
# if not wf.has_state(enrollment): | |
# wf.initialize(enrollment) | |
# return enrollment | |
# @view_defaults(context=IEnrollment, request_method='GET', permission='view', renderer='...') | |
# class EnrollmentView(object): | |
# def __init__(self, context, request): | |
# self.wf = get_workflow(request, 'incoming', IEnrollment) | |
# self.context = context | |
# self.request = request | |
# | |
# @view_config(enrollment_state='incoming:new') | |
# def is_new(self): | |
# self.wf.transition(self.context, self.request, 'start') | |
# return {'status': u'Received'} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment