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

21 lines
896 B
Python
Raw Normal View History

2015-06-09 11:16:36 +00:00
from django import forms
2015-10-05 12:09:11 +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
self.fields['async_actions'].widget = paddingCheckboxSelectMultiple(45)
self.fields['async_actions'].choices = ((action, action) for action in actions)