diff --git a/wortschlucker/src/wortschlucker.py b/wortschlucker/src/wortschlucker.py index 69a95d6..ed7182a 100755 --- a/wortschlucker/src/wortschlucker.py +++ b/wortschlucker/src/wortschlucker.py @@ -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):