From e6dc5cf872f04603642b845f191ed61bf61c3db1 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Thu, 12 Dec 2019 15:01:51 +0100 Subject: [PATCH] Show resource usage based on plan definition. --- musician/settings.py | 14 ++++++++++++++ musician/templates/musician/dashboard.html | 7 +++++-- musician/views.py | 17 +++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 musician/settings.py diff --git a/musician/settings.py b/musician/settings.py new file mode 100644 index 0000000..5581061 --- /dev/null +++ b/musician/settings.py @@ -0,0 +1,14 @@ +# allowed resources limit hardcoded because cannot be retrieved from the API. +ALLOWED_RESOURCES = { + 'INDIVIDUAL': + { + # 'disk': 1024, + # 'traffic': 2048, + 'mailbox': 2, + }, + 'ASSOCIATION': { + # 'disk': 5 * 1024, + # 'traffic': 20 * 1024, + 'mailbox': 10, + } +} diff --git a/musician/templates/musician/dashboard.html b/musician/templates/musician/dashboard.html index abee939..53c694e 100644 --- a/musician/templates/musician/dashboard.html +++ b/musician/templates/musician/dashboard.html @@ -54,8 +54,11 @@

{% trans "Mail" %}

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

diff --git a/musician/views.py b/musician/views.py index 5b39f50..4b46dcc 100644 --- a/musician/views.py +++ b/musician/views.py @@ -20,6 +20,7 @@ from .mixins import (CustomContextMixin, ExtendedPaginationMixin, UserTokenRequiredMixin) from .models import (DatabaseService, MailinglistService, MailService, PaymentSource, SaasService, UserAccount) +from .settings import ALLOWED_RESOURCES class DashboardView(CustomContextMixin, UserTokenRequiredMixin, TemplateView): @@ -57,6 +58,22 @@ class DashboardView(CustomContextMixin, UserTokenRequiredMixin, TemplateView): # TODO(@slamora) update when backend supports notifications notifications = [] + # show resource usage based on plan definition + # TODO(@slamora): validate concept of limits with Pangea + profile_type = context['profile'].type + for domain in domains: + address_left = ALLOWED_RESOURCES[profile_type]['mailbox'] - len(domain.mails) + alert = None + if address_left == 1: + alert = 'warning' + elif address_left < 1: + alert = 'danger' + + domain.address_left = { + 'count': address_left, + 'alert': alert, + } + context.update({ 'domains': domains, 'resource_usage': resource_usage,