aboutsummaryrefslogtreecommitdiffstats
path: root/views.py
diff options
context:
space:
mode:
authormjfernez <mjfernez@gmail.com>2021-08-25 20:05:00 -0400
committermjfernez <mjfernez@gmail.com>2021-08-25 20:05:00 -0400
commit6ddd97e1c39f55fe60fca093ca4fe610eca6d462 (patch)
treeb735576a0d7fa08364ea56b131e3ae47e7178d74 /views.py
parent4972877f8ef0e0e3664d3dd0edd651107ddc026f (diff)
downloadezcms-6ddd97e1c39f55fe60fca093ca4fe610eca6d462.tar.gz
Clarify siteconfig
This clarifies what the MAIN_SITE_DIRS option means since one might read it to mean you can put your directories anywhere. Not so, you can only pick which dirs are displayed with that option. Also recommends to not use the secret key unless needed (for what reason, I don't know).
Diffstat (limited to 'views.py')
-rw-r--r--views.py52
1 files changed, 24 insertions, 28 deletions
diff --git a/views.py b/views.py
index 682ff94..f7711b8 100644
--- a/views.py
+++ b/views.py
@@ -7,12 +7,8 @@ from server import app
# bit of a hack.
# Brackets don't play nicely with Jinja so instead of using .format,
# we just replace the special character $
-CONTENT_BLOCK = (
- "{% extends 'base.html' %}"
- "{% block content %}"
- "$"
- "{% endblock %}"
-)
+CONTENT_BLOCK = "{% extends 'base.html' %}{% block content %}${% endblock %}"
+
def default_context():
"""
@@ -21,8 +17,8 @@ def default_context():
make up the navbar
"""
return {
- 'domain': app.config['DOMAIN'],
- 'navbar': sorted(app.config['MAIN_SITE_DIRS'])
+ 'domain': app.config['DOMAIN'],
+ 'navbar': sorted(app.config['MAIN_SITE_DIRS']),
}
@@ -88,12 +84,7 @@ def home():
edit, though you can optionally change the title here if you wish
"""
context = default_context()
- context.update(
- {
- 'title': app.config['HOME_TITLE'],
- 'parent_dir': '/site/'
- }
- )
+ context.update({'title': app.config['HOME_TITLE'], 'parent_dir': '/site/'})
return render_template("site/home.html", **context)
@@ -115,14 +106,16 @@ def render_file(path):
context.update(
{
'title': path.split('.')[0].upper(),
- 'parent_dir': '/site/' + '/'.join(path.split('/')[:-1])
+ 'parent_dir': '/site/' + '/'.join(path.split('/')[:-1]),
}
)
if os.path.isfile(abs_path):
if abs_path.endswith('.html'):
with open(abs_path, 'rb') as f:
content = f.read().decode("UTF-8")
- return render_template_string(CONTENT_BLOCK.replace('$', content), **context)
+ return render_template_string(
+ CONTENT_BLOCK.replace('$', content), **context
+ )
elif abs_path.endswith('.html!'):
return render_template("site/" + path, **context)
else:
@@ -131,9 +124,8 @@ def render_file(path):
'templates/site/',
path,
mimetype=siteconfig.MIMETYPES.get(
- f".{ path.split('.')[-1] }",
- siteconfig.DEFAULT_MIMETYPE
- )
+ f".{ path.split('.')[-1] }", siteconfig.DEFAULT_MIMETYPE
+ ),
)
elif os.path.isdir(abs_path):
dirs, files, links, description = index_dir(abs_path)
@@ -144,7 +136,7 @@ def render_file(path):
'dirs': dirs,
'files': files,
'links': links,
- 'description': description
+ 'description': description,
}
)
return render_template("index.html", **context)
@@ -160,10 +152,12 @@ def send_file_from_site(path):
`render_file`, send the raw file to the user, when site is replace with
path.
"""
- return send_from_directory('templates/site/', path,
- mimetype=siteconfig.MIMETYPES.get(
- f".{ path.split('.')[-1] }", siteconfig.DEFAULT_MIMETYPE
- )
+ return send_from_directory(
+ 'templates/site/',
+ path,
+ mimetype=siteconfig.MIMETYPES.get(
+ f".{ path.split('.')[-1] }", siteconfig.DEFAULT_MIMETYPE
+ ),
)
@@ -173,8 +167,10 @@ def send_file_from_static(path):
send_file - instead of rendering a file within a template as with
`render_file`, send the raw file to the user
"""
- return send_from_directory('static/', path,
- mimetype=siteconfig.MIMETYPES.get(
- f".{ path.split('.')[-1] }", siteconfig.DEFAULT_MIMETYPE
- )
+ return send_from_directory(
+ 'static/',
+ path,
+ mimetype=siteconfig.MIMETYPES.get(
+ f".{ path.split('.')[-1] }", siteconfig.DEFAULT_MIMETYPE
+ ),
)