File: views.py

package info (click to toggle)
python-werkzeug 3.1.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,912 kB
  • sloc: python: 21,938; javascript: 292; makefile: 39; sh: 17; xml: 16
file content (34 lines) | stat: -rw-r--r-- 1,000 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""Display the aggregated feeds."""
from datetime import date

from .database import Entry
from .utils import expose
from .utils import Pagination
from .utils import render_template


#: number of items per page
PER_PAGE = 30


@expose("/", defaults={"page": 1})
@expose("/page/<int:page>")
def index(request, page):
    """Show the index page or any an offset of it."""
    days = []
    days_found = set()
    query = Entry.query.order_by(Entry.pub_date.desc())
    pagination = Pagination(query, PER_PAGE, page, "index")
    for entry in pagination.entries:
        day = date(*entry.pub_date.timetuple()[:3])
        if day not in days_found:
            days_found.add(day)
            days.append({"date": day, "entries": []})
        days[-1]["entries"].append(entry)
    return render_template("index.html", days=days, pagination=pagination)


@expose("/about")
def about(request):
    """Show the about page, so that we have another view func ;-)"""
    return render_template("about.html")