From 025e844c2f6955ba018f97d0079fea484867cbf2 Mon Sep 17 00:00:00 2001 From: Ant Zucaro Date: Thu, 22 Dec 2011 17:00:34 -0500 Subject: [PATCH] Add basic search to the index pages. --- xonstat/templates/map_index.mako | 5 +++ xonstat/templates/navlinks.mako | 60 ++++++++++++++--------------- xonstat/templates/player_index.mako | 5 +++ xonstat/templates/search.mako | 12 +++++- xonstat/templates/server_index.mako | 5 +++ xonstat/views/search.py | 18 ++++++--- 6 files changed, 67 insertions(+), 38 deletions(-) mode change 100644 => 100755 xonstat/templates/search.mako mode change 100644 => 100755 xonstat/views/search.py diff --git a/xonstat/templates/map_index.mako b/xonstat/templates/map_index.mako index 13eaf4c..f98e3d4 100755 --- a/xonstat/templates/map_index.mako +++ b/xonstat/templates/map_index.mako @@ -10,6 +10,11 @@ Map Index - ${parent.title()} % else:

Map Index

+
+ + + +
diff --git a/xonstat/templates/navlinks.mako b/xonstat/templates/navlinks.mako index a907e71..a529eb4 100755 --- a/xonstat/templates/navlinks.mako +++ b/xonstat/templates/navlinks.mako @@ -1,41 +1,41 @@ <%def name="navlinks(view, curr, last)"> +% if curr != last: + % if curr != 1: + + % endif -% if curr != 1: - -% endif - -% if last < 8: - % for i in range(1, last+1): - ${link_page(view, i, curr)} - % endfor -% else: - % if curr < 5: - % for i in range(1,7): - ${link_page(view, i, curr)} - % endfor - ... - - % elif last-curr < 6: - - ... - % for i in range(last-5, last+1): + % if last < 8: + % for i in range(1, last+1): ${link_page(view, i, curr)} % endfor % else: - - ... - % for i in range(curr-2, curr+3): - ${link_page(view, i, curr)} - % endfor - ... - + % if curr < 5: + % for i in range(1,7): + ${link_page(view, i, curr)} + % endfor + ... + + % elif last-curr < 6: + + ... + % for i in range(last-5, last+1): + ${link_page(view, i, curr)} + % endfor + % else: + + ... + % for i in range(curr-2, curr+3): + ${link_page(view, i, curr)} + % endfor + ... + + % endif % endif -% endif -% if curr != last: - + % if curr != last: + + % endif % endif - <%def name="link_page(view, page_num, curr_page)"> diff --git a/xonstat/templates/player_index.mako b/xonstat/templates/player_index.mako index 9784a6c..1aa38b5 100755 --- a/xonstat/templates/player_index.mako +++ b/xonstat/templates/player_index.mako @@ -10,6 +10,11 @@ Player Index - ${parent.title()} % else:

Player Index

+ + + + +
Name
diff --git a/xonstat/templates/search.mako b/xonstat/templates/search.mako old mode 100644 new mode 100755 index 64e5ced..cceeacb --- a/xonstat/templates/search.mako +++ b/xonstat/templates/search.mako @@ -1,8 +1,9 @@ <%inherit file="base.mako"/> +<%namespace file="navlinks.mako" import="navlinks" /> % if results == None: - +
Nick
@@ -22,7 +23,9 @@
Nick:
-% endif +% elif len(results) == 0: +

Sorry, nothing found!

+% else: ##### player-only results ##### % if result_type == "player": @@ -91,3 +94,8 @@ % endfor % endif + + +

Work in progress (these won't work :P):

+${navlinks("search", results.page, results.last_page)} +% endif diff --git a/xonstat/templates/server_index.mako b/xonstat/templates/server_index.mako index a859023..c992962 100755 --- a/xonstat/templates/server_index.mako +++ b/xonstat/templates/server_index.mako @@ -10,6 +10,11 @@ Map Index - ${parent.title()} % else:

Server Index

+
+ + + +
diff --git a/xonstat/views/search.py b/xonstat/views/search.py old mode 100644 new mode 100755 index 11c22eb..85dae39 --- a/xonstat/views/search.py +++ b/xonstat/views/search.py @@ -64,24 +64,30 @@ def search_q(nick=None, server_name=None, map_name=None, create_dt=None): return (result_type, q) def search(request): - form_submitted = None + fs = None nick = None server_name = None map_name = None result_type = None results = None - if request.params.has_key('form_submitted'): - nick = request.params['nick'] - server_name = request.params['server_name'] - map_name = request.params['map_name'] + current_page = 1 + + if request.params.has_key('fs'): + if request.params.has_key('nick'): + nick = request.params['nick'] + if request.params.has_key('server_name'): + server_name = request.params['server_name'] + if request.params.has_key('map_name'): + map_name = request.params['map_name'] (result_type, q) = search_q(nick=nick, server_name=server_name, map_name=map_name) log.debug(q) try: if q != None: - results = q.all() + results = Page(q, current_page, url=page_url) + log.debug(len(results)) except Exception as e: raise e result_type = None -- 2.39.2
Name