Resolve pep8 import issues

* H301 one import per line
* H302 import only modules
* H306  imports not in alphabetical order

Change-Id: I75d6f63515b6f5d6dc92d8cafd2176e0415c23f5
This commit is contained in:
Ekaterina Fedorova 2014-05-05 18:59:41 +04:00
parent dd52139e72
commit 310c69aeff
37 changed files with 301 additions and 258 deletions

View File

@ -1,10 +1,10 @@
#!/usr/bin/env python
import sys
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "muranodashboard.settings")
from django.core.management import execute_from_command_line
from django.core.management import execute_from_command_line # noqa
execute_from_command_line(sys.argv)

View File

@ -12,8 +12,9 @@
# License for the specific language governing permissions and limitations
# under the License.
import horizon
from django.utils.translation import ugettext_lazy as _
import horizon
from muranodashboard import dashboard

View File

@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from django.conf.urls import patterns, url
from django.conf import urls
from muranodashboard.catalog import views
from muranodashboard.dynamic_ui import services
@ -22,26 +22,26 @@ VIEW_MOD = 'muranodashboard.catalog.views'
wizard_view = views.Wizard.as_view(
services.get_app_forms, condition_dict=services.condition_getter)
urlpatterns = patterns(
urlpatterns = urls.patterns(
VIEW_MOD,
url(r'^index$', views.IndexView.as_view(), name='index'),
url(r'^index/(?P<category>[^/]+)/(?P<page>\d+)$',
urls.url(r'^index$', views.IndexView.as_view(), name='index'),
urls.url(r'^index/(?P<category>[^/]+)/(?P<page>\d+)$',
views.IndexView.as_view(),
name='index'),
url(r'^switch_environment/(?P<environment_id>[^/]+)$',
urls.url(r'^switch_environment/(?P<environment_id>[^/]+)$',
'switch',
name='switch_env'),
url(r'^add/(?P<environment_id>[^/]+)/(?P<app_id>[^/]+)$',
urls.url(r'^add/(?P<environment_id>[^/]+)/(?P<app_id>[^/]+)$',
wizard_view,
name='add'),
url(r'^add/(?P<environment_id>[^/]+)/(?P<app_id>[^/]+)/'
urls.url(r'^add/(?P<environment_id>[^/]+)/(?P<app_id>[^/]+)/'
r'(?P<do_redirect>[^/]+)/(?P<drop_wm_form>[^/]+)$',
wizard_view,
name='add_many'),
url(r'^quick-add/(?P<app_id>[^/]+)$',
urls.url(r'^quick-add/(?P<app_id>[^/]+)$',
'quick_deploy',
name='quick_add'),
url(r'^details/(?P<application_id>[^/]+)$',
urls.url(r'^details/(?P<application_id>[^/]+)$',
views.AppDetailsView.as_view(), name='application_details'),
url(r'^images/(?P<app_id>[^/]*)', 'get_image', name="images")
urls.url(r'^images/(?P<app_id>[^/]*)', 'get_image', name="images")
)

View File

@ -23,17 +23,17 @@ from django.conf import settings
from django.contrib import auth
from django.contrib.auth import decorators as auth_dec
from django.contrib.formtools.wizard import views as wizard_views
from django.core import urlresolvers as url
from django.core.urlresolvers import reverse
from django import http
from django import shortcuts
from django.utils import decorators as django_dec
from django.utils import http as http_utils
from django.utils.translation import ugettext_lazy as _ # noqa
from django.utils.translation import ugettext_lazy as _
from django.views.generic import list as list_view
from horizon import exceptions
from horizon.forms import views
from horizon import messages
from horizon import tabs
from horizon.forms import views
from horizon import exceptions
from muranoclient.common import exceptions as exc
from muranodashboard.catalog import tabs as catalog_tabs
@ -214,7 +214,7 @@ class Wizard(views.ModalFormMixin, LazyWizard):
def done(self, form_list, **kwargs):
environment_id = kwargs.get('environment_id')
env_url = url.reverse('horizon:murano:environments:services',
env_url = reverse('horizon:murano:environments:services',
args=(environment_id,))
app_name = services.get_service_name(self.request,
kwargs.get('app_id'))
@ -233,7 +233,7 @@ class Wizard(views.ModalFormMixin, LazyWizard):
else:
do_redirect = self.get_wizard_flag('do_redirect')
fail_url = url.reverse("horizon:murano:environments:index")
fail_url = reverse("horizon:murano:environments:index")
try:
srv = api.service_create(self.request, environment_id, attributes)
except exc.HTTPForbidden:
@ -266,7 +266,7 @@ class Wizard(views.ModalFormMixin, LazyWizard):
return response
else:
ns_url = 'horizon:murano:catalog:index'
return http.HttpResponseRedirect(url.reverse(ns_url))
return http.HttpResponseRedirect(reverse(ns_url))
def get_form_initial(self, step):
init_dict = {'request': self.request,

View File

@ -17,11 +17,11 @@ import functools
import logging
import os
from muranodashboard.environments.consts import CACHE_DIR
from muranodashboard.environments import consts
LOG = logging.getLogger(__name__)
OBJS_PATH = os.path.join(CACHE_DIR, 'apps')
OBJS_PATH = os.path.join(consts.CACHE_DIR, 'apps')
if not os.path.exists(OBJS_PATH):
os.makedirs(OBJS_PATH)

View File

@ -11,8 +11,10 @@
# 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 horizon
from django.utils.translation import ugettext_lazy as _
import horizon
from muranodashboard import exceptions
# prevent pyflakes from fail
assert exceptions

View File

@ -12,27 +12,28 @@
# License for the specific language governing permissions and limitations
# under the License.
import json
import copy
import json
import logging
import netaddr
import re
from django import forms
from django.core.validators import RegexValidator, validate_ipv4_address
from netaddr import all_matching_cidrs, IPNetwork, IPAddress
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import smart_text
from muranodashboard.environments import api
from horizon import exceptions, messages
from openstack_dashboard.api import glance
from openstack_dashboard.api.nova import novaclient
from django.template.defaultfilters import pluralize
import horizon.tables as tables
import horizon.forms as hz_forms
import floppyforms
from django.template.loader import render_to_string
from muranoclient.common import exceptions as muranoclient_exc
from django.core import validators as django_validator
from django import forms
from django.template import defaultfilters
from django.template import loader
from django.utils.encoding import smart_text
from django.utils.translation import ugettext_lazy as _
import floppyforms
from horizon import exceptions
from horizon import forms as hz_forms
from horizon import messages
from horizon import tables
from openstack_dashboard.api import glance
from openstack_dashboard.api import nova
from muranoclient.common import exceptions as muranoclient_exc
from muranodashboard.environments import api
LOG = logging.getLogger(__name__)
@ -75,7 +76,7 @@ def make_yaql_validator(field, form, key, validator_property):
def get_regex_validator(expr):
try:
validator = expr['validators'][0]
if isinstance(validator, RegexValidator):
if isinstance(validator, django_validator.RegexValidator):
return validator
except (TypeError, KeyError, IndexError):
pass
@ -194,7 +195,7 @@ class PasswordField(CharField):
password_re = re.compile('^.*(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[%s]).*$'
% special_characters)
has_clone = False
validate_password = RegexValidator(
validate_password = django_validator.RegexValidator(
password_re, _('The password must contain at least one letter, one \
number and one special character'), 'invalid')
@ -208,7 +209,7 @@ class PasswordField(CharField):
# do not run compare for hidden fields (they are not required)
if form_data.get(name) != form_data.get(self.get_clone_name(name)):
raise forms.ValidationError(_(u"{0}{1} don't match").format(
self.label, pluralize(2)))
self.label, defaultfilters.pluralize(2)))
class PasswordInput(forms.PasswordInput):
class Media:
@ -271,7 +272,7 @@ class Column(tables.Column):
'row_index': str(datum.id),
'table_name': table_name,
'column_name': self.name}
return render_to_string(self.template_name, context)
return loader.render_to_string(self.template_name, context)
_transform.__name__ = transform
transform = _transform
super(Column, self).__init__(transform, **kwargs)
@ -456,7 +457,7 @@ class FlavorChoiceField(ChoiceField):
@with_request
def update(self, request, **kwargs):
self.choices = [(flavor.name, flavor.name) for flavor in
novaclient(request).flavors.list()]
nova.novaclient(request).flavors.list()]
for flavor in self.choices:
if 'medium' in flavor[1]:
self.initial = flavor[0]
@ -468,7 +469,7 @@ class KeyPairChoiceField(ChoiceField):
@with_request
def update(self, request, **kwargs):
self.choices = [('', _('No keypair'))]
for keypair in novaclient(request).keypairs.list():
for keypair in nova.novaclient(request).keypairs.list():
self.choices.append((keypair.name, keypair.name))
@ -510,8 +511,8 @@ class AZoneChoiceField(ChoiceField):
@with_request
def update(self, request, **kwargs):
try:
availability_zones = novaclient(request).availability_zones.\
list(detailed=False)
availability_zones = nova.novaclient(
request).availability_zones.list(detailed=False)
except Exception:
availability_zones = []
exceptions.handle(request,
@ -552,12 +553,12 @@ class ClusterIPField(CharField):
@staticmethod
def make_nova_validator(request, ip_ranges):
def perform_checking(ip):
validate_ipv4_address(ip)
if not all_matching_cidrs(ip, ip_ranges) and ip_ranges:
django_validator.validate_ipv4_address(ip)
if not netaddr.all_matching_cidrs(ip, ip_ranges) and ip_ranges:
raise forms.ValidationError(_('Specified Cluster Static IP is'
' not in valid IP range'))
try:
ip_info = novaclient(request).fixed_ips.get(ip)
ip_info = nova.novaclient(request).fixed_ips.get(ip)
except exceptions.UNAUTHORIZED:
LOG.error("Error to get information about IP address"
" using novaclient")
@ -584,12 +585,13 @@ class ClusterIPField(CharField):
def make_neutron_validator(self):
def perform_checking(ip):
validate_ipv4_address(ip)
django_validator.validate_ipv4_address(ip)
if not self.existing_subnet:
raise forms.ValidationError(
_('Cannot get allowed subnet for the environment, '
'consult your admin'))
elif not IPAddress(ip) in IPNetwork(self.existing_subnet):
elif not netaddr.IPAddress(ip) in netaddr.IPNetwork(
self.existing_subnet):
raise forms.ValidationError(
_('Specified IP address should belong to {0} '
'subnet').format(self.existing_subnet))
@ -602,7 +604,7 @@ class ClusterIPField(CharField):
if self.network_topology == 'nova':
try:
network_list = novaclient(request).networks.list()
network_list = nova.novaclient(request).networks.list()
ip_ranges = [network.cidr for network in network_list]
ranges = ', '.join(ip_ranges)
except StandardError:
@ -621,11 +623,12 @@ class ClusterIPField(CharField):
self.validators = [self.make_neutron_validator()]
else: # 'flat' topology
raise NotImplementedError('Flat topology is not implemented yet')
self.error_messages['invalid'] = validate_ipv4_address.message
self.error_messages['invalid'] = \
django_validator.validate_ipv4_address.message
class DatabaseListField(CharField):
validate_mssql_identifier = RegexValidator(
validate_mssql_identifier = django_validator.RegexValidator(
re.compile(r'^[a-zA-z_][a-zA-Z0-9_$#@]*$'),
_((u'First symbol should be latin letter or underscore. Subsequent ' +
u'symbols can be latin letter, numeric, underscore, at sign, ' +

View File

@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import collections
from collections import defaultdict
import logging
import types
@ -29,7 +29,7 @@ from muranodashboard.dynamic_ui import yaql_functions
LOG = logging.getLogger(__name__)
class AnyFieldDict(collections.defaultdict):
class AnyFieldDict(defaultdict):
def __missing__(self, key):
return fields.make_select_cls(key)

View File

@ -12,29 +12,29 @@
# License for the specific language governing permissions and limitations
# under the License.
import logging
import os
import re
import yaml
import yaql
from muranodashboard.catalog import forms as catalog_forms
from muranodashboard.common import cache
from muranodashboard.dynamic_ui import helpers
from .helpers import decamelize
from muranodashboard.environments.consts import CACHE_DIR
from muranodashboard.dynamic_ui import version
from muranodashboard.dynamic_ui import yaql_expression
from muranodashboard.dynamic_ui import yaql_functions
from muranodashboard.catalog import forms as catalog_forms
from muranodashboard.common import cache
from muranodashboard.environments import consts
LOG = logging.getLogger(__name__)
if not os.path.exists(CACHE_DIR):
os.mkdir(CACHE_DIR)
LOG.info('Creating cache directory located at {dir}'.format(dir=CACHE_DIR))
LOG.info('Using cache directory located at {dir}'.format(dir=CACHE_DIR))
if not os.path.exists(consts.CACHE_DIR):
os.mkdir(consts.CACHE_DIR)
LOG.info('Creating cache directory located at {dir}'.format(
dir=consts.CACHE_DIR))
LOG.info('Using cache directory located at {dir}'.format(
dir=consts.CACHE_DIR))
class Service(object):
@ -178,7 +178,8 @@ def import_app(request, app_id):
ui_desc = _get(request, app_id)
version.check_version(ui_desc.pop('Version', 1))
service = dict((decamelize(k), v) for (k, v) in ui_desc.iteritems())
service = dict(
(helpers.decamelize(k), v) for (k, v) in ui_desc.iteritems())
services[app_id] = Service(**service)
app = services[app_id]

View File

@ -20,13 +20,13 @@ from django.contrib.messages import api as msg_api
from django.utils.encoding import force_unicode
from django.utils.translation import ugettext_lazy as _
from horizon import exceptions
from openstack_dashboard.api.base import url_for
from openstack_dashboard.api import base
import muranoclient.client as client
from muranoclient.common.exceptions import HTTPForbidden, HTTPNotFound
from consts import STATUS_ID_READY, STATUS_ID_NEW
from muranoclient.common import exceptions as exc
from muranodashboard.environments import topology
from muranodashboard.common import utils
from muranodashboard.environments import consts
from muranodashboard.environments import topology
LOG = logging.getLogger(__name__)
@ -76,7 +76,7 @@ def get_endpoint(request):
if not endpoint:
try:
endpoint = url_for(request, 'murano')
endpoint = base.url_for(request, 'murano')
except exceptions.ServiceCatalogException:
endpoint = 'http://localhost:8082'
LOG.warning('Murano API location could not be found in Service '
@ -163,7 +163,7 @@ class Session(object):
try:
session_data = \
muranoclient(request).sessions.get(environment_id, id)
except HTTPForbidden:
except exc.HTTPForbidden:
del sessions[environment_id]
LOG.debug("The environment is deploying by other user."
"Creating a new session "
@ -218,8 +218,8 @@ def environments_list(request):
environments[index].has_services = True
break
if not environments[index].has_services:
if environments[index].status == STATUS_ID_READY:
environments[index].status = STATUS_ID_NEW
if environments[index].status == consts.STATUS_ID_READY:
environments[index].status = consts.STATUS_ID_NEW
return environments
@ -271,7 +271,7 @@ def services_list(request, environment_id):
try:
reports = muranoclient(request).environments.last_status(
environment_id, session_id)
except HTTPNotFound:
except exc.HTTPNotFound:
reports = {}
for service_item in environment.services:

View File

@ -12,9 +12,9 @@
# License for the specific language governing permissions and limitations
# under the License.
import os
import tempfile
import os
from django.conf import settings

View File

@ -13,8 +13,9 @@
# under the License.
import logging
from muranodashboard.dynamic_ui.fields import get_murano_images, \
ImageChoiceField
from muranodashboard.dynamic_ui import fields
LOG = logging.getLogger(__name__)
@ -22,7 +23,7 @@ def filter_service_by_image_type(service, request):
def find_image_field():
for form_cls in service.forms:
for field in form_cls.base_fields.itervalues():
if isinstance(field, ImageChoiceField):
if isinstance(field, fields.ImageChoiceField):
return field
return None
@ -38,7 +39,7 @@ def filter_service_by_image_type(service, request):
return filtered, message
registered_murano_images = []
available_images = get_murano_images(request)
available_images = fields.get_murano_images(request)
for image in available_images:
registered_murano_images.append(image.murano_property.get('type'))

View File

@ -12,8 +12,9 @@
# License for the specific language governing permissions and limitations
# under the License.
import horizon
from django.utils.translation import ugettext_lazy as _
import horizon
from muranodashboard import dashboard

View File

@ -13,21 +13,16 @@
# under the License.
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _
from django import shortcuts
from django.utils.translation import ugettext_lazy as _
from horizon import exceptions
from horizon import tables
from horizon import messages
from horizon import tables
from muranodashboard.environments import api
from muranodashboard.environments import consts
from muranodashboard.openstack.common import timeutils
from consts import STATUS_ID_DEPLOYING
from consts import STATUS_CHOICES
from consts import STATUS_DISPLAY_CHOICES
from consts import STATUS_ID_NEW
from consts import DEPLOYMENT_STATUS_DISPLAY_CHOICES
def creation_allowed(self, request, environment):
@ -35,7 +30,7 @@ def creation_allowed(self, request, environment):
env = api.environment_get(request, environment_id)
status = getattr(env, 'status', None)
if status not in [STATUS_ID_DEPLOYING]:
if status not in [consts.STATUS_ID_DEPLOYING]:
return True
return False
@ -75,7 +70,7 @@ class DeleteEnvironment(tables.DeleteAction):
def allowed(self, request, environment):
if environment:
environment = api.environment_get(request, environment.id)
if environment.status == STATUS_ID_DEPLOYING:
if environment.status == consts.STATUS_ID_DEPLOYING:
deployment = api.deployments_list(request, environment.id)[0]
last_action = timeutils.parse_strtime(
deployment.started.replace(' ', 'T'),
@ -95,7 +90,7 @@ class EditEnvironment(tables.LinkAction):
def allowed(self, request, environment):
status = getattr(environment, 'status', None)
if status not in [STATUS_ID_DEPLOYING]:
if status not in [consts.STATUS_ID_DEPLOYING]:
return True
else:
return False
@ -110,7 +105,7 @@ class DeleteService(tables.DeleteAction):
env = api.environment_get(request, environment_id)
status = getattr(env, 'status', None)
return False if status == STATUS_ID_DEPLOYING else True
return False if status == consts.STATUS_ID_DEPLOYING else True
def action(self, request, service_id):
try:
@ -136,7 +131,7 @@ class DeployEnvironment(tables.BatchAction):
def allowed(self, request, environment):
status = getattr(environment, 'status', None)
if status == STATUS_ID_DEPLOYING:
if status == consts.STATUS_ID_DEPLOYING:
return False
if environment.version == 0 and not environment.has_services:
return False
@ -163,7 +158,7 @@ class DeployThisEnvironment(tables.Action):
status = getattr(env, 'status', None)
version = getattr(env, 'version', None)
if status == STATUS_ID_DEPLOYING:
if status == consts.STATUS_ID_DEPLOYING:
return False
services = self.table.data
if version == 0 and not services:
@ -215,7 +210,7 @@ class ShowDeployments(tables.LinkAction):
url = 'horizon:murano:environments:deployments'
def allowed(self, request, environment):
return environment.status != STATUS_ID_NEW
return environment.status != consts.STATUS_ID_NEW
class EnvironmentsTable(tables.DataTable):
@ -226,8 +221,8 @@ class EnvironmentsTable(tables.DataTable):
status = tables.Column('status',
verbose_name=_('Status'),
status=True,
status_choices=STATUS_CHOICES,
display_choices=STATUS_DISPLAY_CHOICES)
status_choices=consts.STATUS_CHOICES,
display_choices=consts.STATUS_DISPLAY_CHOICES)
class Meta:
name = 'murano'
@ -259,8 +254,8 @@ class ServicesTable(tables.DataTable):
status = tables.Column(lambda datum: datum['?'].get('status'),
verbose_name=_('Status'),
status=True,
status_choices=STATUS_CHOICES,
display_choices=STATUS_DISPLAY_CHOICES)
status_choices=consts.STATUS_CHOICES,
display_choices=consts.STATUS_DISPLAY_CHOICES)
operation = tables.Column('operation',
verbose_name=_('Last operation'))
operation_updated = tables.Column('operation_updated',
@ -299,10 +294,11 @@ class DeploymentsTable(tables.DataTable):
finished = tables.Column('finished',
verbose_name=_('Time Finished'))
status = tables.Column('state',
status = tables.Column(
'state',
verbose_name=_('Status'),
status=True,
display_choices=DEPLOYMENT_STATUS_DISPLAY_CHOICES)
display_choices=consts.DEPLOYMENT_STATUS_DISPLAY_CHOICES)
class Meta:
name = 'deployments'

View File

@ -15,14 +15,15 @@
import logging
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _
from django.utils.datastructures import SortedDict
from django.utils.translation import ugettext_lazy as _
from horizon import exceptions
from horizon import tabs
from muranoclient.common import exceptions as exc
from muranodashboard.environments import api
from muranodashboard.environments import consts
from muranodashboard.environments.tables import EnvConfigTable, ServicesTable
from muranodashboard.environments import tables
LOG = logging.getLogger(__name__)
@ -105,7 +106,7 @@ class EnvLogsTab(tabs.Tab):
class EnvConfigTab(tabs.TableTab):
name = _("Configuration")
slug = "env_config"
table_classes = (EnvConfigTable,)
table_classes = (tables.EnvConfigTable,)
template_name = 'horizon/common/_detail_table.html'
preload = False
@ -132,7 +133,7 @@ class EnvironmentTopologyTab(tabs.Tab):
class EnvironmentServicesTab(tabs.TableTab):
name = _("Components")
slug = "serviceslist"
table_classes = (ServicesTable,)
table_classes = (tables.ServicesTable,)
template_name = "services/_service_list.html"
preload = False

View File

@ -13,10 +13,10 @@
# under the License.
import json
import types
from django.template.loader import render_to_string
from django.contrib.staticfiles.templatetags.staticfiles import static
from django.template import loader
def _get_environment_status_message(entity):
@ -58,7 +58,7 @@ def _application_info(application, app_image, status):
'type': _truncate_type(application['?']['type'], 45),
'status': status,
'app_image': app_image}
return render_to_string('services/_application_info.html',
return loader.render_to_string('services/_application_info.html',
context)
@ -68,13 +68,13 @@ def _unit_info(unit, unit_image):
context = {'data': data,
'unit_image': unit_image}
return render_to_string('services/_unit_info.html', context)
return loader.render_to_string('services/_unit_info.html', context)
def _environment_info(environment, status):
context = {'name': environment.name,
'status': status}
return render_to_string('services/_environment_info.html',
return loader.render_to_string('services/_environment_info.html',
context)

View File

@ -12,46 +12,46 @@
# License for the specific language governing permissions and limitations
# under the License.
from django.conf.urls import patterns, url
from django.conf import urls
from openstack_dashboard.dashboards.project.instances import views as inst_view
from views import IndexView, DeploymentDetailsView
from views import JSONView, EnvironmentDetails
from views import CreateEnvironmentView
from views import DetailServiceView
from views import DeploymentsView
from views import EditEnvironmentView
from openstack_dashboard.dashboards.project.instances.views import DetailView
from muranodashboard.environments import views
VIEW_MOD = 'muranodashboard.environments.views'
ENVIRONMENT_ID = r'^(?P<environment_id>[^/]+)'
urlpatterns = patterns(
urlpatterns = urls.patterns(
VIEW_MOD,
url(r'^environments$', IndexView.as_view(), name='index'),
urls.url(r'^environments$', views.IndexView.as_view(), name='index'),
url(r'^create_environment$', CreateEnvironmentView.as_view(),
urls.url(r'^create_environment$', views.CreateEnvironmentView.as_view(),
name='create_environment'),
url(ENVIRONMENT_ID + r'/update_environment$',
EditEnvironmentView.as_view(),
urls.url(ENVIRONMENT_ID + r'/update_environment$',
views.EditEnvironmentView.as_view(),
name='update_environment'),
url(ENVIRONMENT_ID + r'/services$', EnvironmentDetails.as_view(),
urls.url(ENVIRONMENT_ID + r'/services$',
views.EnvironmentDetails.as_view(),
name='services'),
url(ENVIRONMENT_ID + r'/services/get_d3_data$',
JSONView.as_view(), name='d3_data'),
urls.url(ENVIRONMENT_ID + r'/services/get_d3_data$',
views.JSONView.as_view(), name='d3_data'),
url(ENVIRONMENT_ID + r'/(?P<service_id>[^/]+)/$',
DetailServiceView.as_view(),
urls.url(ENVIRONMENT_ID + r'/(?P<service_id>[^/]+)/$',
views.DetailServiceView.as_view(),
name='service_details'),
url(r'^(?P<instance_id>[^/]+)/$', DetailView.as_view(), name='detail'),
urls.url(r'^(?P<instance_id>[^/]+)/$',
inst_view.DetailView.as_view(),
name='detail'),
url(ENVIRONMENT_ID + r'/deployments$',
DeploymentsView.as_view(), name='deployments'),
urls.url(ENVIRONMENT_ID + r'/deployments$',
views.DeploymentsView.as_view(),
name='deployments'),
url(ENVIRONMENT_ID + r'/deployments/(?P<deployment_id>[^/]+)$',
DeploymentDetailsView.as_view(), name='deployment_details'),
urls.url(ENVIRONMENT_ID + r'/deployments/(?P<deployment_id>[^/]+)$',
views.DeploymentDetailsView.as_view(),
name='deployment_details'),
)

View File

@ -14,18 +14,20 @@
import logging
from django.core import urlresolvers as url
from django.utils.translation import ugettext_lazy as _ # noqa
from django.http import HttpResponse
from django.core.urlresolvers import reverse
from django.core.urlresolvers import reverse_lazy
from django import http
from django.utils.translation import ugettext_lazy as _
from django.views import generic
from horizon import exceptions
from horizon import tabs
from horizon import tables
from horizon import tabs
from horizon import workflows
from muranoclient.common import exceptions as exc
from muranodashboard.environments import api
from muranodashboard.environments import tabs as env_tabs
from muranodashboard.environments import tables as env_tables
from muranodashboard.environments import tabs as env_tabs
from muranodashboard.environments import workflows as env_workflows
@ -68,7 +70,7 @@ class EnvironmentDetails(tabs.TabbedTableView):
except Exception:
msg = _("Sorry, this environment doesn't exist anymore")
redirect = url.reverse("horizon:murano:environments:index")
redirect = reverse("horizon:murano:environments:index")
exceptions.handle(self.request, msg, redirect=redirect)
return context
@ -96,7 +98,7 @@ class DetailServiceView(tabs.TabView):
exceptions.handle(self.request)
except exc.HTTPForbidden:
redirect = url.reverse('horizon:murano:environments:index')
redirect = reverse('horizon:murano:environments:index')
exceptions.handle(self.request,
_('Unable to retrieve details for '
'service'),
@ -124,7 +126,7 @@ class CreateEnvironmentView(workflows.WorkflowView):
class EditEnvironmentView(workflows.WorkflowView):
workflow_class = env_workflows.UpdateEnvironment
template_name = 'environments/update.html'
success_url = url.reverse_lazy("horizon:murano:environments:index")
success_url = reverse_lazy("horizon:murano:environments:index")
def get_context_data(self, **kwargs):
context = super(EditEnvironmentView, self).get_context_data(**kwargs)
@ -138,7 +140,7 @@ class EditEnvironmentView(workflows.WorkflowView):
self._object = \
api.environment_get(self.request, environment_id)
except Exception:
redirect = url.reverse("horizon:murano:environments:index")
redirect = reverse("horizon:murano:environments:index")
msg = _('Unable to retrieve environment details.')
exceptions.handle(self.request, msg, redirect=redirect)
return self._object
@ -162,7 +164,7 @@ class DeploymentsView(tables.DataTableView):
context['environment_name'] = env.name
except Exception:
msg = _("Sorry, this environment doesn't exist anymore")
redirect = url.reverse("horizon:murano:environments:index")
redirect = reverse("horizon:murano:environments:index")
exceptions.handle(self.request, msg, redirect=redirect)
return context
@ -176,13 +178,13 @@ class DeploymentsView(tables.DataTableView):
except exc.HTTPForbidden:
msg = _('Unable to retrieve list of deployments')
exceptions.handle(self.request, msg, redirect=url.reverse(ns_url))
exceptions.handle(self.request, msg, redirect=reverse(ns_url))
except exc.HTTPInternalServerError:
msg = _("Environment with id %s doesn't exist anymore")
exceptions.handle(self.request,
msg % self.environment_id,
redirect=url.reverse(ns_url))
redirect=reverse(ns_url))
return deployments
@ -210,7 +212,7 @@ class DeploymentDetailsView(tabs.TabbedTableView):
self.deployment_id)
except (exc.HTTPInternalServerError, exc.HTTPNotFound):
msg = _("Deployment with id %s doesn't exist anymore")
redirect = url.reverse("horizon:murano:environments:deployments")
redirect = reverse("horizon:murano:environments:deployments")
exceptions.handle(self.request,
msg % self.deployment_id,
redirect=redirect)
@ -224,7 +226,7 @@ class DeploymentDetailsView(tabs.TabbedTableView):
self.deployment_id)
except (exc.HTTPInternalServerError, exc.HTTPNotFound):
msg = _('Deployment with id %s doesn\'t exist anymore')
redirect = url.reverse("horizon:murano:environments:deployments")
redirect = reverse("horizon:murano:environments:deployments")
exceptions.handle(self.request,
msg % self.deployment_id,
redirect=redirect)
@ -244,4 +246,4 @@ class JSONView(generic.View):
@staticmethod
def get(request, **kwargs):
data = api.load_environment_data(request, kwargs['environment_id'])
return HttpResponse(data, content_type='application/json')
return http.HttpResponse(data, content_type='application/json')

View File

@ -15,7 +15,7 @@
import logging
from django.core import validators
from django.utils.translation import ugettext as _
from django.utils.translation import ugettext_lazy as _
from horizon import exceptions
from horizon import forms

View File

@ -12,13 +12,14 @@
# License for the specific language governing permissions and limitations
# under the License.
import logging
import json
import logging
from django import forms
from django.utils.translation import ugettext_lazy as _
from django.forms import ValidationError
from horizon.forms import SelfHandlingForm
from horizon import messages, exceptions
from horizon import exceptions
from horizon import forms as horizon_forms
from horizon import messages
from openstack_dashboard.api import glance
LOG = logging.getLogger(__name__)
@ -44,7 +45,7 @@ def filter_murano_images(images, request=None):
return marked_images
class MarkImageForm(SelfHandlingForm):
class MarkImageForm(horizon_forms.SelfHandlingForm):
_metadata = {
'windows.2012': ' Windows Server 2012',
'linux': 'Generic Linux',
@ -94,7 +95,7 @@ class MarkImageForm(SelfHandlingForm):
title = cleaned_data.get('title')
existing_titles = self.fields['existing_titles'].initial
if title in existing_titles:
raise ValidationError(_('Specified title already in use.'
raise forms.ValidationError(_('Specified title already in use.'
' Please choose another one.'))
return title

View File

@ -12,8 +12,9 @@
# License for the specific language governing permissions and limitations
# under the License.
import horizon
from django.utils.translation import ugettext_lazy as _
import horizon
from muranodashboard import dashboard

View File

@ -11,8 +11,8 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ugettext_lazy as _
from horizon import exceptions
from horizon import tables
from openstack_dashboard.api import glance

View File

@ -12,20 +12,19 @@
# License for the specific language governing permissions and limitations
# under the License.
from django.conf.urls import patterns, url
from .views import MarkedImagesView, MarkImageView
from django.conf import urls
from muranodashboard.images import views
urlpatterns = patterns(
urlpatterns = urls.patterns(
'',
url(r'^$', MarkedImagesView.as_view(),
urls.url(r'^$', views.MarkedImagesView.as_view(),
name='index'),
url(r'^mark_image$', MarkImageView.as_view(),
urls.url(r'^mark_image$', views.MarkImageView.as_view(),
name='mark_image'),
url(r'^remove_metadata$', MarkedImagesView.as_view(),
urls.url(r'^remove_metadata$', views.MarkedImagesView.as_view(),
name='remove_metadata'),
)

View File

@ -12,19 +12,21 @@
# License for the specific language governing permissions and limitations
# under the License.
from django.core.urlresolvers import reverse, reverse_lazy
from django.core.urlresolvers import reverse
from django.core.urlresolvers import reverse_lazy
from django.utils.translation import ugettext_lazy as _
from openstack_dashboard.api import glance
from horizon import exceptions
from horizon import tables
from horizon.forms.views import ModalFormView
from .tables import MarkedImagesTable
from .forms import MarkImageForm, filter_murano_images
from horizon.forms import views
from horizon import tables as horizon_tables
from openstack_dashboard.api import glance
from muranodashboard.images import forms
from muranodashboard.images import tables
class MarkedImagesView(tables.DataTableView):
table_class = MarkedImagesTable
class MarkedImagesView(horizon_tables.DataTableView):
table_class = tables.MarkedImagesTable
template_name = 'images/index.html'
def get_data(self):
@ -36,11 +38,11 @@ class MarkedImagesView(tables.DataTableView):
uri = reverse('horizon:murano:images:index')
exceptions.handle(self.request, msg, redirect=uri)
return filter_murano_images(images, request=self.request)
return forms.filter_murano_images(images, request=self.request)
class MarkImageView(ModalFormView):
form_class = MarkImageForm
class MarkImageView(views.ModalFormView):
form_class = forms.MarkImageForm
template_name = 'images/mark.html'
context_object_name = 'image'
success_url = reverse_lazy('horizon:murano:images:index')

View File

@ -11,17 +11,20 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from horizon.middleware import HorizonMiddleware
from horizon.exceptions import Http302
import traceback
import logging
import traceback
from horizon import exceptions
from horizon import middleware
logger = logging.getLogger(__name__)
class ExceptionMiddleware(HorizonMiddleware):
class ExceptionMiddleware(middleware.HorizonMiddleware):
def process_exception(self, request, exception):
if not isinstance(exception, Http302):
if not isinstance(exception, exceptions.Http302):
logger.error(traceback.format_exc())
return super(ExceptionMiddleware, self).process_exception(
request, exception)

View File

@ -11,19 +11,21 @@
# 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 import forms
from django.core.files import uploadedfile
from django.utils.translation import ugettext_lazy as _
from django.core.urlresolvers import reverse
from django.conf import settings
from horizon.forms import SelfHandlingForm
from django.core.files import uploadedfile
from django.core.urlresolvers import reverse
from django import forms
from django.utils.translation import ugettext_lazy as _
from horizon import exceptions
from horizon import forms as horizon_forms
from horizon import messages
from muranoclient.common.exceptions import HTTPException
from muranodashboard.environments import api
from muranoclient.common import exceptions as exc
from muranodashboard.catalog import views
from muranodashboard.environments import api
LOG = logging.getLogger(__name__)
@ -45,7 +47,7 @@ def split_post_data(post):
return data, files
class UploadPackageForm(SelfHandlingForm):
class UploadPackageForm(horizon_forms.SelfHandlingForm):
package = forms.FileField(label=_('Application .zip package'),
required=True)
categories = forms.MultipleChoiceField(label=_('Application Category'),
@ -80,7 +82,7 @@ class UploadPackageForm(SelfHandlingForm):
return _handle(request, app_id=package.id)
except HTTPException:
except exc.HTTPException:
LOG.exception(_('Uploading package failed'))
redirect = reverse('horizon:murano:packages:index')
exceptions.handle(request,
@ -96,7 +98,7 @@ class CheckboxInput(forms.CheckboxInput):
css = {'all': ('muranodashboard/css/checkbox.css',)}
class ModifyPackageForm(SelfHandlingForm):
class ModifyPackageForm(horizon_forms.SelfHandlingForm):
name = forms.CharField(label=_('Name'))
categories = forms.MultipleChoiceField(label=_('Categories'))
tags = forms.CharField(label=_('Tags'), required=False)
@ -125,7 +127,7 @@ class ModifyPackageForm(SelfHandlingForm):
result = api.muranoclient(request).packages.update(app_id, data)
messages.success(request, _('Package modified.'))
return result
except HTTPException:
except exc.HTTPException:
LOG.exception(_('Modifying package failed'))
redirect = reverse('horizon:murano:packages:index')
exceptions.handle(request,

View File

@ -12,8 +12,9 @@
# License for the specific language governing permissions and limitations
# under the License.
import horizon
from django.utils.translation import ugettext_lazy as _
import horizon
from muranodashboard import dashboard

View File

@ -14,13 +14,14 @@
import logging
from django.utils.translation import ugettext_lazy as _
from django.core.urlresolvers import reverse
from django.http import HttpResponse
from django import http
from django.template import defaultfilters
from django.utils.translation import ugettext_lazy as _
from horizon import exceptions
from horizon import tables
from horizon import messages
from horizon import tables
from muranoclient.common import exceptions as exc
from muranodashboard.environments import api
@ -63,7 +64,7 @@ class DownloadPackage(tables.Action):
body = api.muranoclient(request).packages.download(app_id)
content_type = 'application/octet-stream'
response = HttpResponse(body, content_type=content_type)
response = http.HttpResponse(body, content_type=content_type)
response['Content-Disposition'] = 'filename={name}.package'.format(
name=self.get_package_name(data_table, app_id))
return response

View File

@ -12,23 +12,21 @@
# License for the specific language governing permissions and limitations
# under the License.
from django.conf.urls import patterns, url
from django.conf import urls
from .views import PackageDefinitionsView
from .views import UploadPackageView
from .views import ModifyPackageView
from muranodashboard.packages import views
urlpatterns = patterns(
urlpatterns = urls.patterns(
'',
url(r'^$', PackageDefinitionsView.as_view(),
urls.url(r'^$', views.PackageDefinitionsView.as_view(),
name='index'),
url(r'^upload$', UploadPackageView.as_view(),
urls.url(r'^upload$', views.UploadPackageView.as_view(),
name='upload'),
url(r'^modify/(?P<app_id>[^/]+)?$',
ModifyPackageView.as_view(),
urls.url(r'^modify/(?P<app_id>[^/]+)?$',
views.ModifyPackageView.as_view(),
name='modify'),
)

View File

@ -15,16 +15,18 @@
import logging
from django.core.urlresolvers import reverse_lazy
from horizon import tables
from horizon.forms.views import ModalFormView
from .tables import PackageDefinitionsTable
from muranodashboard.packages import forms
from horizon.forms import views
from horizon import tables as horizon_tables
from muranodashboard.environments import api
from muranodashboard.packages import forms
from muranodashboard.packages import tables
LOG = logging.getLogger(__name__)
class PackageDefinitionsView(tables.DataTableView):
table_class = PackageDefinitionsTable
class PackageDefinitionsView(horizon_tables.DataTableView):
table_class = tables.PackageDefinitionsTable
template_name = 'packages/index.html'
def get_data(self):
@ -37,7 +39,7 @@ class PackageDefinitionsView(tables.DataTableView):
return pkgs
class UploadPackageView(ModalFormView):
class UploadPackageView(views.ModalFormView):
form_class = forms.UploadPackageForm
template_name = 'packages/upload_package.html'
context_object_name = 'packages'
@ -45,7 +47,7 @@ class UploadPackageView(ModalFormView):
failure_url = reverse_lazy('horizon:murano:packages:index')
class ModifyPackageView(ModalFormView):
class ModifyPackageView(views.ModalFormView):
form_class = forms.ModifyPackageForm
template_name = 'packages/modify_package.html'
success_url = reverse_lazy('horizon:murano:packages:index')

View File

@ -1,7 +1,7 @@
import logging
import os
import tempfile
import sys
import tempfile
from openstack_dashboard import exceptions
@ -137,6 +137,8 @@ SESSION_COOKIE_HTTPONLY = True
SESSION_EXPIRE_AT_BROWSER_CLOSE = True
SESSION_COOKIE_SECURE = False
SECRET_KEY = 'some_random_value'
gettext_noop = lambda s: s
LANGUAGES = (
('en', gettext_noop('English')),

View File

@ -11,10 +11,12 @@
# 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 muranodashboard.common import utils
from muranodashboard.environments import api
from muranodashboard.environments import consts
from muranodashboard.common import utils
LOG = logging.getLogger(__name__)

View File

@ -12,8 +12,9 @@
# License for the specific language governing permissions and limitations
# under the License.
import horizon
from django.utils.translation import ugettext_lazy as _
import horizon
from muranodashboard import dashboard

View File

@ -12,8 +12,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from horizon import tabs
from django.utils.translation import ugettext_lazy as _
from horizon import tabs
from muranodashboard.stats import models

View File

@ -12,12 +12,13 @@
# License for the specific language governing permissions and limitations
# under the License.
from django.conf.urls import patterns, url
from django.conf import urls
from muranodashboard.stats import views
VIEW_MOD = "muranodashboard.stats.views"
urlpatterns = patterns(
urlpatterns = urls.patterns(
VIEW_MOD,
url(r'^view$', views.StatsView.as_view(), name="index"))
urls.url(r'^view$', views.StatsView.as_view(), name="index"))

View File

@ -1,12 +1,12 @@
from django import forms
from django import template
from django.forms import CheckboxInput
register = template.Library()
@register.filter(name='is_checkbox')
def is_checkbox(field):
return isinstance(field.field.widget, CheckboxInput)
return isinstance(field.field.widget, forms.CheckboxInput)
@register.filter(name='firsthalf')

28
tox.ini
View File

@ -12,6 +12,7 @@ setenv = VIRTUAL_ENV={envdir}
NOSE_OPENSTACK_RED=0.05
NOSE_OPENSTACK_YELLOW=0.025
NOSE_OPENSTACK_SHOW_ELAPSED=1
DJANGO_SETTINGS_MODULE=muranodashboard.settings
deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
http://tarballs.openstack.org/horizon/horizon-stable-icehouse.tar.gz
@ -36,11 +37,28 @@ commands = flake8
downloadcache = ~/cache/pip
[flake8]
# H301 one import per line
# H302 import only modules
# H306 imports not in alphabetical order
# H701 Empty localization string
ignore = H301,H302,H306,H701
ignore = H701
show-source = true
builtins = _
exclude=.build,.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,tools
exclude=.build,.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,tools,*/local/*,horizon
[hacking]
import_exceptions = collections.defaultdict,
django.conf.settings,
django.contrib.staticfiles.templatetags.staticfiles.static,
django.core.urlresolvers.reverse,
django.core.urlresolvers.reverse_lazy,
django.template.loader.render_to_string,
django.test.utils.override_settings,
django.utils.datastructures.SortedDict,
django.utils.encoding.force_unicode,
django.utils.encoding.smart_text,
django.utils.html.escape,
django.utils.http.urlencode,
django.utils.safestring.mark_safe,
django.utils.translation.pgettext_lazy,
django.utils.translation.ugettext_lazy,
django.utils.translation.ungettext_lazy,
operator.attrgetter,
StringIO.StringIO