implemented multi-page display of frontpage polls
This commit is contained in:
parent
b9411b3855
commit
ff177974be
1 changed files with 23 additions and 2 deletions
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue