Update po files
[mailman-postorious.git] / src / postorius / forms / domain_forms.py
blobe3a0e2fc5098e1d2ccc406daa3b99c6eef700627
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2012-2021 by the Free Software Foundation, Inc.
4 # This file is part of Postorius.
6 # Postorius is free software: you can redistribute it and/or modify it under
7 # the terms of the GNU General Public License as published by the Free
8 # Software Foundation, either version 3 of the License, or (at your option)
9 # any later version.
11 # Postorius is distributed in the hope that it will be useful, but WITHOUT
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 # more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Postorius. If not, see <http://www.gnu.org/licenses/>.
20 from django import forms
21 from django.contrib.sites.models import Site
22 from django.core.exceptions import ValidationError
23 from django.core.validators import validate_email
24 from django.urls import reverse
25 from django.utils.translation import gettext_lazy as _
27 from postorius.forms.fields import SiteModelChoiceField
30 def _get_web_host_help():
31 # Using a function is necessary, otherwise reverse() will be called before
32 # URLConfs are loaded.
33 return (_(
34 'The domain from which you want the web UI to be served from. '
35 'This can be same or different from the Mail Host. '
36 'You can edit the list of available web hosts <a href="%s">here</a>.'
37 ) % reverse("admin:sites_site_changelist"))
40 class DomainForm(forms.Form):
41 """
42 Form to add a domain.
43 """
44 mail_host = forms.CharField(
45 label=_('Mail Host'),
46 error_messages={'required': _('Please enter a domain name'),
47 'invalid': _('Please enter a valid domain name.')},
48 required=True,
49 help_text=_(
50 'The domain for your mailing lists. For example when you want '
51 'lists like testing@example.com, enter example.com here.'),
53 description = forms.CharField(
54 label=_('Description'),
55 required=False)
56 alias_domain = forms.CharField(
57 label=_('Alias Domain'),
58 error_messages={
59 'invalid': _('Please enter a valid domain name or nothing.')},
60 required=False,
61 help_text=_('Normally empty. Used only for unusual Postfix configs.'),
63 site = SiteModelChoiceField(
64 label=_('Web Host'),
65 error_messages={'required': _('Please enter a domain name'),
66 'invalid': _('Please enter a valid domain name.')},
67 required=True,
68 queryset=Site.objects.order_by("name").all(),
69 initial=lambda: Site.objects.get_current(),
70 help_text=_get_web_host_help,
73 def clean_mail_host(self):
74 mail_host = self.cleaned_data['mail_host']
75 try:
76 validate_email('mail@' + mail_host)
77 except ValidationError:
78 raise forms.ValidationError(_("Please enter a valid domain name"))
79 return mail_host
81 def clean_alias_domain(self):
82 alias_domain = self.cleaned_data['alias_domain']
83 if alias_domain != '':
84 try:
85 validate_email('mail@' + alias_domain)
86 except ValidationError:
87 raise forms.ValidationError(
88 _("Please enter a valid domain name or nothing."))
89 return alias_domain
92 class DomainEditForm(DomainForm):
93 """
94 Form to edit domains
95 separte from the DomainForm, so that the mail_host can't be changed.
96 """
97 mail_host = None
100 class DomainOwnerForm(forms.Form):
101 """Form to add a owner for a domain."""
102 email = forms.EmailField(
103 label=_("Owner's Email"),
104 required=True,