From 03f68579bfb0d37158d8d0f8678129503097cc97 Mon Sep 17 00:00:00 2001 From: lars Date: Fri, 7 May 2010 16:28:50 +0000 Subject: [PATCH] added admin page with all (even non-public) polls and their admin links --- wortschlucker/src/wortschlucker.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/wortschlucker/src/wortschlucker.py b/wortschlucker/src/wortschlucker.py index ed7182a..42cd58f 100755 --- a/wortschlucker/src/wortschlucker.py +++ b/wortschlucker/src/wortschlucker.py @@ -418,10 +418,26 @@ def base(): @bobo.query('/') def show_frontpage(page=None): + return show_poll_list("frontpage.html", 10, page) + +@bobo.query('/admin') +@bobo.query('/admin/') +def show_admin_page(page=None, page_size=20): + try: + page_size = int(page_size) + except ValueError: + page_size = 20 + return show_poll_list("admin.html", page_size, page, filter_private=False) + +def show_poll_list(render_file, page_size, page=None, filter_private=True): value_dict = get_default_values() polls = Poll.select().orderBy("-timestamp_creation") # TODO: speed the filtering up by using SQL statements (see sqlobject "filter") - polls = [poll for poll in polls if poll.get_settings()["public"]] + if filter_private: + polls = [poll for poll in polls if poll.get_settings()["public"]] + else: + # convert the sql query into a list (probably an expensive operation) + polls = [poll for poll in polls] if page is None: page = 1 else: @@ -429,7 +445,6 @@ def show_frontpage(page=None): page = int(page) except ValueError: page = 1 - page_size = 10 start = (page - 1) * page_size if start >= len(polls): start = 0 @@ -441,7 +456,7 @@ def show_frontpage(page=None): value_dict["show_next_link"] = (end + 1 < len(polls)) value_dict["show_previous_link"] = (start > 0) value_dict["page"] = page - return render("frontpage.html", **value_dict) + return render(render_file, **value_dict) def render_poll_admin(poll, add_related, del_related): value_dict = get_default_values()