Add workflow instance transitioning support, add workflow instance detail view
This commit is contained in:
@@ -3,7 +3,9 @@ from __future__ import unicode_literals
|
||||
from django import forms
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from .models import WorkflowState, WorkflowTransition
|
||||
from common.forms import DetailForm
|
||||
|
||||
from .models import WorkflowState, WorkflowInstance, WorkflowTransition
|
||||
|
||||
|
||||
class WorkflowStateForm(forms.ModelForm):
|
||||
@@ -13,7 +15,27 @@ class WorkflowStateForm(forms.ModelForm):
|
||||
|
||||
|
||||
class WorkflowTransitionForm(forms.ModelForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
workflow = kwargs.pop('workflow')
|
||||
super(WorkflowTransitionForm, self).__init__(*args, **kwargs)
|
||||
self.fields['origin_state'].queryset = self.fields['origin_state'].queryset.filter(workflow=workflow)
|
||||
self.fields['destination_state'].queryset = self.fields['destination_state'].queryset.filter(workflow=workflow)
|
||||
|
||||
class Meta:
|
||||
# TODO: restrict states to the ones of this workflow
|
||||
fields = ('label', 'origin_state', 'destination_state')
|
||||
model = WorkflowTransition
|
||||
|
||||
|
||||
class WorkflowInstanceTransitionForm(forms.Form):
|
||||
def __init__(self, *args, **kwargs):
|
||||
workflow = kwargs.pop('workflow')
|
||||
super(WorkflowInstanceTransitionForm, self).__init__(*args, **kwargs)
|
||||
self.fields['transition'].choices = workflow.get_transition_choices().values_list('pk', 'label')
|
||||
|
||||
transition = forms.ChoiceField(label=_('Transition'))
|
||||
|
||||
|
||||
class WorkflowInstanceDetailForm(DetailForm):
|
||||
class Meta:
|
||||
model = WorkflowInstance
|
||||
fields = ('workflow',)
|
||||
|
||||
Reference in New Issue
Block a user