Permalink
Browse files

Pagination fix.

  • Loading branch information...
1 parent f10abdc commit d311deb6185b6f1391ff6918a0feaa166faa3b1f @grigorescu committed Jul 30, 2012
View
@@ -7,7 +7,12 @@
@dajaxice_register
def getData(request, type, query, indices, sort, start=0):
data = {}
- sort = ast.literal_eval(sort)
+
+ try:
+ sort = ast.literal_eval(str(sort))
+ except ValueError:
+ raise ValueError(sort)
+
try:
result = utils.es.doQuery(utils.es.queryEscape(query), index=indices, type=type, start=start, sort=sort)
except requests.ConnectionError:
@@ -115,7 +115,7 @@
{% endfor %}
</tbody>
</table>
-{% paginate start total openTab query indices %}
+{% paginate start total openTab query indices sort.field sort.order %}
<script>
$('.popover_links').popover({placement:'bottom'});
Dajaxice.Brownian.view.updateIndices(jQuery.noop);
@@ -28,19 +28,29 @@ def genPagination(parser, token):
"""Generates pagination given the current location, and the total number of items."""
try:
- tag_name, start, total, openTab, query, indices = token.split_contents()
+ tokens = token.split_contents()
+ tag_name = tokens[0]
+ start = tokens[1]
+ total = tokens[2]
+ openTab = tokens[3]
+ query = tokens[4]
+ indices = tokens[5]
+ sortField = tokens[6]
+ sortOrder = tokens[7]
except ValueError:
- raise template.TemplateSyntaxError("%r tag requires arguments (location, total, openTab, query, indices)." % token.contents.split(0))
+ raise template.TemplateSyntaxError("%r tag requires arguments (location, total, openTab, query, indices, sortField, sortOrder)." % tag_name)
- return Paginate(start, total, openTab, query, indices)
+ return Paginate(start, total, openTab, query, indices, sortField, sortOrder)
class Paginate(template.Node):
- def __init__(self, start, total, openTab, query, indices):
+ def __init__(self, start, total, openTab, query, indices, sortField, sortOrder):
self.start = template.Variable(start)
self.total = template.Variable(total)
self.openTab = template.Variable(openTab)
self.query = template.Variable(query)
self.indices = template.Variable(indices)
+ self.sortField = template.Variable(sortField)
+ self.sortOrder = template.Variable(sortOrder)
def render(self, context):
result = '<div class="pagination pagination-centered">\
@@ -49,7 +59,7 @@ def render(self, context):
start = int(self.start.resolve(context))
total = int(self.total.resolve(context))
page = (start/settings.PAGE_SIZE) + 1
- onclick = """onclick="replaceContents('<img class=&quot;loader&quot; src=&quot;""" + settings.STATIC_URL + """img/ajax-loader.gif&quot;>');Dajaxice.Brownian.view.getData(replaceContents, {'type': '%s', 'query': '%s', 'indices': '%s', """ % (self.openTab.resolve(context), self.query.resolve(context), self.indices.resolve(context)) + """'start': '%s'});" """
+ onclick = """onclick="replaceContents('<img class=&quot;loader&quot; src=&quot;""" + settings.STATIC_URL + """img/ajax-loader.gif&quot;>');Dajaxice.Brownian.view.getData(replaceContents, {'type': '%s', 'query': '%s', 'indices': '%s', """ % (self.openTab.resolve(context), self.query.resolve(context), self.indices.resolve(context)) + """'sort': {&quot;%s&quot;: {&quot;order&quot;: &quot;%s&quot;}}, """ % (self.sortField.resolve(context), self.sortOrder.resolve(context)) + """'start': '%s'});" """
if page == 1 and total > settings.PAGE_SIZE:
result += '<li class="disabled"><a href="#">&laquo;</a></li>'
result += '<li class="disabled"><a href="#">&lsaquo;</a></li>'
View
@@ -1,5 +1,5 @@
{"index": {"_index": "@bro-meta", "_type": "index", "_id": "bro-06241900-0.0-10800.0"} }
-{"name": "bro-06241900", "start": }
+{"name": "bro-06241900", "start": 1340578800.0, "end": 1340589600.0}
{"index": {"_index": "bro-06241900", "_type": "communication"} }
{"peer": "worker-1", "src_name": "child", "message": "selects=3000000 canwrites=0 timeouts=2986503", "ts": 1340647604358, "level": "info"}
{"index": {"_index": "bro-06241900", "_type": "communication"} }

0 comments on commit d311deb

Please sign in to comment.