From a88c2decd3bdd9bcc02d6434594913bf9168cd96 Mon Sep 17 00:00:00 2001 From: jorgepastorr Date: Tue, 19 Nov 2024 13:21:02 +0100 Subject: [PATCH] musician saas nextcloud progresbar --- orchestra/contrib/musician/saas/views.py | 23 ++++++++++++++----- .../musician/saas_nextcloud_list.html | 12 ++++++++++ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/orchestra/contrib/musician/saas/views.py b/orchestra/contrib/musician/saas/views.py index 84ed79f2..768b397b 100644 --- a/orchestra/contrib/musician/saas/views.py +++ b/orchestra/contrib/musician/saas/views.py @@ -4,18 +4,20 @@ from django.urls import reverse_lazy from django.views.generic.base import RedirectView, TemplateView from django.views.generic.detail import DetailView +from django.views.generic.list import ListView from django.views.generic.edit import (CreateView, DeleteView, FormView, UpdateView) -from django.views.generic.list import ListView +from orchestra.contrib.saas.models import SaaS +from orchestra.contrib.resources.models import Resource, ResourceData + +from orchestra.contrib.musician.settings import ALLOWED_RESOURCES +from orchestra.contrib.musician.utils import get_bootstraped_percent_exact from orchestra.contrib.musician.mixins import (CustomContextMixin, ExtendedPaginationMixin, UserTokenRequiredMixin) from .forms import ( NextcloudChangePasswordForm, SaasNextcloudUpdateForm, SaasWordpressUpdateForm, NextcloudCreateForm ) -from orchestra.contrib.saas.models import SaaS - -from orchestra.contrib.musician.settings import ALLOWED_RESOURCES class SaasNextcloudListView(CustomContextMixin, UserTokenRequiredMixin, ListView): @@ -29,8 +31,17 @@ class SaasNextcloudListView(CustomContextMixin, UserTokenRequiredMixin, ListView } def get_queryset(self): - return self.model.objects.filter(account=self.request.user, service='nextcloud') - + # return self.model.objects.filter(account=self.request.user, service='nextcloud') + qs = self.model.objects.filter(account=self.request.user, service='nextcloud') + disk_resource = Resource.objects.get(name='nextcloud-disk') + for Nuser in qs: + try: + Nuser.usage = Nuser.resource_set.get(resource=disk_resource) + except ResourceData.DoesNotExist: + Nuser.usage = ResourceData(resource=disk_resource) + Nuser.percent = get_bootstraped_percent_exact(Nuser.usage.used, Nuser.usage.allocated) + return qs + class SaasWordpressListView(CustomContextMixin, UserTokenRequiredMixin, ListView): model = SaaS diff --git a/orchestra/contrib/musician/templates/musician/saas_nextcloud_list.html b/orchestra/contrib/musician/templates/musician/saas_nextcloud_list.html index fd0a9f09..fc6bb6c8 100644 --- a/orchestra/contrib/musician/templates/musician/saas_nextcloud_list.html +++ b/orchestra/contrib/musician/templates/musician/saas_nextcloud_list.html @@ -13,6 +13,7 @@ {% trans "Name" %} {% trans "Status" %} {% trans "Service" %} + {% trans "Disk usage" %} @@ -32,6 +33,17 @@ {{ saas.service|capfirst }} {% trans "Open service admin panel" %} + + {% if saas.usage.used %} + {{ saas.usage.used|floatformat }} + {% else %} + 0 + {% endif %} + {{ saas.usage.unit }} +
+
+
+