Commits

Anonymous committed a55227d

Change Paginate to PageBar, and don't pass querydict copy
Copy querydict in querystring filter

Comments (0)

Files changed (1)

gnocchi/tools/templatetags/paginate.py

 @register.filter
 def querystring(qdict, pagenum):
     '''Set the page number to that passed, and return the querystring'''
+    qdict = qdict.copy()
     qdict['page'] = pagenum
     return qdict.urlencode()
 
         return val.resolve(context)
     return val
 
-class PaginateNode(template.Node):
-    def __init__(self, nodelist, querydict=None, span=5, leadin=3, leadout=3):
-        self.nodelist = nodelist
-        self.querydict = querydict
+class PageBarNode(template.Node):
+    def __init__(self, page=None, paginator=None, span=5, leadin=3, leadout=3):
+        self.page = page
+        self.paginator = paginator
         self.span = span
         self.leadin = leadin
         self.leadout = leadout
 
     def render(self, context):
-        querydict = self.querydict
-        if not querydict:
-            querydict = context['request'].GET
 
-        page = context['page_obj']
-        paginator = context['paginator']
+        page = resolve(self.page, context)
+        if page is None:
+            page = context['page_obj']
+
+        paginator = resolve(self.paginator, context)
+        if paginator is None:
+            paginator = context['paginator']
 
         span = int(resolve(self.span, context))
         leadin = int(resolve(self.span, context))
         else:
             leadout = range(leadout, paginator.num_pages)
 
-        context.update({
-            'querydict': querydict.copy(),
-            'page_range': range(start, stop+1),
-            'page': page,
+        context['paging_bar'] = {
             'leadin': leadin,
             'leadout': leadout,
-        })
-        output = self.nodelist.render(context)
-        context.pop()
-        return output
+            'range': range(start, stop+1),
+        }
+        return ''
 
 @register.tag
-def paginate(parser, token):
+def page_bar(parser, token):
     bits = token.contents.split()
     bits.pop(0)	# discard name
     kwargs = {}
     if bits:
-        if not '=' in bits[0]:
-            kwargs['querydict'] = bits.pop(0)
         for bit in bits:
             key, val = bit.split('=')
             kwargs[key] = parser.compile_filter(val)
-    nodelist = parser.parse(('endpaginate',))
-    parser.delete_first_token()
-    return PaginateNode(nodelist, **kwargs)
+    return PageBarNode(**kwargs)