Add optins to members registration form

parent 379ae9a1
This diff was suppressed by a .gitattributes entry.
# Generated by Django 2.0.2 on 2018-07-04 21:38
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('registrations', '0008_auto_20180704_2309'),
]
operations = [
migrations.AddField(
model_name='registration',
name='optin_birthday',
field=models.BooleanField(default=False, verbose_name='birthday calendar opt-in'),
),
migrations.AddField(
model_name='registration',
name='optin_mailinglist',
field=models.BooleanField(default=False, verbose_name='mailinglist opt-in'),
),
]
......@@ -225,6 +225,18 @@ class Registration(Entry):
blank=False,
)
# ---- Opt-ins -----
optin_mailinglist = models.BooleanField(
verbose_name=_('mailinglist opt-in'),
default=False
)
optin_birthday = models.BooleanField(
verbose_name=_('birthday calendar opt-in'),
default=False
)
def get_full_name(self):
full_name = '{} {}'.format(self.first_name, self.last_name)
return full_name.strip()
......
......@@ -223,7 +223,9 @@ def _create_member_from_registration(registration):
address_city=registration.address_city,
phone_number=registration.phone_number,
birthday=registration.birthday,
language=registration.language
language=registration.language,
show_birthday=registration.optin_birthday,
receive_optin=registration.optin_mailinglist
)
# Send welcome message to new member
......
<div class="control-group row {% if field.errors %}error{% endif %}">
<label class="control-label" for="id_{{ field.name }}">{{ field.label }}:</label>
<label class="control-label" for="id_{{ field.name }}">{{ field.label|capfirst }}:</label>
<div class="controls">
{{ field }}
......
......@@ -34,13 +34,33 @@
<form method="post" enctype="multipart/form-data" class="form-horizontal span8 offset2">
{% csrf_token %}
<fieldset>
{% form_field form 'length' %}
</fieldset>
<fieldset>
{% form_field form 'first_name' %}
{% form_field form 'last_name' %}
<span class="birthday-field">
{% form_field form 'birthday' %}
</span>
<div class="control-group row">
<div class="controls">
<label class="checkbox">
<input type="checkbox" name="optin_birthday" required id="id_optin_birthday">
{% trans "Display birthday in calendar" %}.
</label>
</div>
</div>
{% form_field form 'email' %}
<div class="control-group row">
<div class="controls">
<label class="checkbox">
<input type="checkbox" name="optin_mailinglist" required id="id_optin_mailinglist">
{% trans "Receive emails about (amongst others) job opportunities and in-house days from sponsors of Thalia." %}.
</label>
</div>
</div>
{% form_field form 'phone_number' %}
</fieldset>
......@@ -58,8 +78,6 @@
</fieldset>
<fieldset>
{% form_field form 'length' %}
<div class="control-group row">
<div class="controls">
<label class="checkbox">
......
......@@ -164,7 +164,8 @@ class RegistrationAdminTest(TestCase):
'programme', 'starting_year',
'address_street', 'address_street2',
'address_postal_code', 'address_city',
'payment', 'membership'])
'payment', 'membership',
'optin_mailinglist', 'optin_birthday'])
fields = self.admin.get_readonly_fields(request, Registration(
status=Entry.STATUS_ACCEPTED
......@@ -178,7 +179,8 @@ class RegistrationAdminTest(TestCase):
'programme', 'starting_year',
'address_street', 'address_street2',
'address_postal_code', 'address_city',
'payment', 'membership'])
'payment', 'membership',
'optin_mailinglist', 'optin_birthday'])
def test_get_actions(self):
actions = self.admin.get_actions(_get_mock_request([]))
......
......@@ -397,7 +397,6 @@ class RenewalFormViewTest(TestCase):
type=Membership.MEMBER
)
self.view.request = MagicMock()
self.view.request.member.latest_membership = membership
context = self.view.get_context_data(form=MagicMock())
self.assertEqual(len(context), 7)
......@@ -405,14 +404,22 @@ class RenewalFormViewTest(TestCase):
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)
with self.subTest("With latest membership"):
self.view.request.member.latest_membership = membership
context = self.view.get_context_data(form=MagicMock())
self.assertEqual(context['membership'], membership)
self.assertEqual(context['membership_type'], _('Member'))
self.assertEqual(context['privacy_policy_url'],
reverse('privacy-policy'))
with self.subTest('Without latest membership'):
self.view.request.member.latest_membership = None
context = self.view.get_context_data(form=MagicMock())
self.assertEqual(context['membership'], None)
self.assertFalse('membership_type' in context)
def test_get_form(self):
self.view.request = _get_mock_request()
......
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