Some work about ticket #22

This commit is contained in:
tonio
2010-05-05 20:47:12 +02:00
parent 846d298f44
commit 7ad7c1f48e
15 changed files with 89 additions and 81 deletions
+2 -1
View File
@@ -57,7 +57,8 @@ def urls():
def menu(**kwargs):
if kwargs["target"] == "user_menu_box":
return [
{"name" : _("Quarantine"),
{"name" : "quarantine",
"label" : _("Quarantine"),
"url" : reverse(index),
"img" : "/static/pics/quarantine.png"}
]
+13
View File
@@ -0,0 +1,13 @@
from django import forms
from models import ARmessage
from django.utils.translation import ugettext as _
class ARmessageForm(forms.ModelForm):
class Meta:
model = ARmessage
fields = ('subject', 'content', 'enabled')
def __init__(self, *args, **kwargs):
super(ARmessageForm, self).__init__(*args, **kwargs)
self.fields['subject'].widget.attrs['size'] = 40
self.fields['content'].widget.attrs['cols'] = 50
+42 -5
View File
@@ -7,11 +7,21 @@ This module provides a way to integrate MailNG auto-reply
functionality into Postfix.
"""
from django.contrib.auth.decorators \
import login_required
from django.conf.urls.defaults import include
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext as _
from mailng.lib import events, parameters
from mailng import main
from models import Transport, Alias
from mailng.lib import _render, events, parameters
from forms import *
from models import *
def infos():
return {
"name" : "Postfix autoreply",
"version" : "1.0",
"description" : "Auto-reply (vacation) functionality using Postfix"
}
def init():
events.register("CreateDomain", onCreateDomain)
@@ -26,14 +36,15 @@ def init():
help=_("Timeout in seconds between two auto-replies to the same recipient"))
def urls():
return ()
return (r'^mailng/postfix_autoreply/',
include('mailng.extensions.postfix_autoreply.urls'))
def menu(**kwargs):
if kwargs["target"] != "user_menu_bar":
return []
return [
{"name" : "autoreply",
"url" : reverse(main.views.autoreply),
"url" : reverse(autoreply),
"img" : "/static/pics/auto-reply.png",
"label" : _("Auto-reply message")}
]
@@ -76,3 +87,29 @@ def onModifyMailbox(**kwargs):
alias.autoreply_address = \
"%s@autoreply.%s" % (mbox.full_address, mbox.domain.name)
alias.save()
@login_required
def autoreply(request):
mb = Mailbox.objects.get(user=request.user.id)
try:
arm = ARmessage.objects.get(mbox=mb.id)
except ARmessage.DoesNotExist:
arm = None
if request.method == "POST":
if arm:
form = ARmessageForm(request.POST, instance=arm)
else:
form = ARmessageForm(request.POST)
error = None
if form.is_valid():
arm = form.save(commit=False)
arm.mbox = mb
arm.save()
request.user.message_set.create(
message=_("Auto reply message updated successfully.")
)
form = ARmessageForm(instance=arm)
return _render(request, "postfix_autoreply/autoreply.html", {
"form" : form
})
+13
View File
@@ -1,4 +1,5 @@
from django.db import models
from django.utils.translation import ugettext_lazy as _
from mailng.admin.models import Domain, Mailbox
class Transport(models.Model):
@@ -8,3 +9,15 @@ class Transport(models.Model):
class Alias(models.Model):
full_address = models.CharField(max_length=255)
autoreply_address = models.CharField(max_length=255)
class ARmessage(models.Model):
mbox = models.ForeignKey(Mailbox)
subject = models.CharField(_('subject'), max_length=255)
content = models.TextField(_('content'))
enabled = models.BooleanField(_('enabled'))
# untildate = models.DateTimeField(_('until'))
class ARhistoric(models.Model):
armessage = models.ForeignKey(ARmessage)
last_sent = models.DateTimeField(auto_now=True)
sender = models.TextField()
@@ -1,4 +1,4 @@
{% extends "main/header.html" %}
{% extends "userprefs/header.html" %}
{% load i18n %}
{% block html_head %}
<link rel="stylesheet" type="text/css" href="/static/stylesheets/box.css" />
@@ -6,10 +6,6 @@
<script src="/static/js/datepicker.js" type="text/javascript"></script>
<script src="/static/js/main.js" type="text/javascript"></script>
{% endblock %}
{% block menu %}
{% load main_extras %}
{% menu "autoreply" perms %}
{% endblock %}
{% block subcontent %}
<form action="" method="POST" id="armform" name="armform" class="simple">
{% include "common/genericform.html" %}
+5
View File
@@ -0,0 +1,5 @@
from django.conf.urls.defaults import *
urlpatterns = patterns('mailng.extensions.postfix_autoreply.main',
url(r'^$', 'autoreply'),
)
+2 -6
View File
@@ -1,10 +1,6 @@
window.addEvent('domready', function(){
parse_menubar('topmenubar');
SqueezeBox.assign($$('a.boxed'), {
parse: 'rel',
});
infobox = new InfoBox({
parent : $("menubar"),
message : "Loading"
@@ -248,7 +244,7 @@ confirmation = function(question, action, callback) {
}
}
});
SqueezeBox.open("/mailng/main/confirm/?question=" + question);
SqueezeBox.open("/mailng/userprefs/confirm/?question=" + question);
}
setDivHeight = function(id, extrah, modulo) {
-4
View File
@@ -1,8 +1,4 @@
window.addEvent('domready', function() {
SqueezeBox.assign($$('a.boxed'), {
parse: 'rel'
});
new DatePicker("#untildate", {
pickerClass: "datepicker_vista",
allowEmpty: true
+4 -2
View File
@@ -175,6 +175,8 @@ div#footer {
border-bottom: 5px solid #ccc;
border-right: 5px solid #ccc;
border-left: 5px solid #ccc;
position: relative;
z-index: 2;
}
div.left {
@@ -193,8 +195,6 @@ div.right {
.dropdown {
/*position: absolute;*/
position: relative;
z-index: 2;
/*width: 250px;*/
}
@@ -214,6 +214,8 @@ div.right {
border-left: 5px solid #333;
width: 150px;
float: left;
position: relative;
z-index: 4;
}
.dropdown ul li {
+4 -1
View File
@@ -8,7 +8,10 @@
{% if entry.width %}style="width: {{ entry.width }}px"{% endif %}>
{% for sentry in entry.menu %}
<li>
<a href="{{ sentry.url }}" name="{{ sentry.name }}">
<a href="{{ sentry.url }}" name="{{ sentry.name }}"
{% if sentry.class %}class={{ sentry.class }}{% endif %}
{% if sentry.rel %}rel={{ sentry.rel }}{% endif %}
{% if sentry.confirm %} onclick="return confirm('{{ sentry.confirm }}')"{% endif %}>
<img src="{{ sentry.img }}" border="0" alt="" />
{{ sentry.label }}
</a>
-11
View File
@@ -1,18 +1,7 @@
from django import forms
from models import ARmessage
from mailng.lib.authbackends import check_password
from django.utils.translation import ugettext as _
class ARmessageForm(forms.ModelForm):
class Meta:
model = ARmessage
fields = ('subject', 'content', 'enabled', 'untildate')
def __init__(self, *args, **kwargs):
super(ARmessageForm, self).__init__(*args, **kwargs)
self.fields['subject'].widget.attrs['size'] = 40
self.fields['content'].widget.attrs['cols'] = 50
class ChangePasswordForm(forms.Form):
oldpassword = forms.CharField(label=_("Old password"),
widget=forms.PasswordInput)
-15
View File
@@ -1,15 +0,0 @@
from django.db import models
from django.utils.translation import ugettext_lazy as _
from mailng.admin.models import Mailbox
class ARmessage(models.Model):
mbox = models.ForeignKey(Mailbox)
subject = models.CharField(_('subject'), max_length=255)
content = models.TextField(_('content'))
enabled = models.BooleanField(_('enabled'))
# untildate = models.DateTimeField(_('until'))
class ARhistoric(models.Model):
armessage = models.ForeignKey(ARmessage)
last_sent = models.DateTimeField(auto_now=True)
sender = models.TextField()
+2 -2
View File
@@ -24,8 +24,8 @@ def uprefs_menu(perms):
]
}
]
entries[0]["menu"] += [events.raiseQueryEvent("UserMenuDisplay",
target="user_menu_bar")]
entries[0]["menu"] += events.raiseQueryEvent("UserMenuDisplay",
target="user_menu_bar")
return render_to_string('common/menulist.html',
{"entries" : entries, "perms" : perms})
-1
View File
@@ -2,7 +2,6 @@ from django.conf.urls.defaults import *
urlpatterns = patterns('mailng.userprefs.views',
url(r'^$', 'index'),
url(r'^autoreply/$', 'autoreply'),
(r'^changepassword/$', 'changepassword'),
(r'^confirm/$', 'confirm'),
)
+1 -28
View File
@@ -10,8 +10,7 @@ from django.utils import simplejson
from django.utils.translation import ugettext as _
from mailng.lib import _render, _ctx_ok, _ctx_ko
from mailng.lib.authbackends import crypt_password
from forms import ARmessageForm, ChangePasswordForm
from models import ARmessage
from forms import ChangePasswordForm
from mailng.admin.models import Mailbox
@login_required
@@ -23,32 +22,6 @@ def index(request):
arm = None
return _render(request, "userprefs/index.html", {"arm" : arm})
@login_required
def autoreply(request):
mb = Mailbox.objects.get(user=request.user.id)
try:
arm = ARmessage.objects.get(mbox=mb.id)
except ARmessage.DoesNotExist:
arm = None
if request.method == "POST":
if arm:
form = ARmessageForm(request.POST, instance=arm)
else:
form = ARmessageForm(request.POST)
error = None
if form.is_valid():
arm = form.save(commit=False)
arm.mbox = mb
arm.save()
request.user.message_set.create(
message=_("Auto reply message updated successfully.")
)
form = ARmessageForm(instance=arm)
return _render(request, "userprefs/autoreply.html", {
"form" : form
})
@login_required
def changepassword(request):
mb = Mailbox.objects.get(user=request.user.id)