From 257b627a3e36af24fe7f93beec296f52d5b98268 Mon Sep 17 00:00:00 2001 From: Marc Aymerich Date: Wed, 7 Oct 2015 13:15:16 +0000 Subject: [PATCH] Fixed bug on humanize.date --- TODO.md | 4 +++- orchestra/contrib/mailboxes/admin.py | 2 +- orchestra/contrib/mailboxes/forms.py | 3 ++- orchestra/contrib/mailboxes/models.py | 7 +++++-- orchestra/contrib/mailboxes/settings.py | 6 ------ orchestra/utils/humanize.py | 6 +++--- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/TODO.md b/TODO.md index 4a0c3ab5..efb56e1d 100644 --- a/TODO.md +++ b/TODO.md @@ -412,4 +412,6 @@ mkhomedir_helper or create ssh homes with bash.rc and such # warnings if some plugins are disabled, like make routes red # replace show emails by https://docs.python.org/3/library/email.contentmanager.html#module-email.contentmanager -# put addressform.clean on model.clean and search for other places? + + +# setupforbiddendomains --url alexa -n 5000 diff --git a/orchestra/contrib/mailboxes/admin.py b/orchestra/contrib/mailboxes/admin.py index 97544f43..5cc4e8a5 100644 --- a/orchestra/contrib/mailboxes/admin.py +++ b/orchestra/contrib/mailboxes/admin.py @@ -76,7 +76,7 @@ class MailboxAdmin(ChangePasswordAdminMixin, SelectAccountAdminMixin, ExtendedMo def __init__(self, *args, **kwargs): super(MailboxAdmin, self).__init__(*args, **kwargs) - if settings.MAILBOXES_LOCAL_ADDRESS_DOMAIN: + if settings.MAILBOXES_LOCAL_DOMAIN: type(self).actions = self.actions + (SendMailboxEmail(),) def display_addresses(self, mailbox): diff --git a/orchestra/contrib/mailboxes/forms.py b/orchestra/contrib/mailboxes/forms.py index 326c7297..a377c765 100644 --- a/orchestra/contrib/mailboxes/forms.py +++ b/orchestra/contrib/mailboxes/forms.py @@ -51,7 +51,8 @@ class MailboxForm(forms.ModelForm): local_domain = settings.MAILBOXES_LOCAL_DOMAIN if name and local_domain: try: - addr = Address.objects.get(name=name, domain__name=local_domain, account_id=self.modeladmin.account.pk) + addr = Address.objects.get( + name=name, domain__name=local_domain, account_id=self.modeladmin.account.pk) except Address.DoesNotExist: pass else: diff --git a/orchestra/contrib/mailboxes/models.py b/orchestra/contrib/mailboxes/models.py index 5a0d5340..a6326d54 100644 --- a/orchestra/contrib/mailboxes/models.py +++ b/orchestra/contrib/mailboxes/models.py @@ -1,4 +1,5 @@ import os +import re from collections import defaultdict from django.contrib.auth.hashers import make_password @@ -72,9 +73,9 @@ class Mailbox(models.Model): return (name, content) def get_local_address(self): - if not settings.MAILBOXES_LOCAL_ADDRESS_DOMAIN: + if not settings.MAILBOXES_LOCAL_DOMAIN: raise AttributeError("Mailboxes do not have a defined local address domain.") - return '@'.join((self.name, settings.MAILBOXES_LOCAL_ADDRESS_DOMAIN)) + return '@'.join((self.name, settings.MAILBOXES_LOCAL_DOMAIN)) class Address(models.Model): @@ -136,7 +137,9 @@ class Address(models.Model): raise ValidationError(errors) def get_forward_mailboxes(self): + rm_local_domain = re.compile(r'@%s$' % settings.MAILBOXES_LOCAL_DOMAIN) for forward in self.forward.split(): + forward = rm_local_domain.sub('', forward) if '@' not in forward: try: yield Mailbox.objects.get(name=forward) diff --git a/orchestra/contrib/mailboxes/settings.py b/orchestra/contrib/mailboxes/settings.py index 150f9d0b..39403d3e 100644 --- a/orchestra/contrib/mailboxes/settings.py +++ b/orchestra/contrib/mailboxes/settings.py @@ -186,12 +186,6 @@ MAILBOXES_MAILDIRSIZE_PATH = Setting('MAILBOXES_MAILDIRSIZE_PATH', ) -MAILBOXES_LOCAL_ADDRESS_DOMAIN = Setting('MAILBOXES_LOCAL_ADDRESS_DOMAIN', - ORCHESTRA_BASE_DOMAIN, - validators=[validate_name], - help_text="Defaults to ORCHESTRA_BASE_DOMAIN." -) - MAILBOXES_MAIL_LOG_PATH = Setting('MAILBOXES_MAIL_LOG_PATH', '/var/log/mail.log' diff --git a/orchestra/utils/humanize.py b/orchestra/utils/humanize.py index ec64a312..a908b33b 100644 --- a/orchestra/utils/humanize.py +++ b/orchestra/utils/humanize.py @@ -86,15 +86,15 @@ def naturaldate(date): delta_midnight = today - date count = 0 - for chunk, pluralizefun in OLDER_CHUNKS: + for chunk, units in OLDER_CHUNKS: if days < 7.0: count = days - fmt = pluralize_day(count) + fmt = verbose_time(count, 'days') return fmt.format(num=count, ago=ago) if days >= chunk: count = (delta_midnight.days + 1) / chunk count = abs(count) - fmt = pluralizefun(count) + fmt = verbose_time(count, units) return fmt.format(num=count, ago=ago)