django-orchestra/orchestra/contrib/orchestration/forms.py

21 lines
896 B
Python
Raw Permalink Normal View History

2023-07-09 07:51:51 +00:00
from django import forms
from orchestra.forms.widgets import SpanWidget, PaddingCheckboxSelectMultiple
class RouteForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(RouteForm, self).__init__(*args, **kwargs)
if self.instance:
self.fields['backend'].required = False
try:
backend_class = self.instance.backend_class
except KeyError:
self.fields['backend'].widget = SpanWidget(
display='<span style="color:red">%s NOT AVAILABLE</span>' % self.instance.backend)
else:
self.fields['backend'].widget = SpanWidget()
actions = backend_class.actions
self.fields['async_actions'].widget = PaddingCheckboxSelectMultiple(45)
self.fields['async_actions'].choices = ((action, action) for action in actions)