diff --git a/horizon/horizon/api/nova.py b/horizon/horizon/api/nova.py index 1802d1a48d..d523efd40c 100644 --- a/horizon/horizon/api/nova.py +++ b/horizon/horizon/api/nova.py @@ -103,7 +103,7 @@ class ServerAttributes(APIDictWrapper): Preserves the request info so image name can later be retrieved """ - _attrs = ['description', 'disk_gb', 'host', 'image_ref', 'kernel_id', + _attrs = ['disk_gb', 'host', 'image_ref', 'kernel_id', 'key_name', 'launched_at', 'mac_address', 'memory_mb', 'name', 'os_type', 'tenant_id', 'ramdisk_id', 'scheduled_at', 'terminated_at', 'user_data', 'user_id', 'vcpus', 'hostname', @@ -231,12 +231,11 @@ def server_delete(request, instance): def server_get(request, instance_id): - return Server(extras_api(request).servers.get(instance_id), request) + return Server(novaclient(request).servers.get(instance_id), request) -@check_openstackx def server_list(request): - return [Server(s, request) for s in extras_api(request).servers.list()] + return [Server(s, request) for s in novaclient(request).servers.list()] @check_openstackx @@ -251,10 +250,8 @@ def server_reboot(request, server.reboot(hardness) -def server_update(request, instance_id, name, description): - return extras_api(request).servers.update(instance_id, - name=name, - description=description) +def server_update(request, instance_id, name): + return novaclient(request).servers.update(instance_id, name=name) def server_add_floating_ip(request, server, address): diff --git a/horizon/horizon/context_processors.py b/horizon/horizon/context_processors.py index eccb0452a8..6f3c8af684 100644 --- a/horizon/horizon/context_processors.py +++ b/horizon/horizon/context_processors.py @@ -46,8 +46,12 @@ def horizon(request): ``network_configured`` Boolean. Will be ``True`` if ``settings.QUANTUM_ENABLED`` is ``True``. + + Additionally, it sets the names ``True`` and ``False`` in the context + to their boolean equivalents for convenience. """ - context = {} + context = {"True": True, + "False": False} # Auth/Keystone context context.setdefault('authorized_tenants', []) diff --git a/horizon/horizon/dashboards/nova/images/forms.py b/horizon/horizon/dashboards/nova/images/forms.py index 806d06210b..14e07b559f 100644 --- a/horizon/horizon/dashboards/nova/images/forms.py +++ b/horizon/horizon/dashboards/nova/images/forms.py @@ -65,7 +65,7 @@ class UpdateImageForm(forms.SelfHandlingForm): LOG.exception(error_retrieving) messages.error(request, error_retrieving) - if image.owner == request.user.username: + if image.owner == request.user.tenant_id: try: meta = { 'is_public': True, diff --git a/horizon/horizon/dashboards/nova/images/views.py b/horizon/horizon/dashboards/nova/images/views.py index 12e3ef3b6b..c2b12b48c3 100644 --- a/horizon/horizon/dashboards/nova/images/views.py +++ b/horizon/horizon/dashboards/nova/images/views.py @@ -46,8 +46,6 @@ def index(request): unused, handled = f.maybe_handle(request) if handled: return handled - delete_form = DeleteImage() - all_images = [] try: all_images = api.image_list_detailed(request) @@ -67,9 +65,12 @@ def index(request): images = [im for im in all_images if im['container_format'] not in ['aki', 'ari']] + quotas = api.tenant_quota_get(request, request.user.tenant_id) + return shortcuts.render(request, 'nova/images/index.html', { - 'delete_form': delete_form, + 'delete_form': DeleteImage(), + 'quotas': quotas, 'images': images}) diff --git a/horizon/horizon/dashboards/nova/instances/forms.py b/horizon/horizon/dashboards/nova/instances/forms.py index 1296008e89..70d6fc3052 100644 --- a/horizon/horizon/dashboards/nova/instances/forms.py +++ b/horizon/horizon/dashboards/nova/instances/forms.py @@ -82,16 +82,13 @@ class UpdateInstance(forms.SelfHandlingForm): instance = forms.CharField(widget=forms.TextInput( attrs={'readonly': 'readonly'})) name = forms.CharField(required=True) - description = forms.CharField(required=False) def handle(self, request, data): tenant_id = data['tenant_id'] - description = data.get('description', '') try: api.server_update(request, data['instance'], - data['name'], - description) + data['name']) messages.success(request, _("Instance '%s' updated") % data['name']) except api_exceptions.ApiException, e: diff --git a/horizon/horizon/dashboards/nova/instances/views.py b/horizon/horizon/dashboards/nova/instances/views.py index 75b975e2ef..9674b97fbf 100644 --- a/horizon/horizon/dashboards/nova/instances/views.py +++ b/horizon/horizon/dashboards/nova/instances/views.py @@ -209,8 +209,7 @@ def update(request, instance_id): form, handled = UpdateInstance.maybe_handle(request, initial={ 'instance': instance_id, 'tenant_id': tenant_id, - 'name': instance.name, - 'description': instance.attrs['description']}) + 'name': instance.name}) if handled: return handled diff --git a/horizon/horizon/dashboards/nova/templates/nova/containers/_create.html b/horizon/horizon/dashboards/nova/templates/nova/containers/_create.html index c82d716cc8..1fd10b3862 100644 --- a/horizon/horizon/dashboards/nova/templates/nova/containers/_create.html +++ b/horizon/horizon/dashboards/nova/templates/nova/containers/_create.html @@ -1,11 +1,24 @@ -{% extends 'nova/keypairs/_form.html' %} +{% extends "horizon/common/_modal_form.html" %} {%load i18n%} -{% block form_url %}{% url horizon:nova:containers:create %}{% endblock %} +{% block form_id %}create_container_form{% endblock %} +{% block form_action %}{% url horizon:nova:containers:create %}{% endblock %} -{% block submit %} - - {% block submit %} + {% block modal-footer %} {% endfor %} - {% block submit %} + {% block modal-footer %} {% endblock %} diff --git a/horizon/horizon/dashboards/nova/templates/nova/volumes/_create.html b/horizon/horizon/dashboards/nova/templates/nova/volumes/_create.html index 345723d890..8d8b789a98 100644 --- a/horizon/horizon/dashboards/nova/templates/nova/volumes/_create.html +++ b/horizon/horizon/dashboards/nova/templates/nova/volumes/_create.html @@ -1,9 +1,9 @@ {% extends 'nova/volumes/_form.html' %} {%load i18n%} -{% block form_url %}{% url horizon:nova:volumes:create %}{% endblock %} +{% block form_action %}{% url horizon:nova:volumes:create %}{% endblock %} -{% block submit %} +{% block modal-footer %} {% endfor %} - {% block submit %} + {% block modal-footer %} {% endblock %} diff --git a/horizon/horizon/dashboards/syspanel/templates/syspanel/flavors/_create.html b/horizon/horizon/dashboards/syspanel/templates/syspanel/flavors/_create.html index e8a6ee716e..ef453ba085 100644 --- a/horizon/horizon/dashboards/syspanel/templates/syspanel/flavors/_create.html +++ b/horizon/horizon/dashboards/syspanel/templates/syspanel/flavors/_create.html @@ -1,9 +1,9 @@ {% extends 'syspanel/flavors/_form.html' %} {%load i18n%} -{% block form_url %}{% url horizon:syspanel:users:create %}{% endblock %} +{% block form_action %}{% url horizon:syspanel:users:create %}{% endblock %} -{% block submit %} +{% block modal-footer %} {% endfor %} - {% block submit %} + {% block modal-footer %} {% endblock %} diff --git a/horizon/horizon/dashboards/syspanel/templates/syspanel/images/_form.html b/horizon/horizon/dashboards/syspanel/templates/syspanel/images/_form.html index 4811210c87..6657b13634 100644 --- a/horizon/horizon/dashboards/syspanel/templates/syspanel/images/_form.html +++ b/horizon/horizon/dashboards/syspanel/templates/syspanel/images/_form.html @@ -1,5 +1,5 @@ {%load i18n%} - + {% csrf_token %}
{% for hidden in form.hidden_fields %} @@ -19,7 +19,7 @@ {% endfor %} - {% block submit %} + {% block modal-footer %} {% endblock %}
diff --git a/horizon/horizon/dashboards/syspanel/templates/syspanel/images/_update.html b/horizon/horizon/dashboards/syspanel/templates/syspanel/images/_update.html index 6e006edfbe..8ae979b7eb 100644 --- a/horizon/horizon/dashboards/syspanel/templates/syspanel/images/_update.html +++ b/horizon/horizon/dashboards/syspanel/templates/syspanel/images/_update.html @@ -1,9 +1,9 @@ {% extends 'syspanel/images/_form.html' %} {%load i18n%} -{% block form_url %}{% url horizon:syspanel:images:update image.id %}{% endblock %} +{% block form_action %}{% url horizon:syspanel:images:update image.id %}{% endblock %} -{% block submit %} +{% block modal-footer %} {% endfor %} - {% block submit %} + {% block modal-footer %} {% endblock %} diff --git a/horizon/horizon/dashboards/syspanel/templates/syspanel/tenants/_quotas_form.html b/horizon/horizon/dashboards/syspanel/templates/syspanel/tenants/_quotas_form.html index a2168618c8..e9e353e244 100644 --- a/horizon/horizon/dashboards/syspanel/templates/syspanel/tenants/_quotas_form.html +++ b/horizon/horizon/dashboards/syspanel/templates/syspanel/tenants/_quotas_form.html @@ -6,7 +6,7 @@ {{ field.errors }} {{ field }} {% endfor %} - {% block submit %} + {% block modal-footer %} {% endblock %} diff --git a/horizon/horizon/dashboards/syspanel/templates/syspanel/tenants/_update.html b/horizon/horizon/dashboards/syspanel/templates/syspanel/tenants/_update.html index 6bb77ae8ed..0e7f6d197d 100644 --- a/horizon/horizon/dashboards/syspanel/templates/syspanel/tenants/_update.html +++ b/horizon/horizon/dashboards/syspanel/templates/syspanel/tenants/_update.html @@ -1,9 +1,9 @@ {% extends 'syspanel/images/_form.html' %} {%load i18n%} -{% block form_url %}{% url horizon:syspanel:tenants:update tenant_id %}{% endblock %} +{% block form_action %}{% url horizon:syspanel:tenants:update tenant_id %}{% endblock %} -{% block submit %} +{% block modal-footer %} {% endfor %} - {% block submit %} + {% block modal-footer %} {% endblock %} diff --git a/horizon/horizon/templates/horizon/common/_form_fields.html b/horizon/horizon/templates/horizon/common/_form_fields.html new file mode 100644 index 0000000000..73af73f8a8 --- /dev/null +++ b/horizon/horizon/templates/horizon/common/_form_fields.html @@ -0,0 +1,17 @@ +{% for hidden in form.hidden_fields %} + {{ hidden }} +{% endfor %} +{% for field in form.visible_fields %} +
+ {{field.label_tag}} + {% if field.errors %} + {% for error in field.errors %} + {{error}} + {% endfor %} + {% endif %} + {{field.help_text}} +
+ {{field}} +
+
+{% endfor %} diff --git a/horizon/horizon/templates/horizon/common/_modal_form.html b/horizon/horizon/templates/horizon/common/_modal_form.html new file mode 100644 index 0000000000..6f2de4ed71 --- /dev/null +++ b/horizon/horizon/templates/horizon/common/_modal_form.html @@ -0,0 +1,16 @@ + diff --git a/horizon/horizon/templates/horizon/common/instances/_terminate.html b/horizon/horizon/templates/horizon/common/instances/_terminate.html index 054c64ea9c..256133b45d 100644 --- a/horizon/horizon/templates/horizon/common/instances/_terminate.html +++ b/horizon/horizon/templates/horizon/common/instances/_terminate.html @@ -5,5 +5,5 @@ {{ hidden }} {% endfor %} - + diff --git a/horizon/horizon/users.py b/horizon/horizon/users.py index a3b880c135..d5e444f871 100644 --- a/horizon/horizon/users.py +++ b/horizon/horizon/users.py @@ -21,6 +21,13 @@ Classes and methods related to user handling in Horizon. """ +import logging + +from horizon import exceptions + + +LOG = logging.getLogger(__name__) + def get_user_from_request(request): """ Checks the current session and returns a :class:`~horizon.users.User`. @@ -34,11 +41,12 @@ def get_user_from_request(request): If the session contains invalid data, :exc:`~horizon.exceptions.NotAuthorized` will be raised. """ - if 'user' not in request.session: + if 'user_id' not in request.session: return User() try: - return User(token=request.session['token'], - user=request.session['user'], + return User(id=request.session['user_id'], + token=request.session['token'], + user=request.session['user_name'], tenant_id=request.session['tenant_id'], tenant_name=request.session['tenant'], service_catalog=request.session['serviceCatalog'], @@ -46,6 +54,7 @@ def get_user_from_request(request): except KeyError: # If any of those keys are missing from the session it is # overwhelmingly likely that we're dealing with an outdated session. + LOG.exception("Error while creating User from session.") request.session.clear() raise exceptions.NotAuthorized(_("Your session has expired. " "Please log in again.")) @@ -91,8 +100,9 @@ class User(object): Boolean value indicating whether or not this user has admin privileges. Internally mapped to :meth:`horizon.users.User.is_admin`. """ - def __init__(self, token=None, user=None, tenant_id=None, + def __init__(self, id=None, token=None, user=None, tenant_id=None, service_catalog=None, tenant_name=None, roles=None): + self.id = id self.token = token self.username = user self.tenant_id = tenant_id diff --git a/horizon/horizon/views/auth_forms.py b/horizon/horizon/views/auth_forms.py index 7664b69402..b4e855c65f 100644 --- a/horizon/horizon/views/auth_forms.py +++ b/horizon/horizon/views/auth_forms.py @@ -44,7 +44,8 @@ def _set_session_data(request, token): request.session['tenant'] = token.tenant['name'] request.session['tenant_id'] = token.tenant['id'] request.session['token'] = token.id - request.session['user'] = token.user['name'] + request.session['user_name'] = token.user['name'] + request.session['user_id'] = token.user['id'] request.session['roles'] = token.user['roles'] diff --git a/openstack-dashboard/dashboard/static/dashboard/css/style.css b/openstack-dashboard/dashboard/static/dashboard/css/style.css index 374bd5983a..c26a0b9e9b 100644 --- a/openstack-dashboard/dashboard/static/dashboard/css/style.css +++ b/openstack-dashboard/dashboard/static/dashboard/css/style.css @@ -63,7 +63,7 @@ html, #splash{ } #create_container_form .modal-footer{ - margin-top: 190px; + margin-top: 190px; } .nav li a { @@ -308,6 +308,10 @@ table form { width: 1px; } +.modal > form { + margin-bottom: 0; +} + #actions.single { width: 90px; } diff --git a/openstack-dashboard/dashboard/templates/_login.html b/openstack-dashboard/dashboard/templates/_login.html index 61e7169424..952648ae7d 100644 --- a/openstack-dashboard/dashboard/templates/_login.html +++ b/openstack-dashboard/dashboard/templates/_login.html @@ -1,7 +1,6 @@ {% extends 'horizon/auth/_login.html' %} {% load i18n %} -{% block submit %} - +{% block modal-footer %} {% endblock %}