Fix checkbox appearance in ModifyPackageForm.
And remove more obsolete code. Partially implements: blueprint service-defitions-migrate-to-apps-ui Change-Id: I94f40c3c53def47329118935ed0f5d2674daa0cb
This commit is contained in:
parent
5f28195f66
commit
bf6f1869cc
@ -75,12 +75,24 @@ class UploadPackageForm(SelfHandlingForm):
|
||||
redirect=redirect)
|
||||
|
||||
|
||||
class CheckboxInput(forms.CheckboxInput):
|
||||
def __init__(self):
|
||||
super(CheckboxInput, self).__init__(attrs={'class': 'checkbox'})
|
||||
|
||||
class Media:
|
||||
css = {'all': ('muranodashboard/css/checkbox.css',)}
|
||||
|
||||
|
||||
class ModifyPackageForm(SelfHandlingForm):
|
||||
name = forms.CharField(label=_('Name'))
|
||||
categories = forms.MultipleChoiceField(label=_('Categories'))
|
||||
tags = forms.CharField(label=_('Tags'), required=False)
|
||||
is_public = forms.BooleanField(label=_('Public'), required=False)
|
||||
enabled = forms.BooleanField(label=_('Active'), required=False)
|
||||
is_public = forms.BooleanField(label=_('Public'),
|
||||
required=False,
|
||||
widget=CheckboxInput)
|
||||
enabled = forms.BooleanField(label=_('Active'),
|
||||
required=False,
|
||||
widget=CheckboxInput)
|
||||
description = forms.CharField(label=_('Description'),
|
||||
widget=forms.Textarea,
|
||||
required=False)
|
||||
|
@ -1,93 +0,0 @@
|
||||
# Copyright (c) 2013 Mirantis, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import logging
|
||||
from django.utils.translation import ugettext as _
|
||||
from horizon import tables, workflows, forms
|
||||
from muranodashboard.dynamic_ui.forms import UpdatableFieldsForm
|
||||
from muranodashboard.dynamic_ui.fields import TableField
|
||||
from muranodashboard.dynamic_ui.fields import Column, CheckColumn
|
||||
from muranodashboard.dynamic_ui.fields import RadioColumn
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
STEP_NAMES = [('ui', _('UI Files')), ('workflows', _('Workflows')),
|
||||
('heat', _('Heat Templates')), ('agent', _('Agent Templates')),
|
||||
('scripts', _('Scripts'))]
|
||||
|
||||
|
||||
class CheckboxInput(forms.CheckboxInput):
|
||||
def __init__(self):
|
||||
super(CheckboxInput, self).__init__(attrs={'class': 'checkbox'})
|
||||
|
||||
|
||||
class Action(workflows.Action, UpdatableFieldsForm):
|
||||
def __init__(self, request, context, *args, **kwargs):
|
||||
super(Action, self).__init__(request, context, *args, **kwargs)
|
||||
self.update_fields(request=request)
|
||||
|
||||
|
||||
def make_table_cls(field_name):
|
||||
if field_name == 'ui':
|
||||
column_cls = RadioColumn
|
||||
else:
|
||||
column_cls = CheckColumn
|
||||
|
||||
class MetadataObjectsTableNoActions(tables.DataTable):
|
||||
filename = Column('filename', verbose_name=_('File Name'),
|
||||
table_name=field_name)
|
||||
path = Column('path', verbose_name=_('Path'), table_name=field_name)
|
||||
selected = column_cls('selected', verbose_name=_('Selected'),
|
||||
table_name=field_name)
|
||||
|
||||
class Meta:
|
||||
template = 'common/form-fields/data-grid/data_table.html'
|
||||
|
||||
return MetadataObjectsTableNoActions
|
||||
|
||||
|
||||
def make_files_step(field_name, step_verbose_name):
|
||||
field_instance = TableField(label=_('Selected Files'),
|
||||
table_class=make_table_cls(field_name),
|
||||
js_buttons=False)
|
||||
|
||||
class IntermediateAction(Action):
|
||||
def handle(self, request, context):
|
||||
files = []
|
||||
for item in context[field_name]:
|
||||
if item['selected']:
|
||||
if item.get('path'):
|
||||
files.append('{path}/{filename}'.format(**item))
|
||||
else:
|
||||
files.append(item['filename'])
|
||||
return {field_name: files}
|
||||
|
||||
class Meta:
|
||||
name = step_verbose_name
|
||||
|
||||
# action class name should be different for every different form,
|
||||
# otherwise they all look the same
|
||||
action_cls = type('FinalAction__%s' % field_name, (IntermediateAction,),
|
||||
{field_name: field_instance,
|
||||
'Meta': Meta})
|
||||
|
||||
class AddFileStep(workflows.Step):
|
||||
action_class = action_cls
|
||||
template_name = 'service_catalog/_workflow_step_files.html'
|
||||
contributes = (field_name,)
|
||||
|
||||
return AddFileStep
|
||||
|
||||
|
||||
FILE_STEPS = [make_files_step(field_name, step_verbose_name)
|
||||
for (field_name, step_verbose_name) in STEP_NAMES]
|
@ -14,7 +14,7 @@
|
||||
|
||||
import logging
|
||||
|
||||
from django.core.urlresolvers import reverse_lazy, reverse
|
||||
from django.core.urlresolvers import reverse_lazy
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from horizon import exceptions
|
||||
from horizon import tables
|
||||
|
@ -1,103 +0,0 @@
|
||||
# Copyright (c) 2013 Mirantis, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import logging
|
||||
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.forms import MediaDefiningClass, RegexField
|
||||
from .utils import Action, CheckboxInput, FILE_STEPS
|
||||
from horizon import exceptions
|
||||
from horizon import forms
|
||||
from horizon import workflows
|
||||
|
||||
from muranodashboard.dynamic_ui.metadata import metadataclient
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class EditManifest(Action):
|
||||
service_display_name = forms.CharField(label=_('Service Name'),
|
||||
required=True)
|
||||
full_service_name = forms.RegexField(
|
||||
r'^[a-zA-Z0-9.]+$',
|
||||
label=_('Fully Qualified Service Name'), required=True)
|
||||
author = forms.CharField(label=_('Author'))
|
||||
enabled = forms.BooleanField(label=_('Active'), initial=True,
|
||||
widget=CheckboxInput)
|
||||
description = forms.CharField(label=_('Description'),
|
||||
widget=forms.Textarea)
|
||||
service_version = forms.IntegerField(label=_('Version'), initial=0)
|
||||
|
||||
def __init__(self, request, context, *args, **kwargs):
|
||||
super(EditManifest, self).__init__(request, context, *args, **kwargs)
|
||||
# disable field with service_id for service being modified
|
||||
self.fields['service_version'].widget.attrs.update(
|
||||
{'disabled': True, })
|
||||
if context and context.get('full_service_name'):
|
||||
self.fields['full_service_name'].widget.attrs.update({
|
||||
'disabled': True,
|
||||
})
|
||||
|
||||
class Meta:
|
||||
name = _('Manifest')
|
||||
help_text_template = "service_catalog/_help_manifest.html"
|
||||
|
||||
|
||||
class EditManifestStep(workflows.Step):
|
||||
__metaclass__ = MediaDefiningClass
|
||||
action_class = EditManifest
|
||||
template_name = 'service_catalog/_workflow_step.html'
|
||||
contributes = ('service_display_name', 'full_service_name',
|
||||
'author', 'service_version', 'enabled', 'description')
|
||||
|
||||
# Workflow doesn't handle Media inner class of widgets for us, so we need
|
||||
# to inject media directly to the step
|
||||
class Media:
|
||||
css = {'all': ('muranodashboard/css/checkbox.css',
|
||||
'muranodashboard/css/tablefield.css')}
|
||||
js = ('muranodashboard/js/submit-disabled.js',)
|
||||
|
||||
|
||||
class ComposeService(workflows.Workflow):
|
||||
slug = "compose_service"
|
||||
name = _("Compose Service")
|
||||
finalize_button_name = _("Submit")
|
||||
success_message = _('Service "%s" created.')
|
||||
failure_message = _('Unable to create service "%s".')
|
||||
modify_success_message = _('Service "%s" modified.')
|
||||
modify_failure_message = _('Unable to modify service "%s".')
|
||||
success_url = "horizon:murano:service_catalog:index"
|
||||
default_steps = (EditManifestStep,) + tuple(FILE_STEPS)
|
||||
|
||||
def __init__(self, request=None, context_seed=None, *args, **kwargs):
|
||||
if context_seed and context_seed.get('full_service_name'):
|
||||
self.success_message = self.modify_success_message
|
||||
self.failure_message = self.modify_failure_message
|
||||
super(ComposeService, self).__init__(
|
||||
request, context_seed, *args, **kwargs)
|
||||
|
||||
def format_status_message(self, message):
|
||||
name = self.context.get('service_display_name', 'noname')
|
||||
return message % name
|
||||
|
||||
def handle(self, request, context):
|
||||
try:
|
||||
return metadataclient(request).metadata_admin.\
|
||||
create_or_update_service(context.get('full_service_name'),
|
||||
context)
|
||||
except Exception:
|
||||
name = self.context.get('service_display_name', 'noname')
|
||||
log.error("Unable to create/modify service {0}".format(name))
|
||||
exceptions.handle(request)
|
||||
return False
|
@ -1,14 +1,14 @@
|
||||
{% load custom_filters %}
|
||||
|
||||
{% for hidden in wizard.form.hidden_fields %}
|
||||
{% for hidden in form.hidden_fields %}
|
||||
{{ hidden }}
|
||||
{% endfor %}
|
||||
{% if wizard.form.non_field_errors %}
|
||||
{% if form.non_field_errors %}
|
||||
<div class="alert alert-message alert-error">
|
||||
{{ wizard.form.non_field_errors }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% for field in wizard.form.visible_fields %}
|
||||
{% for field in form.visible_fields %}
|
||||
<div class="control-group form-field clearfix{% if field.errors %} error{% endif %}">
|
||||
{% if field|is_checkbox %}
|
||||
{{ field }}{{ field.label_tag }}
|
||||
|
@ -10,7 +10,7 @@
|
||||
{% block modal-body %}
|
||||
<div class='left'>
|
||||
<fieldset>
|
||||
{% include 'horizon/common/_form_fields.html' %}
|
||||
{% include 'common/_form_fields.html' %}
|
||||
</fieldset>
|
||||
</div>
|
||||
<div class='right'>
|
||||
@ -25,6 +25,7 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block modal-footer %}
|
||||
{{ form.media }}
|
||||
<input class='btn btn-primary pull-right' type='submit' value='{% trans 'Submit' %}' />
|
||||
<a href="{% url 'horizon:murano:packages:index' %}" class="btn secondary cancel close">{% trans "Cancel" %}</a>
|
||||
{% endblock %}
|
||||
|
@ -20,7 +20,9 @@
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<fieldset>
|
||||
{% with form=wizard.form %}
|
||||
{% include "common/_form_fields.html" %}
|
||||
{% endwith %}
|
||||
</fieldset>
|
||||
{% endif %}
|
||||
<p class='italic'>{% blocktrans %} {{ extended_description }} {% endblocktrans %}</p>
|
||||
|
Loading…
Reference in New Issue
Block a user