flows: add to api and add forms
This commit is contained in:
51
passbook/flows/api.py
Normal file
51
passbook/flows/api.py
Normal file
@ -0,0 +1,51 @@
|
||||
"""Flow API Views"""
|
||||
from rest_framework.serializers import ModelSerializer
|
||||
from rest_framework.viewsets import ModelViewSet
|
||||
|
||||
from passbook.flows.models import Flow, FlowFactorBinding
|
||||
|
||||
|
||||
class FlowSerializer(ModelSerializer):
|
||||
"""Flow Serializer"""
|
||||
|
||||
class Meta:
|
||||
|
||||
model = Flow
|
||||
fields = [
|
||||
"pk",
|
||||
"name",
|
||||
"slug",
|
||||
"designation",
|
||||
"factors",
|
||||
"policies"
|
||||
]
|
||||
|
||||
|
||||
class FlowViewSet(ModelViewSet):
|
||||
"""Flow Viewset"""
|
||||
|
||||
queryset = Flow.objects.all()
|
||||
serializer_class = FlowSerializer
|
||||
|
||||
|
||||
class FlowFactorBindingSerializer(ModelSerializer):
|
||||
"""FlowFactorBinding Serializer"""
|
||||
|
||||
class Meta:
|
||||
|
||||
model = FlowFactorBinding
|
||||
fields = [
|
||||
"pk",
|
||||
"flow",
|
||||
"factor",
|
||||
"re_evaluate_policies",
|
||||
"order",
|
||||
"policies"
|
||||
]
|
||||
|
||||
|
||||
class FlowFactorBindingViewSet(ModelViewSet):
|
||||
"""FlowFactorBinding Viewset"""
|
||||
|
||||
queryset = FlowFactorBinding.objects.all()
|
||||
serializer_class = FlowFactorBindingSerializer
|
||||
@ -1,3 +1,47 @@
|
||||
"""factor forms"""
|
||||
|
||||
from django import forms
|
||||
from django.contrib.admin.widgets import FilteredSelectMultiple
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from passbook.flows.models import Flow, FlowFactorBinding
|
||||
|
||||
GENERAL_FIELDS = ["name", "slug", "order", "policies", "enabled"]
|
||||
|
||||
|
||||
class FlowForm(forms.ModelForm):
|
||||
"""Flow Form"""
|
||||
|
||||
class Meta:
|
||||
|
||||
model = Flow
|
||||
fields = [
|
||||
"name",
|
||||
"slug",
|
||||
"designation",
|
||||
"factors",
|
||||
"policies",
|
||||
]
|
||||
widgets = {
|
||||
"name": forms.TextInput(),
|
||||
"factors": FilteredSelectMultiple(_("policies"), False),
|
||||
}
|
||||
|
||||
|
||||
class FlowFactorBindingForm(forms.ModelForm):
|
||||
"""FlowFactorBinding Form"""
|
||||
|
||||
class Meta:
|
||||
|
||||
model = FlowFactorBinding
|
||||
fields = [
|
||||
"flow",
|
||||
"factor",
|
||||
"re_evaluate_policies",
|
||||
"order",
|
||||
"policies",
|
||||
]
|
||||
widgets = {
|
||||
"name": forms.TextInput(),
|
||||
"factors": FilteredSelectMultiple(_("policies"), False),
|
||||
}
|
||||
|
||||
@ -80,7 +80,11 @@ class FlowExecutorView(View):
|
||||
# We don't save the Plan after getting the next factor
|
||||
# as it hasn't been successfully passed yet
|
||||
self.current_factor = self.plan.next()
|
||||
LOGGER.debug("Current factor", current_factor=self.current_factor, flow_slug=self.flow.slug)
|
||||
LOGGER.debug(
|
||||
"Current factor",
|
||||
current_factor=self.current_factor,
|
||||
flow_slug=self.flow.slug,
|
||||
)
|
||||
factor_cls = path_to_class(self.current_factor.type)
|
||||
self.current_factor_view = factor_cls(self)
|
||||
self.current_factor_view.request = request
|
||||
|
||||
Reference in New Issue
Block a user