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

Proposed by Michael Hall
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 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.
Revision history for this message
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

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

Revision history for this message
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

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

568. By Michael Hall

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
=== modified file 'requirements.txt'
--- requirements.txt 2014-04-15 01:02:18 +0000
+++ requirements.txt 2014-04-23 01:37:56 +0000
@@ -19,6 +19,7 @@
19simplejson==2.0.919simplejson==2.0.9
20wsgiref==0.1.220wsgiref==0.1.2
21model-mommy==0.8.121model-mommy==0.8.1
22mock>=1.0
22Markdown==2.1.123Markdown==2.1.1
23pylint24pylint
2425
2526
=== modified file 'summit/schedule/tests/registration.py'
--- summit/schedule/tests/registration.py 2013-04-06 15:09:33 +0000
+++ summit/schedule/tests/registration.py 2014-04-23 01:37:56 +0000
@@ -29,6 +29,8 @@
29 Attendee,29 Attendee,
30)30)
3131
32from mock import MagicMock, patch
33from django.conf import settings
3234
33class RegistrationTestCase(djangotest.TestCase):35class RegistrationTestCase(djangotest.TestCase):
34 """36 """
@@ -62,6 +64,8 @@
62 )64 )
63 self.user1.set_password('password')65 self.user1.set_password('password')
64 self.user1.save()66 self.user1.save()
67
68 self.OLD_REGISTRATION_FORM_VIEW = getattr(settings, 'REGISTRATION_FORM_VIEW', None)
6569
66 def create_attendee(self):70 def create_attendee(self):
67 self.attendee1 = factory.make_one(71 self.attendee1 = factory.make_one(
@@ -74,6 +78,7 @@
7478
75 def tearDown(self):79 def tearDown(self):
76 self.client.logout()80 self.client.logout()
81 settings.REGISTRATION_FORM_VIEW = self.OLD_REGISTRATION_FORM_VIEW
7782
78 def login(self):83 def login(self):
79 logged_in = self.c.login(84 logged_in = self.c.login(
@@ -270,3 +275,24 @@
270 response.content275 response.content
271 )276 )
272 self.assertIn('Register in Summit', response.content)277 self.assertIn('Register in Summit', response.content)
278
279 def test_registration_view_override(self):
280 """
281 Test that registration form view overrides in settings are being
282 used
283 """
284 self.login()
285 rev_args = [self.summit.name, ]
286 with patch('summit.schedule.tests.registration.registration_form_test') as mock_form:
287 settings.REGISTRATION_FORM_VIEW = 'summit.schedule.tests.registration.registration_form_test'
288 mock_form.side_effect = registration_form_side_effect
289 self.assertFalse(mock_form.called)
290 response = self.c.get(reverse('registration', args=rev_args))
291 self.assertTrue(mock_form.called)
292
293def registration_form_side_effect(request, summit, attendee):
294 from summit.schedule.views import default_registration_form
295 return default_registration_form(request, summit, attendee)
296
297registration_form_test = None
298
273299
=== modified file 'summit/schedule/views.py'
--- summit/schedule/views.py 2013-11-05 20:56:44 +0000
+++ summit/schedule/views.py 2014-04-23 01:37:56 +0000
@@ -16,6 +16,9 @@
1616
17import datetime17import datetime
1818
19from importlib import import_module
20from django.conf import settings
21
19from django.db.models import Q22from django.db.models import Q
20from django.contrib.auth import logout23from django.contrib.auth import logout
21from django.http import Http404, HttpResponse, HttpResponseRedirect24from django.http import Http404, HttpResponse, HttpResponseRedirect
@@ -1207,6 +1210,18 @@
1207@login_required1210@login_required
1208@summit_required1211@summit_required
1209def registration_form(request, summit, attendee):1212def registration_form(request, summit, attendee):
1213 if (hasattr(settings, 'REGISTRATION_FORM_VIEW')
1214 and settings.REGISTRATION_FORM_VIEW is not None
1215 and settings.REGISTRATION_FORM_VIEW != 'summit.schedule.views.default_registration_form'):
1216 p, m = settings.REGISTRATION_FORM_VIEW.rsplit('.', 1)
1217
1218 mod = import_module(p)
1219 form_method = getattr(mod, m)
1220 return form_method(request, summit, attendee)
1221 else:
1222 return default_registration_form(request, summit, attendee)
1223
1224def default_registration_form(request, summit, attendee):
1210 registration_args = dict()1225 registration_args = dict()
12111226
1212 if attendee is None:1227 if attendee is None:

Subscribers

People subscribed via source and target branches