mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-23 06:38:40 +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):
|
||||
|
||||
Reference in New Issue
Block a user