diff --git a/adjutant_ui/api/adjutant.py b/adjutant_ui/api/adjutant.py index 7f6dcaa..442aff3 100644 --- a/adjutant_ui/api/adjutant.py +++ b/adjutant_ui/api/adjutant.py @@ -625,20 +625,24 @@ def size_details_get(request, size, region=None): resp = _get_quota_information(request, regions=region) data = resp['quota_sizes'][size] - region_data = resp['regions'][0]['current_quota'] + try: + region = resp['regions'][0] + except IndexError: + region = {} + current_quota = region.get('current_quota', {}) + current_usage = region.get('current_usage', {}) for service, values in data.items(): - if service not in resp['regions'][0]['current_usage']: - continue for resource, value in values.items(): if _is_quota_hidden(service, resource): continue - usage = resp['regions'][0]['current_usage'][service].get( - resource) - try: - percent = float(usage) / value - except (TypeError, ZeroDivisionError): - percent = '-' + quota = current_quota.get(service, {}).get(resource, '-') + usage = current_usage.get(service, {}).get(resource, '-') + percent = ( + '-' + if not value or usage == '-' + else (usage / value) + ) quota_details.append( SIZE_QUOTA_VALUE( @@ -646,7 +650,7 @@ def size_details_get(request, size, region=None): name=resource, service=service, value=value, - current_quota=region_data[service][resource], + current_quota=quota, current_usage=usage, percent=percent ) @@ -659,7 +663,11 @@ def quota_details_get(request, region): resp = _get_quota_information(request, regions=region) - data = resp['regions'][0]['current_quota'] + try: + region = resp['regions'][0] + except IndexError: + region = {} + data = region.get('current_quota', {}) for service, values in data.items(): for name, value in values.items(): diff --git a/adjutant_ui/content/quota/templates/quota/region_detail.html b/adjutant_ui/content/quota/templates/quota/region_detail.html index cd9212d..77c1a5d 100644 --- a/adjutant_ui/content/quota/templates/quota/region_detail.html +++ b/adjutant_ui/content/quota/templates/quota/region_detail.html @@ -1,6 +1,6 @@ {% extends 'base.html' %} {% load i18n %} -{% block title %} {% trans "Quota Details" %} {% endblock %} +{% block title %}{% blocktrans %}{{ region }} Quota Details{% endblocktrans %}{% endblock %} {% block main %} {{ table.render }} diff --git a/adjutant_ui/content/quota/templates/quota/size_detail.html b/adjutant_ui/content/quota/templates/quota/size_detail.html index 87aa1b9..1250411 100644 --- a/adjutant_ui/content/quota/templates/quota/size_detail.html +++ b/adjutant_ui/content/quota/templates/quota/size_detail.html @@ -1,10 +1,6 @@ {% extends 'base.html' %} {% load i18n %} -{% block title %} {{title}} - Quota Details{% endblock %} - -{% block page_header %} - {% include "horizon/common/_page_header.html" with title=title %} -{% endblock page_header %} +{% block title %}{% blocktrans %}{{ size_titlecase }} Quota Details{% endblocktrans %}{% endblock %} {% block main %} {{ table.render }} diff --git a/adjutant_ui/content/quota/views.py b/adjutant_ui/content/quota/views.py index 669e2b6..4a69bb3 100644 --- a/adjutant_ui/content/quota/views.py +++ b/adjutant_ui/content/quota/views.py @@ -57,7 +57,7 @@ class IndexView(horizon_tables.MultiTableView): class RegionDetailView(horizon_tables.DataTableView): table_class = quota_tables.RegionQuotaDetailTable template_name = 'management/quota/region_detail.html' - page_title = _("'{{ region }}' Quota Details") + page_title = _("{{ region }} Quota Details") def get_data(self): try: @@ -76,7 +76,7 @@ class RegionDetailView(horizon_tables.DataTableView): class QuotaSizeView(horizon_tables.DataTableView): table_class = quota_tables.QuotaDetailUsageTable template_name = 'management/quota/size_detail.html' - page_title = _("'{{ size }}' Quota Details") + page_title = _("{{ size | title }} Quota Details") def get_data(self): try: @@ -89,8 +89,10 @@ class QuotaSizeView(horizon_tables.DataTableView): def get_context_data(self, **kwargs): # request.user.services_region context = super(QuotaSizeView, self).get_context_data(**kwargs) - context['title'] = _("%s - Quota Details") \ - % self.kwargs['size'].title() + context['size'] = self.kwargs['size'] + # NOTE(callumdickinson): Necessary because the title filter + # is overloaded in the title block. + context['size_titlecase'] = self.kwargs['size'].title() return context