Skip to content
Permalink
Browse files

PEP8 fixes

  • Loading branch information...
tonioo committed Jan 15, 2015
1 parent 934525f commit 5e71ed1917b1b1ffe58f1a00c0d022bed02a703c
@@ -7,23 +7,27 @@
"""
import sys

from django.utils.translation import ugettext_lazy
from modoboa.lib import events, parameters

from modoboa.core.extensions import ModoExtension, exts_pool
from modoboa.extensions.postfix_autoreply.models import (
Transport, Alias
)
from modoboa.lib import events, parameters


class PostfixAutoreply(ModoExtension):

"""
Auto-reply (vacation) functionality using Postfix.
"""
name = "postfix_autoreply"
label = "Postfix autoreply"
version = "1.0"
description = ugettext_lazy("Auto-reply (vacation) functionality using Postfix")
description = ugettext_lazy(
"Auto-reply (vacation) functionality using Postfix")

def init(self):
from modoboa.extensions.admin.models import Domain
@@ -45,10 +49,14 @@ def init(self):
onMailboxCreated(None, mb)

def load(self):
from modoboa.extensions.postfix_autoreply.app_settings import ParametersForm
parameters.register(ParametersForm, ugettext_lazy("Automatic replies"))
from modoboa.extensions.postfix_autoreply.app_settings import (
ParametersForm
)
parameters.register(
ParametersForm, ugettext_lazy("Automatic replies"))
from modoboa.extensions.postfix_autoreply import general_callbacks
if 'modoboa.extensions.postfix_autoreply.general_callbacks' in sys.modules:
modname = "modoboa.extensions.postfix_autoreply.general_callbacks"
if modname in sys.modules:
reload(general_callbacks)

def destroy(self):
@@ -1,8 +1,12 @@
# coding: utf-8
from django.utils.translation import ugettext_lazy

"""Custom settings."""

from django import forms
from modoboa.lib.parameters import AdminParametersForm
from django.utils.translation import ugettext_lazy

from modoboa.lib.form_utils import SeparatorField
from modoboa.lib.parameters import AdminParametersForm


class ParametersForm(AdminParametersForm):
@@ -13,15 +17,18 @@ class ParametersForm(AdminParametersForm):
autoreplies_timeout = forms.IntegerField(
label=ugettext_lazy("Automatic reply timeout"),
initial=86400,
help_text=ugettext_lazy("Timeout in seconds between two auto-replies to the same recipient"),
help_text=ugettext_lazy(
"Timeout in seconds between two auto-replies to the same recipient"
),
widget=forms.TextInput(attrs={"class": "form-control"})
)

default_subject = forms.CharField(
label=ugettext_lazy("Default subject"),
initial=ugettext_lazy("I'm off"),
help_text=ugettext_lazy(
"Default subject used when an auto-reply message is created automatically"
"Default subject used when an auto-reply message is created "
"automatically"
),
widget=forms.TextInput(attrs={"class": "form-control"})
)
@@ -1,11 +1,16 @@
# coding: utf-8

"""Custom forms."""

from django import forms
from django.utils.translation import ugettext as _, ugettext_lazy
from django.utils import timezone
from django.utils.translation import ugettext as _, ugettext_lazy

from .models import ARmessage


class ARmessageForm(forms.ModelForm):

fromdate = forms.DateTimeField(
label=ugettext_lazy('From'),
required=False,
@@ -23,15 +28,15 @@ class ARmessageForm(forms.ModelForm):
)
)
subject = forms.CharField(
widget=forms.TextInput(
attrs={'class': 'form-control'}
)
widget=forms.TextInput(
attrs={'class': 'form-control'}
)
)
content = forms.CharField(
widget=forms.Textarea(
attrs={'class': 'form-control'}
)
widget=forms.Textarea(
attrs={'class': 'form-control'}
)
)

class Meta:
model = ARmessage
@@ -67,13 +72,14 @@ def clean(self):
else:
self.cleaned_data['fromdate'] = timezone.now()
if self.cleaned_data["untildate"] is not None:
if self.cleaned_data["untildate"] < timezone.now():
untildate = self.cleaned_data["untildate"]
if untildate < timezone.now():
self._errors["untildate"] = self.error_class(
[_("This date is over")])
del self.cleaned_data['untildate']
elif 'fromdate' in self.cleaned_data and \
self.cleaned_data['untildate'] < self.cleaned_data['fromdate']:
del self.cleaned_data["untildate"]
elif "fromdate" in self.cleaned_data and \
untildate < self.cleaned_data["fromdate"]:
self._errors["untildate"] = \
self.error_class([_("Must be greater than start date")])
del self.cleaned_data['untildate']
del self.cleaned_data["untildate"]
return self.cleaned_data
@@ -1,8 +1,11 @@
"""Event callbacks."""

from django.utils import timezone
from django.utils.translation import ugettext_lazy
from modoboa.lib import events, parameters
from modoboa.extensions.postfix_autoreply.models import Transport, Alias

from .models import ARmessage
from modoboa.extensions.postfix_autoreply.models import Transport, Alias
from modoboa.lib import events, parameters


@events.observe("ExtraUprefsJS")
@@ -45,8 +48,11 @@ def onDomainModified(domain):
return
Transport.objects.filter(domain="autoreply.%s" % domain.oldname) \
.update(domain="autoreply.%s" % domain.name)
for al in Alias.objects.filter(full_address__contains="@%s" % domain.oldname):
new_address = al.full_address.replace("@%s" % domain.oldname, "@%s" % domain.name)
for al in Alias.objects.filter(
full_address__contains="@%s" % domain.oldname):
new_address = al.full_address.replace(
"@%s" % domain.oldname,
"@%s" % domain.name)
al.full_address = new_address
al.autoreply_address = "%s@autoreply.%s" % (new_address, domain.name)
al.save()
@@ -18,7 +18,7 @@ def send_autoreply(sender, mailbox, armessage):
if armessage.fromdate > timezone.now():
return
if armessage.untildate is not None \
and armessage.untildate < timezone.now():
and armessage.untildate < timezone.now():
armessage.enabled = False
armessage.save()
return
@@ -51,7 +51,8 @@ class Command(BaseCommand, CloseConnectionMixin):

def handle(self, *args, **options):
if len(args) < 2:
raise CommandError("usage: ./manage.py autoreply <sender> <recipient ...>")
raise CommandError(
"usage: ./manage.py autoreply <sender> <recipient ...>")

sender = args[0]
for fulladdress in args[1:]:
@@ -82,7 +82,6 @@ def test_mailbox_deleted_event(self):
ARmessage.objects.get(
mbox__address='user', mbox__domain__name='test.com')


def test_modify_mailbox_event(self):
values = {
'username': "leon@test.com",

0 comments on commit 5e71ed1

Please sign in to comment.
You can’t perform that action at this time.