Merge lp:~james-w/python-timeline-django/timeline-factory into lp:python-timeline-django

Proposed by James Westby
Status: Approved
Approved by: Michael Nelson
Approved revision: 28
Proposed branch: lp:~james-w/python-timeline-django/timeline-factory
Merge into: lp:python-timeline-django
Diff against target: 84 lines (+32/-7)
3 files modified
timeline_django/setup.py (+1/-7)
timeline_django/tests/test_wsgi.py (+19/-0)
timeline_django/wsgi.py (+12/-0)
To merge this branch: bzr merge lp:~james-w/python-timeline-django/timeline-factory
Reviewer Review Type Date Requested Status
Michael Nelson (community) Approve
Review via email: mp+239254@code.launchpad.net

Commit message

Add a timeline_factory function.

To post a comment you must log in.
28. By James Westby

Fix typo, thanks Michael.

Revision history for this message
Michael Nelson (michael.nelson) :
review: Approve

Unmerged revisions

28. By James Westby

Fix typo, thanks Michael.

27. By James Westby

Add a timeline_factory function.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'timeline_django/setup.py'
--- timeline_django/setup.py 2012-09-22 09:00:56 +0000
+++ timeline_django/setup.py 2014-10-23 13:49:02 +0000
@@ -13,8 +13,6 @@
13# along with this program. If not, see <http://www.gnu.org/licenses/>.13# along with this program. If not, see <http://www.gnu.org/licenses/>.
14# GNU Lesser General Public License version 3 (see the file LICENSE).14# GNU Lesser General Public License version 3 (see the file LICENSE).
1515
16from functools import partial
17
18from . import hooks, timeline_cursor, wsgi16from . import hooks, timeline_cursor, wsgi
1917
2018
@@ -37,11 +35,7 @@
37 factory.35 factory.
38 """36 """
39 if timeline_factory is None:37 if timeline_factory is None:
40 def timeline_factory():38 timeline_factory = wsgi.timeline_factory
41 environ = wsgi.get_environ()
42 if not environ:
43 return None
44 return environ.get('timeline.timeline')
45 timeline_cursor.setup_timeline_cursor_hooks(timeline_factory, prefix=prefix)39 timeline_cursor.setup_timeline_cursor_hooks(timeline_factory, prefix=prefix)
46 receiver = hooks.TimelineReceiver(timeline_factory)40 receiver = hooks.TimelineReceiver(timeline_factory)
47 receiver.connect_to_signals()41 receiver.connect_to_signals()
4842
=== modified file 'timeline_django/tests/test_wsgi.py'
--- timeline_django/tests/test_wsgi.py 2014-08-29 14:45:51 +0000
+++ timeline_django/tests/test_wsgi.py 2014-10-23 13:49:02 +0000
@@ -35,6 +35,9 @@
35 def test_get_environ_is_None_first_call(self):35 def test_get_environ_is_None_first_call(self):
36 self.assertEqual(None, wsgi.get_environ())36 self.assertEqual(None, wsgi.get_environ())
3737
38 def test_timeline_factory_is_None_first_call(self):
39 self.assertEqual(None, wsgi.timeline_factory())
40
38 def test_wsgi_sets_timeline(self):41 def test_wsgi_sets_timeline(self):
39 environ = {}42 environ = {}
40 start_response = lambda status, headers: None43 start_response = lambda status, headers: None
@@ -45,6 +48,22 @@
45 out = app(environ, start_response)48 out = app(environ, start_response)
46 self.assertEqual(["foo"], list(out))49 self.assertEqual(["foo"], list(out))
4750
51 def test_timeline_factory_with_no_timeline(self):
52 environ = {}
53 start_response = lambda status, headers: None
54 def do_check(environ, start_response):
55 self.assertEqual(None, wsgi.timeline_factory())
56 app = wsgi.make_app(do_check)
57 out = app(environ, start_response)
58
59 def test_timeline_factory_with_timeline(self):
60 environ = {'timeline.timeline': 'a'}
61 start_response = lambda status, headers: None
62 def do_check(environ, start_response):
63 self.assertEqual('a', wsgi.timeline_factory())
64 app = wsgi.make_app(do_check)
65 out = app(environ, start_response)
66
48 def test_wsgi_unsets_timeline(self):67 def test_wsgi_unsets_timeline(self):
49 environ = {}68 environ = {}
50 start_response = lambda status, headers: None69 start_response = lambda status, headers: None
5170
=== modified file 'timeline_django/wsgi.py'
--- timeline_django/wsgi.py 2014-08-29 13:02:39 +0000
+++ timeline_django/wsgi.py 2014-10-23 13:49:02 +0000
@@ -33,6 +33,18 @@
33 return getattr(_thread_local, 'environ', None)33 return getattr(_thread_local, 'environ', None)
3434
3535
36def timeline_factory():
37 """Get a timeline for the currently active request.
38
39 Calling this factory will get you a timeline for the currently
40 active request, if there is one. If there is no active request,
41 or if the request environ has no timeline then it returns None.
42 """
43 environ = get_environ()
44 if environ:
45 return environ.get('timeline.timeline')
46
47
36def make_app(application):48def make_app(application):
37 """Create a WSGI application that stores the environ in a thread-local.49 """Create a WSGI application that stores the environ in a thread-local.
3850

Subscribers

People subscribed via source and target branches