Compare commits
2 Commits
0b31049f0b
...
52ec1660f6
Author | SHA1 | Date |
---|---|---|
Santiago L | 52ec1660f6 | |
Santiago L | 0695099980 |
|
@ -8,7 +8,6 @@ from django.utils.translation import gettext_lazy as _
|
||||||
from . import settings as musician_settings
|
from . import settings as musician_settings
|
||||||
from .utils import get_bootstraped_percent
|
from .utils import get_bootstraped_percent
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@ -176,7 +175,7 @@ class DatabaseService(OrchestraModel):
|
||||||
break
|
break
|
||||||
|
|
||||||
details = {
|
details = {
|
||||||
'usage': float(resource_disk['used']),
|
'used': float(resource_disk['used']),
|
||||||
'total': resource_disk['allocated'],
|
'total': resource_disk['allocated'],
|
||||||
'unit': resource_disk['unit'],
|
'unit': resource_disk['unit'],
|
||||||
}
|
}
|
||||||
|
@ -185,7 +184,7 @@ class DatabaseService(OrchestraModel):
|
||||||
|
|
||||||
|
|
||||||
percent = get_bootstraped_percent(
|
percent = get_bootstraped_percent(
|
||||||
details['usage'],
|
details['used'],
|
||||||
details['total']
|
details['total']
|
||||||
)
|
)
|
||||||
details['percent'] = percent
|
details['percent'] = percent
|
||||||
|
@ -291,7 +290,7 @@ class Address(OrchestraModel):
|
||||||
break
|
break
|
||||||
|
|
||||||
mailbox_details = {
|
mailbox_details = {
|
||||||
'usage': float(resource_disk['used']),
|
'used': float(resource_disk['used']),
|
||||||
'total': resource_disk['allocated'],
|
'total': resource_disk['allocated'],
|
||||||
'unit': resource_disk['unit'],
|
'unit': resource_disk['unit'],
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +1,22 @@
|
||||||
{% comment %}
|
{% comment %}
|
||||||
Resource usage rendered as bootstrap progress bar
|
Resource used rendered as bootstrap progress bar
|
||||||
|
|
||||||
Expected parameter: detail
|
Expected parameter: detail
|
||||||
Expected structure: dictionary or object with attributes:
|
Expected structure: dictionary or object with attributes:
|
||||||
- usage (int): 125
|
- used (int): 125
|
||||||
- total (int): 200
|
- total (int): 200
|
||||||
- unit (string): 'MB'
|
- unit (string): 'MB'
|
||||||
- percent (int: [0, 25, 50, 75, 100]: 75
|
- percent (int: [0, 25, 50, 75, 100]: 75
|
||||||
{% endcomment %}
|
{% endcomment %}
|
||||||
|
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
{% if detail %}
|
{% if detail and detail.used %}
|
||||||
{{ detail.usage }} {{ detail.unit }}
|
{{ detail.used|floatformat }} {{ detail.unit }}
|
||||||
{% else %}
|
{% else %}
|
||||||
N/A
|
N/A
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<div class="progress">
|
<div class="progress">
|
||||||
<div class="progress-bar bg-secondary w-{{ detail.percent }}" role="progressbar" aria-valuenow="{{ detail.usage }}"
|
<div class="progress-bar bg-secondary w-{{ detail.percent }}" role="progressbar" aria-valuenow="{{ detail.used }}"
|
||||||
aria-valuemin="0" aria-valuemax="{{ detail.total }}"></div>
|
aria-valuemin="0" aria-valuemax="{{ detail.total }}"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -67,24 +67,6 @@ class DashboardView(CustomContextMixin, UserTokenRequiredMixin, TemplateView):
|
||||||
|
|
||||||
# TODO(@slamora) update when backend provides resource usage data
|
# TODO(@slamora) update when backend provides resource usage data
|
||||||
resource_usage = {
|
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),
|
'mailbox': self.get_mailbox_usage(profile_type),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,7 +99,7 @@ class DashboardView(CustomContextMixin, UserTokenRequiredMixin, TemplateView):
|
||||||
return {
|
return {
|
||||||
'verbose_name': _('Mailbox usage'),
|
'verbose_name': _('Mailbox usage'),
|
||||||
'data': {
|
'data': {
|
||||||
'usage': total_mailboxes,
|
'used': total_mailboxes,
|
||||||
'total': allowed_mailboxes,
|
'total': allowed_mailboxes,
|
||||||
'alert': alert,
|
'alert': alert,
|
||||||
'unit': 'mailboxes',
|
'unit': 'mailboxes',
|
||||||
|
@ -442,6 +424,21 @@ class DatabasesView(ServiceListView):
|
||||||
'title': _('Databases'),
|
'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):
|
class SaasListView(ServiceListView):
|
||||||
service_class = SaasService
|
service_class = SaasService
|
||||||
|
|
Loading…
Reference in New Issue