Show resource usage based on plan definition.

This commit is contained in:
Santiago Lamora 2019-12-12 15:01:51 +01:00
parent 6520798493
commit e6dc5cf872
3 changed files with 36 additions and 2 deletions

14
musician/settings.py Normal file
View File

@ -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,
}
}

View File

@ -54,8 +54,11 @@
<h4>{% trans "Mail" %}</h4>
<p class="card-text"><i class="fas fa-envelope fa-3x"></i></p>
<p class="card-text text-dark">
{{ domain.mails|length }} {% trans "mail addresses created" %}<br/>
<span class="text-warning">1 mail address left</span>
{{ domain.mails|length }} {% trans "mail addresses created" %}
{% if domain.address_left.alert %}
<br/>
<span class="text-{{ domain.address_left.alert }}">{{ domain.address_left.count }} mail address left</span>
{% endif %}
</p>
<a class="stretched-link" href="{% url 'musician:mails' %}?domain={{ domain.id }}"></a>
</div>

View File

@ -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,