Show address mailbox disk usage.

This commit is contained in:
Santiago Lamora 2020-02-17 12:05:55 +01:00
parent 425d090522
commit 0fa26d799b
2 changed files with 29 additions and 8 deletions

View file

@ -229,14 +229,30 @@ class MailService(OrchestraModel):
def type_detail(self):
if self.type == self.FORWARD:
return self.data['forward']
# TODO(@slamora) retrieve mailbox usage
return {
'usage': 250,
'total': 500,
'unit': 'MB',
'percent': 50,
# retrieve mailbox usage
try:
resource = self.data['mailboxes'][0]['resources']
resource_disk = {}
for r in resource:
if r['name'] == 'disk':
resource_disk = r
break
mailbox_details = {
'usage': resource_disk['used'],
'total': resource_disk['allocated'],
'unit': resource_disk['unit'],
}
# get percent and round to be 0, 25, 50 or 100
# to set progress bar width using CSS classes (e.g. w-25)
percent = float(resource_disk['used']) / resource_disk['allocated']
mailbox_details['percent'] = round(percent * 4) * 100 // 4
except (IndexError, KeyError):
mailbox_details = {}
return mailbox_details
class MailinglistService(OrchestraModel):
api_name = 'mailinglist'

View file

@ -8,8 +8,13 @@ Expected structure: dictionary or object with attributes:
- unit (string): 'MB'
- percent (int: [0, 25, 50, 75, 100]: 75
{% endcomment %}
<div class="text-center">
{% if detail %}
{{ detail.usage }} of {{ detail.total }}{{ detail.unit }}
{% else %}
N/A
{% endif %}
</div>
<div class="progress">
<div class="progress-bar bg-secondary w-{{ detail.percent }}" role="progressbar" aria-valuenow="{{ detail.usage }}"