From e0f2f345232734c699cb19a9f86708e74b7ddafe Mon Sep 17 00:00:00 2001 From: Gael Pasgrimaud Date: Mon, 19 Sep 2016 15:37:37 +0200 Subject: [PATCH] take care of creation date while showing DNS status --- modoboa/admin/handlers.py | 6 ------ modoboa/admin/models/domain.py | 17 +++++++++++++++-- .../admin/templates/admin/domain_detail.html | 14 +++++++++----- .../admin/templates/admin/domains_table.html | 14 +++++++++----- 4 files changed, 33 insertions(+), 18 deletions(-) diff --git a/modoboa/admin/handlers.py b/modoboa/admin/handlers.py index cccff63e6..b6fbae762 100644 --- a/modoboa/admin/handlers.py +++ b/modoboa/admin/handlers.py @@ -1,6 +1,5 @@ """Django signal handlers for admin.""" -from django.core import management from django.db.models import signals from django.dispatch import receiver @@ -11,11 +10,6 @@ from . import models def update_domain_mxs_and_mailboxes(sender, instance, **kwargs): """Update associated MXs and mailboxes.""" if kwargs.get("created"): - management.call_command( - 'modo', 'check_mx', - domain=[instance], - skip_admin_emails=True, - ) return instance.mailbox_set.filter(use_domain_quota=True).update( quota=instance.quota) diff --git a/modoboa/admin/models/domain.py b/modoboa/admin/models/domain.py index d90b00099..eb89380e6 100644 --- a/modoboa/admin/models/domain.py +++ b/modoboa/admin/models/domain.py @@ -1,7 +1,10 @@ """Models related to domains management.""" +import datetime + from django.db import models from django.db.models.manager import Manager +from django.utils import timezone from django.utils.encoding import python_2_unicode_compatible, smart_text from django.utils.functional import cached_property from django.utils.translation import ugettext as _, ugettext_lazy @@ -103,8 +106,18 @@ class Domain(AdminObject): return self.domainalias_set @property - def mx_records(self): - self.mxrecord_set + def just_created(self): + """return true if the domain was created in the latest 24h""" + now = timezone.now() + delta = datetime.timedelta(days=1) + return bool(self.creation + delta > now) + + def awaiting_checks(self): + """return true if the domain has no valid MX records and was created + in the latest 24h""" + if (not self.mxrecord_set.has_valids()) and self.just_created: + return True + return False @cached_property def dnsbl_status_color(self): diff --git a/modoboa/admin/templates/admin/domain_detail.html b/modoboa/admin/templates/admin/domain_detail.html index ab79891ad..578f48fd9 100644 --- a/modoboa/admin/templates/admin/domain_detail.html +++ b/modoboa/admin/templates/admin/domain_detail.html @@ -24,11 +24,15 @@ {% if enable_mx_checks == "yes" or enable_dnsbl_checks == "yes" %}
{% trans "DNS status" %} - {% if enable_mx_checks == "yes" %} - MX - {% endif %} - {% if enable_dnsbl_checks == "yes" %} - DNSBL + {% if domain.awaiting_checks %} + {% trans "Awaiting checks" %} + {% else %} + {% if enable_mx_checks == "yes" %} + MX + {% endif %} + {% if enable_dnsbl_checks == "yes" %} + DNSBL + {% endif %} {% endif %}
{% endif %} diff --git a/modoboa/admin/templates/admin/domains_table.html b/modoboa/admin/templates/admin/domains_table.html index da4587af4..84086aec8 100644 --- a/modoboa/admin/templates/admin/domains_table.html +++ b/modoboa/admin/templates/admin/domains_table.html @@ -8,11 +8,15 @@ {% if enable_mx_checks == "yes" or enable_dnsbl_checks == "yes" %} - {% if enable_mx_checks == "yes" %} - MX - {% endif %} - {% if enable_dnsbl_checks == "yes" %} - DNSBL + {% if domain.awaiting_checks %} + {% trans "awaiting checks" %} + {% else %} + {% if enable_mx_checks == "yes" %} + MX + {% endif %} + {% if enable_dnsbl_checks == "yes" %} + DNSBL + {% endif %} {% endif %}