mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
+6
-1
@@ -1,5 +1,5 @@
|
||||
from django import forms
|
||||
from modoboa.admin.models import Domain, Mailbox, Alias
|
||||
from modoboa.admin.models import *
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.contrib.auth.models import User
|
||||
from modoboa.admin.templatetags.admin_extras import gender
|
||||
@@ -14,6 +14,11 @@ class DomainForm(forms.ModelForm):
|
||||
for f in ['name', 'quota']:
|
||||
self.fields[f].widget.attrs['size'] = 14
|
||||
|
||||
class DomainAliasForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = DomainAlias
|
||||
fields = ('name', 'target', 'enabled')
|
||||
|
||||
class MailboxForm(forms.ModelForm):
|
||||
quota = forms.IntegerField(label=_("Quota"), required=False,
|
||||
help_text=_("Mailbox quota in MB (default to domain quota if blank)"))
|
||||
|
||||
@@ -36,6 +36,14 @@ class Domain(models.Model):
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
class DomainAlias(models.Model):
|
||||
name = models.CharField(_("name"), max_length=100, unique=True,
|
||||
help_text=_("The alias name"))
|
||||
target = models.ForeignKey(Domain, verbose_name=_('target'),
|
||||
help_text=_("The domain this alias points to"))
|
||||
enabled = models.BooleanField(_('enabled'),
|
||||
help_text=_("Check to activate this alias"))
|
||||
|
||||
class Mailbox(models.Model):
|
||||
name = models.CharField(_('name'), max_length=100,
|
||||
help_text=_("First name and last name of mailbox owner"))
|
||||
|
||||
@@ -120,7 +120,11 @@ def domains_menu(selection, user):
|
||||
{"name" : "domains",
|
||||
"url" : reverse(admin.views.domains),
|
||||
"label" : _("Domains"),
|
||||
"img" : static_url("pics/domains.png")}
|
||||
"img" : static_url("pics/domains.png")},
|
||||
{"name" : "domaliases",
|
||||
"url" : reverse(admin.views.domaliases),
|
||||
"label" : _("Domain aliases"),
|
||||
"img" : static_url("pics/alias.png")}
|
||||
]
|
||||
entries += events.raiseQueryEvent("AdminMenuDisplay", target="admin_menu_box",
|
||||
user=user)
|
||||
|
||||
@@ -6,6 +6,10 @@ urlpatterns = patterns('modoboa.admin.views',
|
||||
(r'^domains/new/', 'newdomain'),
|
||||
(r'^domains/(?P<dom_id>\d+)/edit/$', 'editdomain'),
|
||||
(r'^domains/(?P<dom_id>\d+)/delete/$', 'deldomain'),
|
||||
|
||||
(r'^aliases/$', "domaliases"),
|
||||
(r'^aliases/new/(?P<dom_id>\d+)/', 'newdomalias'),
|
||||
|
||||
(r'^domains/(?P<dom_id>\d+)/newmailbox/$', 'newmailbox'),
|
||||
(r'^domains/(?P<dom_id>\d+)/editmailbox/(?P<mbox_id>\d+)/$', 'editmailbox'),
|
||||
(r'^domains/(?P<dom_id>\d+)/deletemailbox/(?P<mbox_id>\d+)/$', 'delmailbox'),
|
||||
|
||||
@@ -53,6 +53,39 @@ def domains(request):
|
||||
"domains" : domains, "counters" : counters
|
||||
})
|
||||
|
||||
@login_required
|
||||
def domaliases(request, dom_id=None):
|
||||
domaliases = DomainAlias.objects.all()
|
||||
return _render(request, 'admin/domaliases.html', {
|
||||
"domaliases" : domaliases
|
||||
})
|
||||
|
||||
@login_required
|
||||
def newdomalias(request, dom_id):
|
||||
domain = Domain.objects.get(pk=dom_id)
|
||||
if request.method == "POST":
|
||||
form = DomainAliasForm(request.POST)
|
||||
error = None
|
||||
if form.is_valid():
|
||||
if DomainAlias.objects.filter(name=request.POST["name"]):
|
||||
error = _("Alias with this name already exists")
|
||||
else:
|
||||
domalias = form.save(commit=False)
|
||||
domalias.save()
|
||||
ctx = _ctx_ok(reverse(admin.views.domaliases))
|
||||
messages.info(request, _("Domain alias created"), fail_silently=True)
|
||||
return HttpResponse(simplejson.dumps(ctx),
|
||||
mimetype="application/json")
|
||||
content = _render_to_string(request, "admin/newdomalias.html", {
|
||||
"form" : form, "error" : error
|
||||
})
|
||||
ctx = getctx("ko", content=content)
|
||||
return HttpResponse(simplejson.dumps(ctx), mimetype="application/json")
|
||||
form = DomainAliasForm()
|
||||
return _render(request, 'admin/newdomalias.html', {
|
||||
"form" : form
|
||||
})
|
||||
|
||||
@login_required
|
||||
@permission_required("admin.add_domain")
|
||||
def newdomain(request):
|
||||
|
||||
@@ -30,6 +30,9 @@ window.addEvent("domready", function() {
|
||||
domain_submit = function(event) {
|
||||
generic_submit(this, event, "domform", domain_submit);
|
||||
};
|
||||
domalias_submit = function(event) {
|
||||
generic_submit(this, event, "domaliasform", domalias_submit);
|
||||
};
|
||||
mailbox_submit = function(event) {
|
||||
generic_submit(this, event, "mboxform", mailbox_submit);
|
||||
};
|
||||
@@ -60,6 +63,9 @@ window.addEvent("domready", function() {
|
||||
if ($("domform"))
|
||||
$("domform").addEvent("submit", domain_submit);
|
||||
|
||||
if ($("domaliasform"))
|
||||
$("domaliasform").addEvent("submit", domalias_submit);
|
||||
|
||||
if ($("mboxform"))
|
||||
$("mboxform").addEvent("submit", mailbox_submit);
|
||||
|
||||
|
||||
@@ -16,12 +16,11 @@
|
||||
{% display_messages messages %}
|
||||
{% endif %}
|
||||
<div id="domcontent">
|
||||
{% if not domains %}
|
||||
{% trans "No domain defined." %}
|
||||
{% if not domains %}<div class="info">{% trans "No domain defined." %}</div>
|
||||
{% else %}
|
||||
<table>
|
||||
<tr>
|
||||
<th width="50px">{% trans "Actions" %}</th>
|
||||
<th width="100px">{% trans "Actions" %}</th>
|
||||
<th>{% trans "Name" %}</th>
|
||||
<th width="150px">{% trans "Mailboxes" %}</th>
|
||||
<th width="50px">{% trans "Quota" %}</th>
|
||||
@@ -39,6 +38,11 @@
|
||||
<a href="{{ del_url }}" name="deleteDom">
|
||||
<img src="{{ MEDIA_URL }}pics/remove.png" border="0" title="{% trans 'Delete domain' %}"/>
|
||||
</a>
|
||||
{% url admin.views.newdomalias dom.id as new_url %}
|
||||
<a href="{{ new_url }}" class="boxed"
|
||||
rel="{handler:'iframe',size:{x:300,y:180}}">
|
||||
<img src="{{ MEDIA_URL }}pics/add.png" border="0" title="{% trans 'Add domain alias' %}"/>
|
||||
</a>
|
||||
</td>
|
||||
{% url admin.views.mailboxes dom.id as domurl %}
|
||||
<td>{{ dom.name }}</td>
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
{% extends "nlayout.html" %}
|
||||
{% load i18n admin_extras libextras %}
|
||||
{% block html_head %}
|
||||
<script src="{{ MEDIA_URL }}js/domains.js" type="text/javascript"></script>
|
||||
<script type="text/javascript">
|
||||
</script>
|
||||
{% endblock %}
|
||||
{% block middletitle %}{% trans "Available aliases" %}{% endblock %}
|
||||
{% block menu %}{% domains_menu "domaliases" user %}{% endblock %}
|
||||
{% block content %}
|
||||
{% if messages %}{% display_messages messages %}{% endif %}
|
||||
<div id="domcontent">
|
||||
{% if not domaliases %}
|
||||
<div class="info">{% trans "No domain alias defined." %}</div>
|
||||
{% else %}
|
||||
<table>
|
||||
<tr>
|
||||
<th width="50px">{% trans "Actions" %}</th>
|
||||
<th width="150px">{% trans "Name" %}</th>
|
||||
<th width="200px">{% trans "Targeted domain" %}</th>
|
||||
<th width="75px">{% trans "Enabled" %}</th>
|
||||
</tr>
|
||||
{% for domalias in domaliases %}
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>{{ domalias.name }}</td>
|
||||
<td>{{ domalias.target.name }}</td>
|
||||
<td>{{ domalias.enabled|yesno }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,17 @@
|
||||
{% extends "layout_simple.html" %}
|
||||
{% load i18n %}
|
||||
{% block html_head %}
|
||||
<script src="{{ MEDIA_URL }}js/form.js" type="text/javascript"></script>
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
<div class="title"><h1>{% trans "New domain alias" %}</h1></div>
|
||||
{% if error %}<div class="error">{{ error }}</div>{% endif %}
|
||||
{% url admin.views.newdomalias domain as box_url %}
|
||||
<form action="{{ box_url }}" method="POST" id="domaliasform" name="domaliasform">
|
||||
{% include "common/genericform.html" %}
|
||||
<div class="spacer"></div>
|
||||
<div class="lastrow" align="center">
|
||||
<input type="submit" name="submit" value="{% trans 'Create' %}" />
|
||||
</div>
|
||||
</form>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user