Add update action support
Partially implements blueprint mistral-dashboard-crud-operations Change-Id: I11241c2c5b8dd3e0f1115cf8bd7df160b7437f82
This commit is contained in:
parent
9f5ea7c56c
commit
386f8342a6
@ -78,3 +78,61 @@ class CreateForm(forms.SelfHandlingForm):
|
||||
msg = _('Failed to create action.')
|
||||
redirect = reverse('horizon:mistral:actions:index')
|
||||
exceptions.handle(request, msg, redirect=redirect)
|
||||
|
||||
|
||||
class UpdateForm(forms.SelfHandlingForm):
|
||||
definition_source = forms.ChoiceField(
|
||||
label=_('Definition Source'),
|
||||
choices=[('file', _('File')),
|
||||
('raw', _('Direct Input'))],
|
||||
widget=forms.Select(
|
||||
attrs={'class': 'switchable',
|
||||
'data-slug': 'definitionsource'})
|
||||
)
|
||||
definition_upload = forms.FileField(
|
||||
label=_('Definition File'),
|
||||
help_text=_('A local definition to upload.'),
|
||||
widget=forms.FileInput(
|
||||
attrs={'class': 'switched',
|
||||
'data-switch-on': 'definitionsource',
|
||||
'data-definitionsource-file': _('Definition File')}
|
||||
),
|
||||
required=False
|
||||
)
|
||||
definition_data = forms.CharField(
|
||||
label=_('Definition Data'),
|
||||
help_text=_('The raw contents of the definition.'),
|
||||
widget=forms.widgets.Textarea(
|
||||
attrs={'class': 'switched',
|
||||
'data-switch-on': 'definitionsource',
|
||||
'data-definitionsource-raw': _('Definition Data'),
|
||||
'rows': 4}
|
||||
),
|
||||
required=False
|
||||
)
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super(UpdateForm, self).clean()
|
||||
|
||||
if cleaned_data.get('definition_upload'):
|
||||
files = self.request.FILES
|
||||
cleaned_data['definition'] = files['definition_upload'].read()
|
||||
elif cleaned_data.get('definition_data'):
|
||||
cleaned_data['definition'] = cleaned_data['definition_data']
|
||||
else:
|
||||
raise forms.ValidationError(
|
||||
_('You must specify the definition source.'))
|
||||
|
||||
return cleaned_data
|
||||
|
||||
def handle(self, request, data):
|
||||
try:
|
||||
api.action_update(request, data['definition'])
|
||||
msg = _('Successfully updated action.')
|
||||
messages.success(request, msg)
|
||||
|
||||
return True
|
||||
except Exception:
|
||||
msg = _('Failed to update action.')
|
||||
redirect = reverse('horizon:mistral:actions:index')
|
||||
exceptions.handle(request, msg, redirect=redirect)
|
||||
|
@ -26,6 +26,14 @@ class CreateAction(tables.LinkAction):
|
||||
icon = "plus"
|
||||
|
||||
|
||||
class UpdateAction(tables.LinkAction):
|
||||
name = "update"
|
||||
verbose_name = _("Update Action")
|
||||
url = "horizon:mistral:actions:update"
|
||||
classes = ("ajax-modal",)
|
||||
icon = "pencil"
|
||||
|
||||
|
||||
def tags_to_string(action):
|
||||
return ', '.join(action.tags) if action.tags else None
|
||||
|
||||
@ -72,4 +80,4 @@ class ActionsTable(tables.DataTable):
|
||||
class Meta(object):
|
||||
name = "actions"
|
||||
verbose_name = _("Actions")
|
||||
table_actions = (CreateAction,)
|
||||
table_actions = (CreateAction, UpdateAction)
|
||||
|
7
mistraldashboard/actions/templates/actions/_update.html
Normal file
7
mistraldashboard/actions/templates/actions/_update.html
Normal file
@ -0,0 +1,7 @@
|
||||
{% extends "horizon/common/_modal_form.html" %}
|
||||
{% load i18n %}
|
||||
{% block form_attrs %}enctype="multipart/form-data"{% endblock %}
|
||||
{% block modal-body-right %}
|
||||
<h3>{% trans "Description:" %}</h3>
|
||||
<p>{% trans "Update action with the provided definition." %}</p>
|
||||
{% endblock %}
|
7
mistraldashboard/actions/templates/actions/update.html
Normal file
7
mistraldashboard/actions/templates/actions/update.html
Normal file
@ -0,0 +1,7 @@
|
||||
{% extends 'base.html' %}
|
||||
{% load i18n %}
|
||||
{% block title %}{% trans "Update Action" %}{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
{% include 'mistral/actions/_update.html' %}
|
||||
{% endblock %}
|
@ -24,4 +24,5 @@ urlpatterns = patterns(
|
||||
url(r'^$', views.IndexView.as_view(), name='index'),
|
||||
url(ACTIONS % 'detail', views.DetailView.as_view(), name='detail'),
|
||||
url(r'^create$', views.CreateView.as_view(), name='create'),
|
||||
url(r'^update$', views.UpdateView.as_view(), name='update'),
|
||||
)
|
||||
|
@ -37,6 +37,17 @@ class CreateView(forms.ModalFormView):
|
||||
page_title = _("Create Action")
|
||||
|
||||
|
||||
class UpdateView(forms.ModalFormView):
|
||||
template_name = 'mistral/actions/update.html'
|
||||
modal_header = _("Update Action")
|
||||
form_id = "update_action"
|
||||
form_class = mistral_forms.UpdateForm
|
||||
submit_label = _("Update")
|
||||
submit_url = reverse_lazy("horizon:mistral:actions:update")
|
||||
success_url = reverse_lazy('horizon:mistral:actions:index')
|
||||
page_title = _("Update Action")
|
||||
|
||||
|
||||
class IndexView(tables.DataTableView):
|
||||
table_class = ActionsTable
|
||||
template_name = 'mistral/actions/index.html'
|
||||
|
@ -212,3 +212,12 @@ def action_create(request, action_definition):
|
||||
"""
|
||||
|
||||
return mistralclient(request).actions.create(action_definition)
|
||||
|
||||
|
||||
def action_update(request, action_definition):
|
||||
"""Update action.
|
||||
|
||||
:param action_definition: Action definition
|
||||
"""
|
||||
|
||||
return mistralclient(request).actions.update(action_definition)
|
||||
|
Loading…
x
Reference in New Issue
Block a user