First working implementation of ticket #3.

This commit is contained in:
tonio
2009-06-12 16:37:44 +02:00
parent 428cd4f143
commit ae68c14396
14 changed files with 125 additions and 5 deletions
+11
View File
@@ -6,6 +6,11 @@ from mailng.admin.templatetags.admin_extras import gender
class DomainForm(forms.ModelForm):
class Meta:
model = Domain
def __init__(self, *args, **kwargs):
super(DomainForm, self).__init__(*args, **kwargs)
for f in ['name', 'quota']:
self.fields[f].widget.attrs['size'] = 14
class MailboxForm(forms.ModelForm):
quota = forms.IntegerField(label=_("Quota"), required=False)
@@ -17,6 +22,11 @@ class MailboxForm(forms.ModelForm):
model = Mailbox
fields = ('name', 'address')
def __init__(self, *args, **kwargs):
super(MailboxForm, self).__init__(*args, **kwargs)
for f in ['name', 'address', 'quota', 'password1', 'password2']:
self.fields[f].widget.attrs['size'] = 14
def clean_password2(self):
if self.cleaned_data["password1"] != self.cleaned_data["password2"]:
raise forms.ValidationError(_("Passwords mismatch"))
@@ -29,6 +39,7 @@ class AliasForm(forms.ModelForm):
domain = kwargs["domain"]
del kwargs["domain"]
super(AliasForm, self).__init__(*args, **kwargs)
self.fields['address'].widget.attrs['size'] = 14
if domain:
self.fields['mbox'].queryset = Mailbox.objects.filter(domain=domain.id)
+5
View File
@@ -1,8 +1,13 @@
from django import forms
from mailng.main.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
+5 -1
View File
@@ -3,7 +3,11 @@ from mailng.admin.models import Mailbox
class ARmessage(models.Model):
mbox = models.ForeignKey(Mailbox)
last_sent = models.DateField(auto_now=True)
subject = models.CharField(max_length=255)
content = models.TextField()
enabled = models.BooleanField()
class ARhistoric(models.Model):
armessage = models.ForeignKey(ARmessage)
last_sent = models.DateTimeField(auto_now=True)
sender = models.TextField()
+3
View File
@@ -29,6 +29,9 @@ def autoreply(request):
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, "main/autoreply.html", {
+44
View File
@@ -0,0 +1,44 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from email.mime.text import MIMEText
import datetime
from django.conf import settings
from mailng.admin.models import Mailbox
from mailng.main.models import ARmessage, ARhistoric
if __name__ == "__main__":
if len(sys.argv) != 3:
print "Not enough arguments, aborting."
sys.exit(1)
sender = sys.argv[1]
mailbox = sys.argv[2]
mbox = Mailbox.objects.get(full_address=mailbox)
try:
armessage = ARmessage.objects.get(mbox=mbox.id, enabled=True)
except ARmessage.DoesNotExist:
sys.exit(0)
try:
lastar = ARhistoric.objects.get(armessage=armessage.id, sender=sender)
try:
timeout = getattr(settings, "AUTOREPLIES_TIMEOUT")
except AttributeError:
timeout = 86400 # 24h
delta = datetime.timedelta(seconds=timeout)
if lastar.last_sent + delta > datetime.datetime.now():
sys.exit(0)
except ARhistoric.DoesNotExist:
lastar = ARhistoric()
lastar.armessage = armessage
lastar.sender = sender
msg = MIMEText(armessage.content.encode('utf-8'), _charset='utf-8')
msg['Subject'] = armessage.subject
msg['From'] = mailbox
msg['To'] = sender
print msg
lastar.last_sent = datetime.datetime.now()
lastar.save()
sys.exit(0)
+3
View File
@@ -94,3 +94,6 @@ VIRTUAL_GID = "vmail"
# Mailboxes format: maildir (default) or mbox
# MAILBOX_TYPE = ""
# Autoreplies sending timeout (default: 86400s)
# AUTOREPLIES_TIMEOUT =
Binary file not shown.

After

Width:  |  Height:  |  Size: 628 B

+12
View File
@@ -136,6 +136,11 @@ body {
margin: 0 0 0 15px;
}
#content2 {
}
#menubar {
margin-left: 20px;
display: table;
@@ -285,4 +290,11 @@ body {
#setcontent h4 {
margin-top: 0;
}
#infos {
float: right;
color: green;
font-weight: bold;
margin-right: 10px;
}
+8 -1
View File
@@ -23,7 +23,6 @@ form input {
color: inherit;
/*background-color: #e9e9e9;*/
background-color: #eee;
width: 120px;
padding: 2px;
}
@@ -71,4 +70,12 @@ form input:hover {
color: red;
font-size: small;
font-weight: bold;
}
#id_username {
width: 120px;
}
#id_password {
width: 120px;
}
+14
View File
@@ -33,6 +33,20 @@
<h3>{{ user.username }}</h3>
{% endif %}
<ul>
{% if user.is_superuser or perms.admin.view_domain %}
<li>
{% url admin.views.domains as dom_url %}
<a href="{{ dom_url }}">
<img src="/static/pics/settings.png" border="0" />{% trans "Admin" %}</a>
</li>
{% endif %}
{% if not user.is_superuser %}
<li>
{% url main.views.index as index_url %}
<a href="{{ index_url }}">
<img src="/static/pics/user.png" border="0" />{% trans "Preferences" %}</a>
</li>
{% endif %}
<li>
{% url django.contrib.auth.views.logout_then_login as logout_url %}
<a href="{{ logout_url }}">
+1 -1
View File
@@ -8,7 +8,7 @@
{% menu "autoreply" perms %}
{% endblock %}
{% block subcontent %}
<form action="" method="POST" id="armform" name="armform">
<form action="" method="POST" id="armform" name="armform" class="simple">
{% include "genericform.html" %}
<div class="spacer"></div>
+7
View File
@@ -3,6 +3,13 @@
{% load i18n %}
<div class="header">
<h1>{% trans "General" %}</h1>
{% if messages %}
<div id="infos">
{% for m in messages %}
{{ m }}
{% endfor %}
</div>
{% endif %}
</div>
<div id="menubar" class="menu2">
+9
View File
@@ -0,0 +1,9 @@
{% extends "main/header.html" %}
{% load i18n %}
{% block menu %}
{% load main_extras %}
{% menu "" perms %}
{% endblock %}
{% block subcontent %}
{% endblock %}
+3 -2
View File
@@ -4,8 +4,9 @@
<img src="/static/pics/edit.png" border="0"/>
{% trans "Change password" %}</a>
</li>
<li>
<a href=""><img src="/static/pics/auto-reply.png" border="0"/>
<li {% ifequal selection "autoreply" %}class="selected"{% endifequal %}>
{% url main.views.autoreply as ar_url %}
<a href="{{ ar_url }}"><img src="/static/pics/auto-reply.png" border="0"/>
{% trans "Auto-reply message" %}
</a>
</li>