Remove excessive 'slug' parameter from services.

Change-Id: I932674e2b789be54c4366a9a2b81ceaa0c37a133
Fixes: bug MRN-843.
This commit is contained in:
Timur Sufiev 2013-08-27 16:36:08 +04:00
parent c58274c80b
commit ca7b1b3954
4 changed files with 37 additions and 37 deletions

View File

@ -237,7 +237,7 @@ def services_list(request, environment_id):
for service_item in environment.services:
service_data = service_item
service_data['full_service_name'] = get_service_name(
service_data['slug'])
service_data['type'])
if service_data['id'] in reports and reports[service_data['id']]:
last_operation = str(reports[service_data['id']].text)
@ -327,6 +327,6 @@ def get_deployment_descr(request, environment_id, deployment_id):
if 'services' in descr:
for service in descr['services']:
service['full_service_name'] = get_service_name(
service['slug'])
service['type'])
return descr
return None

View File

@ -16,7 +16,6 @@ import os
import re
from django.conf import settings
from django.template.defaultfilters import slugify
from ordereddict import OrderedDict
import yaml
@ -91,35 +90,37 @@ def iterate_over_services():
import_all_services()
for service in sorted(_all_services.values(), key=lambda v: v.name):
yield slugify(service.name), service, service.forms
yield service.type, service, service.forms
def iterate_over_service_forms():
for slug, service, forms in iterate_over_services():
for srv_type, service, forms in iterate_over_services():
for step, form in enumerate(forms):
yield '{0}-{1}'.format(slug, step), form
yield '{0}-{1}'.format(srv_type, step), form
def with_service(slug, getter, default):
import_all_services()
match = re.match('(.*)-[0-9]+', slug)
def service_type_from_id(service_id):
match = re.match('(.*)-[0-9]+', service_id)
if match:
slug = match.group(1)
for _slug, service, forms in iterate_over_services():
if _slug == slug:
return match.group(1)
else: # if no number suffix found, it was service_type itself passed in
return service_id
def with_service(service_id, getter, default):
import_all_services()
service_type = service_type_from_id(service_id)
for srv_type, service, forms in iterate_over_services():
if srv_type == service_type:
return getter(service)
return default
def get_service_name(slug):
return with_service(slug, lambda service: service.name, '')
def get_service_name(service_id):
return with_service(service_id, lambda service: service.name, '')
def get_service_client(slug):
return with_service(slug, lambda service: service.type, None)
def get_service_field_descriptions(slug, index):
def get_service_field_descriptions(service_id, index):
def get_descriptions(service):
Form = service.forms[index]
descriptions = []
@ -128,7 +129,7 @@ def get_service_field_descriptions(slug, index):
title = field.get('descriptionTitle', field.get('label', ''))
descriptions.append((title, field['description']))
return descriptions
return with_service(slug, get_descriptions, [])
return with_service(service_id, get_descriptions, [])
def get_service_type(wizard):
@ -138,23 +139,22 @@ def get_service_type(wizard):
def get_service_choices():
return [(slug, service.name) for slug, service, forms in
return [(srv_type, service.name) for srv_type, service, forms in
iterate_over_services()]
def get_service_checkers():
import_all_services()
def make_comparator(slug):
def make_comparator(srv_id):
def compare(wizard):
match = re.match('(.*)-[0-9]+', slug)
return match and match.group(1) == get_service_type(wizard)
return service_type_from_id(srv_id) == get_service_type(wizard)
return compare
return [(slug, make_comparator(slug)) for slug, form
return [(srv_id, make_comparator(srv_id)) for srv_id, form
in iterate_over_service_forms()]
def get_service_descriptions():
return [(slug, service.description) for slug, service, forms in
return [(srv_type, service.description) for srv_type, service, forms in
iterate_over_services()]

View File

@ -39,7 +39,7 @@ from muranoclient.common.exceptions import HTTPUnauthorized, \
CommunicationError, HTTPInternalServerError, HTTPForbidden, HTTPNotFound
from muranodashboard.panel.services import get_service_descriptions, \
get_service_name, get_service_client, get_service_field_descriptions
get_service_name, get_service_field_descriptions
LOG = logging.getLogger(__name__)
@ -54,9 +54,8 @@ class Wizard(ModalFormMixin, SessionWizardView):
args=(environment_id,))
step0_data = form_list[0].cleaned_data
slug = step0_data.get('service', '')
attributes = {'type': get_service_client(slug),
'slug': slug}
service_type = step0_data.get('service', '')
attributes = {'type': service_type}
for form in form_list[1:]:
form.extract_attributes(attributes)
@ -79,7 +78,8 @@ class Wizard(ModalFormMixin, SessionWizardView):
_('Sorry, you can\'t create service right now.'),
redirect=redirect)
else:
message = "The %s service successfully created." % slug
message = "The %s service successfully created." % \
get_service_name(service_type)
messages.success(self.request, message)
return HttpResponseRedirect(url)
@ -94,11 +94,11 @@ class Wizard(ModalFormMixin, SessionWizardView):
context['service_descriptions'] = get_service_descriptions()
if self.steps.index > 0:
data = self.get_cleaned_data_for_step('service_choice')
slug = data['service']
service_type = data['service']
context['field_descriptions'] = get_service_field_descriptions(
slug, self.steps.index - 1)
context.update({'type': get_service_client(slug),
'service_name': get_service_name(slug)})
service_type, self.steps.index - 1)
context.update({'type': service_type,
'service_name': get_service_name(service_type)})
return context

View File

@ -33,8 +33,8 @@
{% endfor %}
{% else %}
<h3>{% trans "Description" %}:</h3>
{% for slug, description in service_descriptions %}
<p class="switchable" id="{{ slug }}">
{% for service_type, description in service_descriptions %}
<p class="switchable" id="{{ service_type }}">
{% autoescape off %} {% blocktrans %}
{{ description }}
{% endblocktrans %} {% endautoescape %}</p>