customize page limit
This commit is contained in:
parent
a5bda3e170
commit
472045cbfd
2 changed files with 22 additions and 3 deletions
16
app.py
16
app.py
|
|
@ -58,13 +58,18 @@ DEFAULT_CONF = {
|
||||||
_cfp = ConfigParser()
|
_cfp = ConfigParser()
|
||||||
if _cfp.read([APP_BASE_DIR + '/site.conf']):
|
if _cfp.read([APP_BASE_DIR + '/site.conf']):
|
||||||
@lru_cache(maxsize=50)
|
@lru_cache(maxsize=50)
|
||||||
def _getconf(k1, k2, fallback=None):
|
def _getconf(k1, k2, fallback=None, cast=None):
|
||||||
if fallback is None:
|
if fallback is None:
|
||||||
fallback = DEFAULT_CONF.get((k1, k2))
|
fallback = DEFAULT_CONF.get((k1, k2))
|
||||||
v = _cfp.get(k1, k2, fallback=fallback)
|
v = _cfp.get(k1, k2, fallback=fallback)
|
||||||
|
if cast in (int, float, str):
|
||||||
|
try:
|
||||||
|
v = cast(v)
|
||||||
|
except ValueError:
|
||||||
|
v = fallback
|
||||||
return v
|
return v
|
||||||
else:
|
else:
|
||||||
def _getconf(k1, k2, fallback=None):
|
def _getconf(k1, k2, fallback=None, cast=None):
|
||||||
if fallback is None:
|
if fallback is None:
|
||||||
fallback = DEFAULT_CONF.get((k1, k2))
|
fallback = DEFAULT_CONF.get((k1, k2))
|
||||||
return fallback
|
return fallback
|
||||||
|
|
@ -516,8 +521,9 @@ def _inject_variables():
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def homepage():
|
def homepage():
|
||||||
|
page_limit = _getconf("appearance","items_per_page",20,cast=int)
|
||||||
return render_template('home.html', new_notes=Page.select()
|
return render_template('home.html', new_notes=Page.select()
|
||||||
.order_by(Page.touched.desc()).limit(20),
|
.order_by(Page.touched.desc()).limit(page_limit),
|
||||||
gallery=make_gallery((x, '') for x in Upload.select().order_by(Upload.upload_date.desc()).limit(3)))
|
gallery=make_gallery((x, '') for x in Upload.select().order_by(Upload.upload_date.desc()).limit(3)))
|
||||||
|
|
||||||
@app.route('/robots.txt')
|
@app.route('/robots.txt')
|
||||||
|
|
@ -534,6 +540,10 @@ def favicon():
|
||||||
def error_404(body):
|
def error_404(body):
|
||||||
return render_template('notfound.html'), 404
|
return render_template('notfound.html'), 404
|
||||||
|
|
||||||
|
@app.errorhandler(403)
|
||||||
|
def error_403(body):
|
||||||
|
return render_template('forbidden.html'), 403
|
||||||
|
|
||||||
|
|
||||||
# Middle point during page editing.
|
# Middle point during page editing.
|
||||||
def savepoint(form, is_preview=False):
|
def savepoint(form, is_preview=False):
|
||||||
|
|
|
||||||
9
templates/forbidden.html
Normal file
9
templates/forbidden.html
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block title %}Access Denied - {{ app_name }}{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h1>Forbidden</h1>
|
||||||
|
|
||||||
|
<p>You don’t have permission to access this resource.</p>
|
||||||
|
{% endblock %}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue