Commit 937a5b1d authored by Luko van der Maas's avatar Luko van der Maas
Browse files

Merge branch 'tc/make-studentnumber-required-member-registration' into 'master'

Make studentnumber required for member registration

See merge request !949
parents 0dcbacf5 1ec044fd
......@@ -11,6 +11,7 @@ from .models import Registration, Renewal
class MemberRegistrationForm(forms.ModelForm):
"""Form for membership registrations"""
birthday = forms.DateField(
widget=forms.widgets.SelectDateWidget(years=[
year for year in range(timezone.now().year - 50,
......
......@@ -264,6 +264,10 @@ class Registration(Entry):
_('A user with that student number already exists. '
'Login using the existing account and renew the '
'membership by visiting the account settings.')})
elif (self.student_number is None and
self.membership_type != Membership.SUPPORTER):
errors.update({
'student_number': _('This field is required.')})
if self.username is not None and get_user_model().objects.filter(
username=self.username).exists():
......
......@@ -28,7 +28,7 @@ class MemberRegistrationFormTest(TestCase):
'privacy_policy': 1,
}
def test_is_valid(self):
def test_privacy_policy_checked(self):
with self.subTest("Form is valid"):
form = forms.MemberRegistrationForm(self.data)
self.assertTrue(form.is_valid(), msg=dict(form.errors))
......
......@@ -75,6 +75,7 @@ class RegistrationTest(TestCase):
address_postal_code='6525AJ',
address_city='Nijmegen',
phone_number='06123456789',
student_number='s1234567',
birthday=timezone.now().replace(year=1990),
language='en',
length=Entry.MEMBERSHIP_YEAR,
......@@ -143,6 +144,20 @@ class RegistrationTest(TestCase):
with self.assertRaises(ValidationError):
self.registration.clean()
def test_require_student_number_members(self):
with self.subTest('No student number entered'):
self.registration.student_number = None
with self.assertRaisesMessage(
ValidationError,
"{'student_number': ['This field is required.']}"
):
self.registration.clean()
with self.subTest('Type is benefactor'):
self.registration.student_number = None
self.registration.membership_type = Membership.SUPPORTER
self.registration.clean()
def test_unique_username_user(self):
self.registration.username = 'johndoe'
self.registration.clean()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment