diff --git a/orchestra/contrib/musician/templates/musician/dashboard2.html b/orchestra/contrib/musician/templates/musician/dashboard2.html index f83018ba..5349cd31 100644 --- a/orchestra/contrib/musician/templates/musician/dashboard2.html +++ b/orchestra/contrib/musician/templates/musician/dashboard2.html @@ -23,8 +23,7 @@ {% if usage.data.progres_bar %}
-
+
{% endif %} {% if usage.data.alert %} @@ -66,5 +65,13 @@ + + {% endblock %} diff --git a/orchestra/contrib/musician/utils.py b/orchestra/contrib/musician/utils.py index 8dea94ef..d35d2751 100644 --- a/orchestra/contrib/musician/utils.py +++ b/orchestra/contrib/musician/utils.py @@ -16,3 +16,10 @@ def get_bootstraped_percent(value, total): bootstraped = min(100, bootstraped) return bootstraped + +def get_bootstraped_percent_exact(value, total): + try: + percent = 100 * float(value)/float(total) + except (TypeError, ZeroDivisionError): + return 0 + return percent \ No newline at end of file diff --git a/orchestra/contrib/musician/views.py b/orchestra/contrib/musician/views.py index ed1215b4..41b34fa5 100644 --- a/orchestra/contrib/musician/views.py +++ b/orchestra/contrib/musician/views.py @@ -48,7 +48,7 @@ from .models import DatabaseService from .models import Mailbox as MailboxService from .models import MailinglistService, SaasService from .settings import ALLOWED_RESOURCES, MUSICIAN_EDIT_ENABLE_PHP_OPTIONS -from .utils import get_bootstraped_percent +from .utils import get_bootstraped_percent, get_bootstraped_percent_exact from .webapps.views import * from .websites.views import * @@ -57,6 +57,7 @@ from .lists.views import * logger = logging.getLogger(__name__) +from django.urls import reverse from django.db.models import Q class DashboardView2(CustomContextMixin, UserTokenRequiredMixin, TemplateView): template_name = "musician/dashboard2.html" @@ -74,17 +75,13 @@ class DashboardView2(CustomContextMixin, UserTokenRequiredMixin, TemplateView): # account account = related_resources.filter(resource_id__verbose_name='account-disk') # account_trafic = related_resources.filter(resource_id__verbose_name='account-traffic') - # print(account_trafic.first()) - # /admin/resources/resourcedata/17000 - # mailbox + # history_disk = reverse('admin:resources_resourcedata_show_history', args=(account.first().pk,)) + # history_traffic = reverse('admin:resources_resourcedata_show_history', args=(account_trafic.first().pk,)) + mailboxes = related_resources.filter(resource_id__verbose_name='mailbox-disk') - # lists lists = related_resources.filter(resource_id__verbose_name='list-traffic') - # Database databases = related_resources.filter(resource_id__verbose_name='database-disk') - # nextcloud nextcloud = related_resources.filter(resource_id__verbose_name='nextcloud-disk') - # domains domains = Domain.objects.filter(account_id=self.request.user) @@ -114,6 +111,8 @@ class DashboardView2(CustomContextMixin, UserTokenRequiredMixin, TemplateView): 'resource_usage': resource_usage, 'notifications': notifications, "support_email_anchor": support_email_anchor, + # 'history_disk': history_disk, + # 'history_traffic': history_traffic, }) return context @@ -161,7 +160,7 @@ class DashboardView2(CustomContextMixin, UserTokenRequiredMixin, TemplateView): 'total': limit_rs, 'alert': alert, 'unit': name_resource.capitalize(), - 'percent': get_bootstraped_percent(total_rs, limit_rs), + 'percent': get_bootstraped_percent_exact(total_rs, limit_rs), }, 'objects': resource_data, } @@ -176,6 +175,7 @@ class DashboardView2(CustomContextMixin, UserTokenRequiredMixin, TemplateView): alert = format_html(f"{size_left * -1} extra size") elif size_left <= 1: alert = format_html(f"{size_left} size left") + print(f"get: {get_bootstraped_percent_exact(total_size, allowed_size)}, total: {total_size}, limit: {allowed_size}") return { 'verbose_name': _('Account'), 'data': { @@ -184,7 +184,7 @@ class DashboardView2(CustomContextMixin, UserTokenRequiredMixin, TemplateView): 'total': allowed_size, 'alert': alert, 'unit': 'GiB Size', - 'percent': get_bootstraped_percent(total_size, allowed_size), + 'percent': get_bootstraped_percent_exact(total_size, allowed_size), }, 'objects': account, }