Commits

Branko Vukelic committed 0f97fa8

Added query property to access query dict

Comments (0)

Files changed (2)

tests/test_url_helper.py

         u.update_query_data(foo=1)
         self.assertEqual(u.get_full_path(), '/foo?foo=1#bar')
 
+    def test_query_property(self):
+        u = UrlHelper('/foo?foo=1')
+        self.assertEqual(u.query['foo'], '1')
+
+    def test_query_setter(self):
+        u = UrlHelper('/foo')
+        u.query = dict(foo=1)
+        self.assertEqual(u.query['foo'], '1')
+

url_tools/context_processors.py

             query_string,
             fragment
         )
+
+    @property
+    def query(self):
+        return self.get_query_data()
+
+    @query.setter
+    def query(self, value):
+        if not hasattr(value, '__getitem__'):
+            raise ValueError(
+                'Query can only be set to mapping type (like dict)'
+            )
+        self.query_dict = QueryDict('', mutable=True)
+        self.update_query_data(**value)
+