mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-18 05:51:26 +02:00
Merge pull request #1172 from modoboa/fix/domain_quota_zero_division
admin: fixed zero division error with domain quota.
This commit is contained in:
@@ -244,11 +244,19 @@ class DomainTestCase(ModoTestCase):
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertIn("Summary", response.content.decode())
|
||||
self.assertIn("Administrators", response.content.decode())
|
||||
self.assertIn("Usage", response.content.decode())
|
||||
self.assertNotIn("Resources usage", response.content.decode())
|
||||
self.set_global_parameter("enable_domain_limits", True, app="limits")
|
||||
response = self.client.get(url)
|
||||
self.assertIn("Resources usage", response.content.decode())
|
||||
|
||||
# Try a domain with no quota
|
||||
domain = Domain.objects.filter(quota=0).first()
|
||||
url = reverse("admin:domain_detail", args=[domain.pk])
|
||||
response = self.client.get(url)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertNotIn("Usage", response.content.decode())
|
||||
|
||||
def test_statitics_widget(self):
|
||||
"""Test statistics display in dashboard."""
|
||||
url = reverse("core:dashboard")
|
||||
|
||||
@@ -176,20 +176,23 @@ class DomainDetailView(
|
||||
result = signals.extra_domain_dashboard_widgets.send(
|
||||
self.__class__, user=self.request.user, domain=self.object)
|
||||
parameters = self.request.localconfig.parameters
|
||||
used_quota = int(
|
||||
Quota.objects.get_domain_usage(self.object) / 1048576)
|
||||
used_quota_in_percent = int(
|
||||
used_quota / float(self.object.quota) * 100)
|
||||
allocated_quota = (
|
||||
self.object.allocated_quota_in_percent - used_quota_in_percent)
|
||||
context.update({
|
||||
"templates": {"left": [], "right": []},
|
||||
"enable_mx_checks": parameters.get_value("enable_mx_checks"),
|
||||
"enable_dnsbl_checks": parameters.get_value("enable_dnsbl_checks"),
|
||||
"used_quota": used_quota,
|
||||
"used_quota_in_percent": used_quota_in_percent,
|
||||
"allocated_quota": allocated_quota
|
||||
})
|
||||
if self.object.quota:
|
||||
used_quota = int(
|
||||
Quota.objects.get_domain_usage(self.object) / 1048576)
|
||||
used_quota_in_percent = int(
|
||||
used_quota / float(self.object.quota) * 100)
|
||||
allocated_quota = (
|
||||
self.object.allocated_quota_in_percent - used_quota_in_percent)
|
||||
context.update({
|
||||
"used_quota": used_quota,
|
||||
"used_quota_in_percent": used_quota_in_percent,
|
||||
"allocated_quota": allocated_quota
|
||||
})
|
||||
for receiver, widgets in result:
|
||||
for widget in widgets:
|
||||
context["templates"][widget["column"]].append(
|
||||
|
||||
Reference in New Issue
Block a user