Merge lp:~mhall119/summit/custom-registration-form into lp:summit

Proposed by Michael Hall on 2014-04-15
Status: Needs review
Proposed branch: lp:~mhall119/summit/custom-registration-form
Merge into: lp:summit
Diff against target: 99 lines (+42/-0)
3 files modified
requirements.txt (+1/-0)
summit/schedule/tests/registration.py (+26/-0)
summit/schedule/views.py (+15/-0)
To merge this branch: bzr merge lp:~mhall119/summit/custom-registration-form
Reviewer Review Type Date Requested Status
Summit Hackers 2014-04-15 Pending
Review via email: mp+215795@code.launchpad.net

Commit message

Add settings.REGISTRATION_FORM_VIEW for registration override

Allows different deployments to provide their own user registration form
views by adding a setting value to their local settings. If no setting is
given, it will default back to the Attendee form previously used

Description of the change

Add settings.REGISTRATION_FORM_VIEW for registration override

Allows different deployments to provide their own user registration form
views by adding a setting value to their local settings. If no setting is
given, it will default back to the Attendee form previously used

To post a comment you must log in.
Chris Johnston (cjohnston) wrote :

I would really prefer that we don't use '\' to extend a line.. could you do:

if (one and two and
       three and four):

569. By Michael Hall on 2014-04-23

Don't use escaped newlines for multi-line if condition

Chris Johnston (cjohnston) wrote :

summit/schedule/views.py:1213:52: W291 trailing whitespace
summit/schedule/views.py:1214:5: E128 continuation line under-indented for visual indent
summit/schedule/views.py:1214:52: W291 trailing whitespace
summit/schedule/views.py:1215:5: E128 continuation line under-indented for visual indent
summit/schedule/views.py:1215:80: E501 line too long (94 > 79 characters)
summit/schedule/views.py:1224:1: E302 expected 2 blank lines, found 1

Unmerged revisions

569. By Michael Hall on 2014-04-23

Don't use escaped newlines for multi-line if condition

568. By Michael Hall on 2014-04-15

Add settings.REGISTRATION_FORM_VIEW for registration override

Allows different deployments to provide their own user registration form
views by adding a setting value to their local settings. If no setting is
given, it will default back to the Attendee form previously used

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'requirements.txt'
2--- requirements.txt 2014-04-15 01:02:18 +0000
3+++ requirements.txt 2014-04-23 01:37:56 +0000
4@@ -19,6 +19,7 @@
5 simplejson==2.0.9
6 wsgiref==0.1.2
7 model-mommy==0.8.1
8+mock>=1.0
9 Markdown==2.1.1
10 pylint
11
12
13=== modified file 'summit/schedule/tests/registration.py'
14--- summit/schedule/tests/registration.py 2013-04-06 15:09:33 +0000
15+++ summit/schedule/tests/registration.py 2014-04-23 01:37:56 +0000
16@@ -29,6 +29,8 @@
17 Attendee,
18 )
19
20+from mock import MagicMock, patch
21+from django.conf import settings
22
23 class RegistrationTestCase(djangotest.TestCase):
24 """
25@@ -62,6 +64,8 @@
26 )
27 self.user1.set_password('password')
28 self.user1.save()
29+
30+ self.OLD_REGISTRATION_FORM_VIEW = getattr(settings, 'REGISTRATION_FORM_VIEW', None)
31
32 def create_attendee(self):
33 self.attendee1 = factory.make_one(
34@@ -74,6 +78,7 @@
35
36 def tearDown(self):
37 self.client.logout()
38+ settings.REGISTRATION_FORM_VIEW = self.OLD_REGISTRATION_FORM_VIEW
39
40 def login(self):
41 logged_in = self.c.login(
42@@ -270,3 +275,24 @@
43 response.content
44 )
45 self.assertIn('Register in Summit', response.content)
46+
47+ def test_registration_view_override(self):
48+ """
49+ Test that registration form view overrides in settings are being
50+ used
51+ """
52+ self.login()
53+ rev_args = [self.summit.name, ]
54+ with patch('summit.schedule.tests.registration.registration_form_test') as mock_form:
55+ settings.REGISTRATION_FORM_VIEW = 'summit.schedule.tests.registration.registration_form_test'
56+ mock_form.side_effect = registration_form_side_effect
57+ self.assertFalse(mock_form.called)
58+ response = self.c.get(reverse('registration', args=rev_args))
59+ self.assertTrue(mock_form.called)
60+
61+def registration_form_side_effect(request, summit, attendee):
62+ from summit.schedule.views import default_registration_form
63+ return default_registration_form(request, summit, attendee)
64+
65+registration_form_test = None
66+
67
68=== modified file 'summit/schedule/views.py'
69--- summit/schedule/views.py 2013-11-05 20:56:44 +0000
70+++ summit/schedule/views.py 2014-04-23 01:37:56 +0000
71@@ -16,6 +16,9 @@
72
73 import datetime
74
75+from importlib import import_module
76+from django.conf import settings
77+
78 from django.db.models import Q
79 from django.contrib.auth import logout
80 from django.http import Http404, HttpResponse, HttpResponseRedirect
81@@ -1207,6 +1210,18 @@
82 @login_required
83 @summit_required
84 def registration_form(request, summit, attendee):
85+ if (hasattr(settings, 'REGISTRATION_FORM_VIEW')
86+ and settings.REGISTRATION_FORM_VIEW is not None
87+ and settings.REGISTRATION_FORM_VIEW != 'summit.schedule.views.default_registration_form'):
88+ p, m = settings.REGISTRATION_FORM_VIEW.rsplit('.', 1)
89+
90+ mod = import_module(p)
91+ form_method = getattr(mod, m)
92+ return form_method(request, summit, attendee)
93+ else:
94+ return default_registration_form(request, summit, attendee)
95+
96+def default_registration_form(request, summit, attendee):
97 registration_args = dict()
98
99 if attendee is None:

Subscribers

People subscribed via source and target branches