aboutsummaryrefslogtreecommitdiff
path: root/src/django_pgpmailman/forms.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/django_pgpmailman/forms.py')
-rw-r--r--src/django_pgpmailman/forms.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/django_pgpmailman/forms.py b/src/django_pgpmailman/forms.py
index 493d3d8..3083274 100644
--- a/src/django_pgpmailman/forms.py
+++ b/src/django_pgpmailman/forms.py
@@ -17,6 +17,7 @@
# this program. If not, see <http://www.gnu.org/licenses/>.
from django import forms
from django.core.exceptions import ValidationError
+from django.core.validators import validate_email
from django.utils.translation import ugettext_lazy as _
from pgpy import PGPKey
@@ -196,3 +197,58 @@ class ListKeyManagementForm(forms.Form):
'has the same key material and contains the UID that '
'was signed.')
)
+
+
+class ListCreateForm(forms.Form):
+ listname = forms.CharField(
+ label=_('List Name'),
+ required=True,
+ error_messages={
+ 'required': _('Please enter a name for your list.'),
+ 'invalid': _('Please enter a valid list name.')})
+ mail_host = forms.ChoiceField()
+ list_owner = forms.EmailField(
+ label=_('Inital list owner address'),
+ error_messages={
+ 'required': _(
+ 'Please enter the list owner\'s email address.')},
+ required=True)
+ advertised = forms.ChoiceField(
+ widget=forms.RadioSelect(),
+ label=_('Advertise this list?'),
+ error_messages={
+ 'required': _('Please choose a list type.')},
+ required=True,
+ choices=(
+ (True, _('Advertise this list in list index')),
+ (False, _('Hide this list in list index'))))
+ description = forms.CharField(
+ label=_('Description'),
+ required=False)
+ list_style = forms.ChoiceField()
+
+ def __init__(self, domain_choices=None, style_choices=None, *args, **kwargs):
+ super(ListCreateForm, self).__init__(*args, **kwargs)
+ self.fields['mail_host'] = forms.ChoiceField(
+ widget=forms.Select(),
+ label=_('Mail Host'),
+ required=True,
+ choices=domain_choices,
+ error_messages={'required': _('Choose an existing Domain.'),
+ 'invalid': _('Invalid mail host')})
+ self.fields['list_style'] = forms.ChoiceField(
+ widget=forms.Select(),
+ label=_('List style'),
+ required=True,
+ choices=style_choices
+ )
+ if len(domain_choices) < 2:
+ self.fields['mail_host'].help_text = _(
+ 'Site admin has not created any domains')
+
+ def clean_listname(self):
+ try:
+ validate_email(self.cleaned_data['listname'] + '@example.net')
+ except:
+ raise forms.ValidationError(_('Please enter a valid listname'))
+ return self.cleaned_data['listname']