Commits

Rostyslav Bryzgunov  committed e43c297

Updated logic: now we don't use state object as first param - request.GET used instead

  • Participants
  • Parent commits 3afe3ab

Comments (0)

Files changed (2)

File urlquerify/__init__.py

-VERSION = (0, 1, 1)
+VERSION = (0, 1, 2)
 __version__ = '.'.join(map(str, VERSION))
-__author__ = 'webriders.com.ua'
+__author__ = 'WebRiders'
 __homepage__ = 'https://bitbucket.org/webriders/django-urlquerify'
 __contact__ = 'contact@webriders.com.ua'
 __doc__ = 'Helps to manage query parameters in django templates'

File urlquerify/templatetags/urlquerify.py

 from copy import deepcopy
 from django import template
 from django.template.base import token_kwargs, resolve_variable
+from ..models import QueryState
+
+
 register = template.Library()
 
 
 class UrlquerifyNode(template.Node):
-    def __init__(self, state_var_name, update_items=None, remove_items=None, only_items=None):
-        self.state_var_name = state_var_name
+    """
+    Simple filter that takes request.GET and updates/deletes/adds params into it
+    Requirements: django.core.context_processors.request should be switched on!
+    """
+    def __init__(self, update_items=None, remove_items=None, only_items=None):
         self.update_items = update_items or {}
         self.remove_items = remove_items or []
         self.only_items = only_items or []
         return '<UrlquerifyNode>'
 
     def render(self, context):
-        state = deepcopy(resolve_variable(self.state_var_name, context))
+        state = QueryState(resolve_variable('request', context))
 
         update_items = deepcopy(self.update_items)
         for key, val in update_items.items():
 @register.tag
 def urlquerify(parser, token):
     bits = token.split_contents()
-    state_var_name = bits[1]
-    remaining_bits = bits[2:]
+    remaining_bits = bits[1:]
 
     update_items = token_kwargs(remaining_bits, parser, support_legacy=True)
 
     remove_items = named_args.get('remove', '').split(',')
     only_items = named_args.get('only', '').split(',')
 
-    return UrlquerifyNode(state_var_name, update_items, remove_items, only_items)
+    return UrlquerifyNode(update_items, remove_items, only_items)