mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
from django import forms
|
|
from mailng.admin.models import Domain, Mailbox, Alias
|
|
from django.utils.translation import ugettext as _
|
|
|
|
class DomainForm(forms.ModelForm):
|
|
class Meta:
|
|
model = Domain
|
|
|
|
class MailboxForm(forms.ModelForm):
|
|
quota = forms.IntegerField(label=_("Quota"), required=False)
|
|
password1 = forms.CharField(label=_("Password"), widget=forms.PasswordInput)
|
|
password2 = forms.CharField(label=_("Confirmation"), widget=forms.PasswordInput)
|
|
enabled = forms.BooleanField(label=_("Enabled"), required=False)
|
|
|
|
class Meta:
|
|
model = Mailbox
|
|
fields = ('name', 'address')
|
|
|
|
def clean_password2(self):
|
|
if self.cleaned_data["password1"] != self.cleaned_data["password2"]:
|
|
raise forms.ValidationError(_("Passwords mismatch"))
|
|
return self.cleaned_data["password2"]
|
|
|
|
class AliasForm(forms.ModelForm):
|
|
def __init__(self, *args, **kwargs):
|
|
domain = None
|
|
if kwargs.has_key("domain"):
|
|
domain = kwargs["domain"]
|
|
del kwargs["domain"]
|
|
super(AliasForm, self).__init__(*args, **kwargs)
|
|
if domain:
|
|
self.fields['mbox'].queryset = Mailbox.objects.filter(domain=domain.id)
|
|
|
|
class Meta:
|
|
model = Alias
|
|
fields = ('address', 'mbox', 'enabled')
|
|
|