Commits

Branko Vukelic committed 9fe270a

Facepalm: We actually need a context processor!

Yeah, I admit to major stupidity. I implemented a middleware class instead of a
context processor. The make the facepalm harder, the module _is_ called
context_processors.

Comments (0)

Files changed (2)

tests/test_context_processors.py

 
 from mock import Mock
 
-from url_tools.context_processors import CurrentUrlProcessor
+from url_tools.context_processors import current_url
 
 
 class CurrentUrlProcessorTestCase(TestCase):
     def setUp(self):
         self.request = Mock()
         self.request.get_full_path.return_value = '/foo?foo=1'
-        self.response = Mock()
-        self.response.context_data = {}
 
     def test_can_get_url_from_request(self):
-        c = CurrentUrlProcessor()
-        c.process_template_response(self.request, self.response)
+        current_url(self.request)
         self.assertTrue(self.request.get_full_path.called)
 
     def test_can_insert_url_helper_into_context(self):
-        c = CurrentUrlProcessor()
-        c.process_template_response(self.request, self.response)
-
-        self.assertTrue('current_url' in self.response.context_data)
+        d = current_url(self.request)
+        self.assertTrue('current_url' in d)
         self.assertEqual(
-            self.response.context_data['current_url'].get_full_path(),
+            d['current_url'].get_full_path(),
             self.request.get_full_path.return_value
         )

url_tools/context_processors.py

 from .helper import UrlHelper
 
 
-class CurrentUrlProcessor(object):
-    def process_template_response(self, request, response):
-        full_path = request.get_full_path()
-        response.context_data['current_url'] = UrlHelper(full_path)
-        return response
+def current_url(request):
+    full_path = request.get_full_path()
+    return dict(current_url=UrlHelper(full_path))