Compare commits

..

No commits in common. "52ec1660f670143ada723d6316ac25eb312b163f" and "0b31049f0b7f5f90488d7590c9a775479586b500" have entirely different histories.

3 changed files with 28 additions and 24 deletions

View file

@ -8,6 +8,7 @@ from django.utils.translation import gettext_lazy as _
from . import settings as musician_settings
from .utils import get_bootstraped_percent
logger = logging.getLogger(__name__)
@ -175,7 +176,7 @@ class DatabaseService(OrchestraModel):
break
details = {
'used': float(resource_disk['used']),
'usage': float(resource_disk['used']),
'total': resource_disk['allocated'],
'unit': resource_disk['unit'],
}
@ -184,7 +185,7 @@ class DatabaseService(OrchestraModel):
percent = get_bootstraped_percent(
details['used'],
details['usage'],
details['total']
)
details['percent'] = percent
@ -290,7 +291,7 @@ class Address(OrchestraModel):
break
mailbox_details = {
'used': float(resource_disk['used']),
'usage': float(resource_disk['used']),
'total': resource_disk['allocated'],
'unit': resource_disk['unit'],
}

View file

@ -1,22 +1,22 @@
{% comment %}
Resource used rendered as bootstrap progress bar
Resource usage rendered as bootstrap progress bar
Expected parameter: detail
Expected structure: dictionary or object with attributes:
- used (int): 125
- usage (int): 125
- total (int): 200
- unit (string): 'MB'
- percent (int: [0, 25, 50, 75, 100]: 75
{% endcomment %}
<div class="text-center">
{% if detail and detail.used %}
{{ detail.used|floatformat }} {{ detail.unit }}
{% if detail %}
{{ detail.usage }} {{ detail.unit }}
{% else %}
N/A
{% endif %}
</div>
<div class="progress">
<div class="progress-bar bg-secondary w-{{ detail.percent }}" role="progressbar" aria-valuenow="{{ detail.used }}"
<div class="progress-bar bg-secondary w-{{ detail.percent }}" role="progressbar" aria-valuenow="{{ detail.usage }}"
aria-valuemin="0" aria-valuemax="{{ detail.total }}"></div>
</div>

View file

@ -67,6 +67,24 @@ class DashboardView(CustomContextMixin, UserTokenRequiredMixin, TemplateView):
# TODO(@slamora) update when backend provides resource usage data
resource_usage = {
'disk': {
'verbose_name': _('Disk usage'),
'data': {
# 'usage': 534,
# 'total': 1024,
# 'unit': 'MB',
# 'percent': 50,
},
},
'traffic': {
'verbose_name': _('Traffic'),
'data': {
# 'usage': 300,
# 'total': 2048,
# 'unit': 'MB/month',
# 'percent': 25,
},
},
'mailbox': self.get_mailbox_usage(profile_type),
}
@ -99,7 +117,7 @@ class DashboardView(CustomContextMixin, UserTokenRequiredMixin, TemplateView):
return {
'verbose_name': _('Mailbox usage'),
'data': {
'used': total_mailboxes,
'usage': total_mailboxes,
'total': allowed_mailboxes,
'alert': alert,
'unit': 'mailboxes',
@ -424,21 +442,6 @@ class DatabasesView(ServiceListView):
'title': _('Databases'),
}
def get_queryset(self):
qs = super().get_queryset()
# TODO(@slamora): optimize query
from django.contrib.contenttypes.models import ContentType
from orchestra.contrib.resources.models import Resource, ResourceData
ctype = ContentType.objects.get_for_model(self.model)
disk_resource = Resource.objects.get(name='disk', content_type=ctype)
for db in qs:
try:
db.usage = db.resource_set.get(resource=disk_resource)
except ResourceData.DoesNotExist:
db.usage = ResourceData(resource=disk_resource)
return qs
class SaasListView(ServiceListView):
service_class = SaasService