Fix subscription form

This commit is contained in:
Skia
2016-09-02 12:29:50 +02:00
parent bae34c4b1c
commit a0b1fa32e7
5 changed files with 95 additions and 87 deletions

View File

@ -69,7 +69,7 @@ class Subscription(models.Model):
except: # This should not happen, because the form should have handled the data before, but sadly, it still
# calls the model validation :'(
# TODO see SubscriptionForm's clean method
raise ValidationError(_("You are trying to create a subscription without member"))
raise ValidationError(_("Subscription error"))
def save(self):
super(Subscription, self).save()

View File

@ -9,6 +9,7 @@
<div id="user_info"></div>
<form action="" method="post" id="subscription_form">
{% csrf_token %}
{{ form.non_field_errors() }}
<p>{{ form.member.errors }}<label for="{{ form.member.name }}">{{ form.member.label }}</label> {{ form.member }}</p>
<div id="new_member">
<p>{{ form.first_name.errors }}<label for="{{ form.first_name.name }}">{{ form.first_name.label }}</label> {{ form.first_name }}</p>

View File

@ -48,6 +48,8 @@ class SubscriptionForm(forms.ModelForm):
and "first_name" not in self.errors.as_data()
and "email" not in self.errors.as_data()):
self.errors.pop("member", None)
if self.errors:
return cleaned_data
if Subscriber.objects.filter(email=cleaned_data.get("email")).first() is not None:
self.add_error("email", ValidationError(_("A user with that email address already exists")))
else: