def test_form_fields_list_invalid(self): form = ListNew({ 'listname': 'xy#z', 'mail_host': 'mailman.most-desirable.org', 'list_owner': 'mailman.most-desirable.org', 'advertise': 'abcd', 'description': 'The Most Desirable organization', }) self.assertFalse(form.is_valid())
def test_form_fields_list(self): form = ListNew( [("mailman.most-desirable.org", "mailman.most-desirable.org")], { 'listname': 'xyz', 'mail_host': 'mailman.most-desirable.org', 'list_owner': '*****@*****.**', 'advertised': 'True', 'description': 'The Most Desirable organization', }) self.assertTrue(form.is_valid(), form.errors)
def test_form_fields_list_invalid(self): form = ListNew( { "listname": "xy#z", "mail_host": "mailman.most-desirable.org", "list_owner": "mailman.most-desirable.org", "advertise": "abcd", "description": "The Most Desirable organization", } ) self.assertFalse(form.is_valid())
def list_new(request, template='postorius/lists/new.html'): """ Add a new mailing list. If the request to the function is a GET request an empty form for creating a new list will be displayed. If the request method is POST the form will be evaluated. If the form is considered correct the list gets created and otherwise the form with the data filled in before the last POST request is returned. The user must be logged in to create a new list. """ mailing_list = None choosable_domains = [('', _('Choose a Domain'))] choosable_domains += _get_choosable_domains(request) if request.method == 'POST': form = ListNew(choosable_domains, request.POST) if form.is_valid(): # grab domain domain = Domain.objects.get_or_404( mail_host=form.cleaned_data['mail_host']) # creating the list try: mailing_list = domain.create_list( form.cleaned_data['listname']) mailing_list.add_owner(form.cleaned_data['list_owner']) list_settings = mailing_list.settings if form.cleaned_data['description']: list_settings["description"] = \ form.cleaned_data['description'] list_settings["advertised"] = form.cleaned_data['advertised'] list_settings.save() messages.success(request, _("List created")) return redirect("list_summary", list_id=mailing_list.list_id) # TODO catch correct Error class: except HTTPError as e: return render(request, 'postorius/errors/generic.html', {'error': e}) else: messages.error(request, _('Please check the errors below')) else: form = ListNew(choosable_domains, initial={ 'list_owner': request.user.email, 'advertised': True, }) return render(request, template, {'form': form})
def list_new(request, template='postorius/lists/new.html'): """ Add a new mailing list. If the request to the function is a GET request an empty form for creating a new list will be displayed. If the request method is POST the form will be evaluated. If the form is considered correct the list gets created and otherwise the form with the data filled in before the last POST request is returned. The user must be logged in to create a new list. """ mailing_list = None choosable_domains = [('', _('Choose a Domain'))] choosable_domains += _get_choosable_domains(request) if request.method == 'POST': form = ListNew(choosable_domains, request.POST) if form.is_valid(): # grab domain domain = Domain.objects.get_or_404( mail_host=form.cleaned_data['mail_host']) # creating the list try: mailing_list = domain.create_list( form.cleaned_data['listname']) mailing_list.add_owner(form.cleaned_data['list_owner']) list_settings = mailing_list.settings list_settings["description"] = form.cleaned_data['description'] list_settings["advertised"] = form.cleaned_data['advertised'] list_settings.save() messages.success(request, _("List created")) return redirect("list_summary", list_id=mailing_list.list_id) # TODO catch correct Error class: except HTTPError as e: return render(request, 'postorius/errors/generic.html', {'error': e}) else: messages.error(request, _('Please check the errors below')) else: form = ListNew(choosable_domains, initial={'list_owner': request.user.email}) return render(request, template, {'form': form})