Verified Commit eb5da32c authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg
Browse files

Add privacy policy checkbox to renewal form

parent bb672be5
......@@ -28,6 +28,12 @@ class MemberRegistrationForm(forms.ModelForm):
class MemberRenewalForm(forms.ModelForm):
"""Form for membership renewals"""
privacy_policy = forms.BooleanField(
required=True,
label=_('I accept the privacy policy')
)
class Meta:
model = Renewal
fields = '__all__'
......
......@@ -75,6 +75,15 @@
{% form_field form 'length' %}
<div class="control-group row">
<div class="controls">
<label class="checkbox">
<input type="checkbox" name="privacy_policy" required="" id="id_privacy_policy">
{% blocktrans trimmed %}I accept the <a target="_blank" href="{{ privacy_policy_url }}">privacy policy</a>{% endblocktrans %}.
</label>
</div>
</div>
<input type="submit" value="{% trans 'send'|capfirst %}" class="btn btn-style1 pull-right login" />
</form>
{% endif %}
......
......@@ -29,8 +29,13 @@ class MemberRegistrationFormTest(TestCase):
}
def test_is_valid(self):
form = forms.MemberRegistrationForm(self.data)
self.assertTrue(form.is_valid(), msg=dict(form.errors))
with self.subTest("Form is valid"):
form = forms.MemberRegistrationForm(self.data)
self.assertTrue(form.is_valid(), msg=dict(form.errors))
with self.subTest("Form is not valid"):
self.data['privacy_policy'] = 0
form = forms.MemberRegistrationForm(self.data)
self.assertFalse(form.is_valid(), msg=dict(form.errors))
def test_has_privacy_policy_field(self):
form = forms.MemberRegistrationForm(self.data)
......@@ -46,9 +51,19 @@ class MemberRenewalFormTest(TestCase):
'member': self.member.pk,
'length': Entry.MEMBERSHIP_STUDY,
'membership_type': Membership.MEMBER,
'privacy_policy': 1,
}
def test_is_valid(self):
self.member.membership_set.all().delete()
with self.subTest("Form is valid"):
form = forms.MemberRenewalForm(self.data)
self.assertTrue(form.is_valid(), msg=dict(form.errors))
with self.subTest("Form is not valid"):
self.data['privacy_policy'] = 0
form = forms.MemberRenewalForm(self.data)
self.assertFalse(form.is_valid(), msg=dict(form.errors))
def test_has_privacy_policy_field(self):
form = forms.MemberRenewalForm(self.data)
self.assertTrue(form.is_valid(), msg=dict(form.errors))
self.assertTrue(form.fields['privacy_policy'] is not None)
......@@ -400,13 +400,19 @@ class RenewalFormViewTest(TestCase):
self.view.request.member.latest_membership = membership
context = self.view.get_context_data(form=MagicMock())
self.assertEqual(len(context), 6)
self.assertEqual(len(context), 7)
self.assertEqual(context['year_fees'], floatformat(
settings.MEMBERSHIP_PRICES[Entry.MEMBERSHIP_YEAR], 2))
self.assertEqual(context['study_fees'], floatformat(
settings.MEMBERSHIP_PRICES[Entry.MEMBERSHIP_STUDY], 2))
self.assertEqual(context['membership'], membership)
self.assertEqual(context['membership_type'], _('Member'))
self.assertEqual(context['privacy_policy_url'],
reverse('privacy-policy'))
self.view.request.member.latest_membership = None
context = self.view.get_context_data(form=MagicMock())
self.assertFalse('membership_type' in context)
def test_get_form(self):
self.view.request = _get_mock_request()
......
......@@ -157,6 +157,7 @@ class RenewalFormView(FormView):
if context['membership'] is not None:
context['membership_type'] = (context['membership']
.get_type_display())
context['privacy_policy_url'] = reverse('privacy-policy')
return context
def get_form(self, form_class=None):
......
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