rounded quota usage and percent in messages
@@ -18,39 +18,41 @@ def get_quota_message(user):
return_msg = ''
for uq in user.quotas.all():
percent = uq.used_value * 100.0 / uq.allocated_value
+ rounded_percent = round(percent,2)
+ rounded_used_val = round(uq.used_value, 2)
if percent >= hard_limit or (percent >= soft_limit and uq.remaining_grace_period == 0):
# return quota enforcement message
msg_template_str = '{}{}\n'.format(qmsg.enforce_content_prepend, qmsg.content)
- return_msg += msg_template_str.format(used=round(uq.used_value),
+ return_msg += msg_template_str.format(used=rounded_used_val,
unit=uq.unit,
allocated=uq.allocated_value,
zone=uq.zone,
- percent=percent)
+ percent=rounded_percent)
elif percent >= soft_limit and uq.remaining_grace_period > 0:
# return quota grace period message
cut_off_date = date.today() + timedelta(days=uq.remaining_grace_period)
msg_template_str = '{}{}\n'.format(qmsg.grace_period_content_prepend, qmsg.content)
- return_msg += msg_template_str.format(used=round(uq.used_value),
+ return_msg += msg_template_str.format(used=rounded_used_val,
unit=uq.unit,
allocated=uq.allocated_value,
zone=uq.zone,
- percent=percent,
+ percent=rounded_percent,
cut_off_date=cut_off_date)
elif percent >= soft_limit:
# return quota warning message
msg_template_str = '{}{}\n'.format(qmsg.warning_content_prepend, qmsg.content)
- return_msg += msg_template_str.format(used=round(uq.used_value),
+ return_msg += msg_template_str.format(used=rounded_used_val,
unit=uq.unit,
allocated=uq.allocated_value,
zone=uq.zone,
- percent=percent)
+ percent=rounded_percent)
else:
# return quota informational message
return_msg += 'Your quota for HydroShare resources is {allocated}{unit} in {zone} ' \
'zone. You currently have resources that consume {used}{unit}, ' \
'{percent}% of your quota.'.format(allocated=uq.allocated_value,
unit=uq.unit,
- used=round(uq.used_value),
+ used=rounded_used_val,
zone=uq.zone,
- percent=percent)
+ percent=rounded_percent)
return return_msg
