Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ListNewTest(unittest.TestCase):
- def setUp(self):
- self.form_data = {
- 'listname' : 'test_list1',
- 'mail_host': 'mailman.most-desirable.org',
- 'list_owner': 'james@example.com',
- 'advertised': True,
- 'description': 'The Most Desirable organization',
- }
- self.domain_choices = ['mailman.most-desirable.org']
- def test_form_fields_listname(self):
- form = ListNew(self.form_data)
- self.assertTrue(form.is_valid())
- def test_form_fields_listname_invalid(self):
- self.form_data['listname'] = 'test$list1'
- form = ListNew(self.form_data)
- self.assertFalse(form.is_valid())
- -----------------------------------------------------------------------
- class ListNew(FieldsetForm):
- """
- Form fields to add a new list. Languages are hard coded which should
- be replaced by a REST lookup of available languages.
- """
- 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=True)
- def __init__(self, domain_choices, *args, **kwargs):
- super(ListNew, 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': "ERROR-todo_forms.py"})
- if len(domain_choices) < 2:
- self.fields["mail_host"].help_text = _(
- "Site admin has not created any domains")
- # if len(choices) < 2:
- # help_text=_("No domains available: " +
- # "The site admin must create new domains " +
- # "before you will be able to create a list")
- def clean_listname(self):
- listname = self.cleaned_data.get('listname')
- try:
- validate_slug(listname)
- except:
- raise forms.ValidationError(_("Please enter a valid listname"))
- return listname
- class Meta:
- """
- Class to handle the automatic insertion of fieldsets and divs.
- To use it: add a list for each wished fieldset. The first item in
- the list should be the wished name of the fieldset, the following
- the fields that should be included in the fieldset.
- """
- layout = [["List Details",
- "listname",
- "mail_host",
- "list_owner",
- "description",
- "advertised"], ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement