diff --git a/musician/models.py b/musician/models.py index 0718aaa..4863638 100644 --- a/musician/models.py +++ b/musician/models.py @@ -229,13 +229,29 @@ 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): diff --git a/musician/templates/musician/components/usage_progress_bar.html b/musician/templates/musician/components/usage_progress_bar.html index e3772e4..bf3d2d6 100644 --- a/musician/templates/musician/components/usage_progress_bar.html +++ b/musician/templates/musician/components/usage_progress_bar.html @@ -1,5 +1,5 @@ {% comment %} -Resource usage rendered as bootstrap progress bar +Resource usage rendered as bootstrap progress bar Expected parameter: detail Expected structure: dictionary or object with attributes: @@ -8,8 +8,13 @@ Expected structure: dictionary or object with attributes: - unit (string): 'MB' - percent (int: [0, 25, 50, 75, 100]: 75 {% endcomment %} +
+ {% if detail %} {{ detail.usage }} of {{ detail.total }}{{ detail.unit }} + {% else %} + N/A + {% endif %}