2015-06-09 11:16:36 +00:00
|
|
|
from django import forms
|
2015-10-05 12:09:11 +00:00
|
|
|
|
2021-05-13 10:37:17 +00:00
|
|
|
from orchestra.forms.widgets import SpanWidget, PaddingCheckboxSelectMultiple
|
2015-06-09 11:16:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
class RouteForm(forms.ModelForm):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super(RouteForm, self).__init__(*args, **kwargs)
|
|
|
|
if self.instance:
|
|
|
|
self.fields['backend'].required = False
|
2015-10-05 12:09:11 +00:00
|
|
|
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
|
2021-05-13 10:37:17 +00:00
|
|
|
self.fields['async_actions'].widget = PaddingCheckboxSelectMultiple(45)
|
2015-10-05 12:09:11 +00:00
|
|
|
self.fields['async_actions'].choices = ((action, action) for action in actions)
|