diff --git a/musician/api.py b/musician/api.py index 2b33dee..6b60c0c 100644 --- a/musician/api.py +++ b/musician/api.py @@ -221,7 +221,7 @@ class Orchestra(object): querystring = "domain={}".format(domain_json['id']) # retrieve services associated to a domain - domain_json['mails'] = self.retrieve_service_list( + domain_json['addresses'] = self.retrieve_service_list( Address.api_name, querystring) # retrieve websites (as they cannot be filtered by domain on the API we should do it here) diff --git a/musician/models.py b/musician/models.py index 146f7c3..8aa4e77 100644 --- a/musician/models.py +++ b/musician/models.py @@ -203,7 +203,7 @@ class Domain(OrchestraModel): "id": None, "name": None, "records": [], - "mails": [], + "addresses": [], "usage": {}, "websites": [], "url": None, diff --git a/musician/templates/musician/dashboard.html b/musician/templates/musician/dashboard.html index 8226bd1..591b26e 100644 --- a/musician/templates/musician/dashboard.html +++ b/musician/templates/musician/dashboard.html @@ -16,6 +16,11 @@
{{ usage.verbose_name }}
{% include "musician/components/usage_progress_bar.html" with detail=usage.data %} + {% if usage.data.alert %} +
+ {{ usage.data.alert }} +
+ {% endif %}
{% endfor %} @@ -65,11 +70,7 @@

{% trans "Mail" %}

- {{ domain.mails|length }} {% trans "mail addresses created" %} - {% if domain.addresses_left.alert_level %} -
- {{ domain.addresses_left.count }} {% trans "mail address left" %} - {% endif %} + {{ domain.addresses|length }} {% trans "mail addresses created" %}

diff --git a/musician/views.py b/musician/views.py index 2daab06..663f498 100644 --- a/musician/views.py +++ b/musician/views.py @@ -10,6 +10,7 @@ from django.http import HttpResponse, HttpResponseRedirect from django.shortcuts import render from django.urls import reverse_lazy from django.utils import translation +from django.utils.html import format_html from django.utils.http import is_safe_url from django.utils.translation import gettext_lazy as _ from django.views import View @@ -49,20 +50,6 @@ class DashboardView(CustomContextMixin, UserTokenRequiredMixin, TemplateView): # show resource usage based on plan definition profile_type = context['profile'].type - total_mailboxes = 0 - for domain in domains: - total_mailboxes += len(domain.mails) - addresses_left = ALLOWED_RESOURCES[profile_type]['mailbox'] - len(domain.mails) - alert_level = None - if addresses_left == 1: - alert_level = 'warning' - elif addresses_left < 1: - alert_level = 'danger' - - domain.addresses_left = { - 'count': addresses_left, - 'alert_level': alert_level, - } # TODO(@slamora) update when backend provides resource usage data resource_usage = { @@ -84,15 +71,7 @@ class DashboardView(CustomContextMixin, UserTokenRequiredMixin, TemplateView): # 'percent': 25, }, }, - 'mailbox': { - 'verbose_name': _('Mailbox usage'), - 'data': { - 'usage': total_mailboxes, - 'total': ALLOWED_RESOURCES[profile_type]['mailbox'], - 'unit': 'accounts', - 'percent': get_bootstraped_percent(total_mailboxes, ALLOWED_RESOURCES[profile_type]['mailbox']), - }, - }, + 'mailbox': self.get_mailbox_usage(profile_type), } context.update({ @@ -103,6 +82,28 @@ class DashboardView(CustomContextMixin, UserTokenRequiredMixin, TemplateView): return context + def get_mailbox_usage(self, profile_type): + allowed_mailboxes = ALLOWED_RESOURCES[profile_type]['mailbox'] + total_mailboxes = len(self.orchestra.retrieve_mailbox_list()) + mailboxes_left = allowed_mailboxes - total_mailboxes + + alert = '' + if mailboxes_left < 0: + alert = format_html("{} extra mailboxes", mailboxes_left * -1) + elif mailboxes_left <= 1: + alert = format_html("{} mailbox left", mailboxes_left) + + return { + 'verbose_name': _('Mailbox usage'), + 'data': { + 'usage': total_mailboxes, + 'total': allowed_mailboxes, + 'alert': alert, + 'unit': 'mailboxes', + 'percent': get_bootstraped_percent(total_mailboxes, allowed_mailboxes), + }, + } + class ProfileView(CustomContextMixin, UserTokenRequiredMixin, TemplateView): template_name = "musician/profile.html"