implemented multi-page display of frontpage polls

This commit is contained in:
lars 2010-05-07 15:49:12 +00:00
parent b9411b3855
commit ff177974be

View file

@ -417,9 +417,30 @@ def base():
return bobo.redirect(BASE_DICT["base_url"])
@bobo.query('/')
def show_frontpage():
def show_frontpage(page=None):
value_dict = get_default_values()
value_dict["polls"] = Poll.select()
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 page is None:
page = 1
else:
try:
page = int(page)
except ValueError:
page = 1
page_size = 10
start = (page - 1) * page_size
if start >= len(polls):
start = 0
page = 1
end = start + page_size - 1
value_dict["polls"] = polls[start : end + 1]
print value_dict["polls"]
# show a link for the next page, if more polls are available
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)
def render_poll_admin(poll, add_related, del_related):