Fixed bug on humanize.date

This commit is contained in:
Marc Aymerich 2015-10-07 13:15:16 +00:00
parent 4869e55168
commit 257b627a3e
6 changed files with 14 additions and 14 deletions

View File

@ -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

View File

@ -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):

View File

@ -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:

View File

@ -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)

View File

@ -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 <tt>ORCHESTRA_BASE_DOMAIN</tt>."
)
MAILBOXES_MAIL_LOG_PATH = Setting('MAILBOXES_MAIL_LOG_PATH',
'/var/log/mail.log'

View File

@ -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)