From 3dc96e8b31eeef876c89aadf26dbf1e5d3355e7f Mon Sep 17 00:00:00 2001 From: romangraef Date: Sat, 2 Jun 2018 10:33:15 +0200 Subject: Added featured projects --- app.py | 18 +++++++++++------- templates/gallery_all.html | 5 +++++ templates/index.html | 1 + 3 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 templates/gallery_all.html diff --git a/app.py b/app.py index 6b3e4da..5b0ba5e 100644 --- a/app.py +++ b/app.py @@ -36,7 +36,6 @@ def check_password(password) -> bool: @app.context_processor def inject(): return { - 'projects': from_json(db.all(), List[Project]), 'empty_project': Project(), 'admin': session.get('logged_in', False), 'no_login': False, @@ -83,6 +82,11 @@ def find_project(name) -> Document: return matches[0] +@app.route('/projects/') +def list_all_projects(): + return render_template("gallery_all.html", projects=from_json(db.all(), List[Project])) + + @app.route('/projects/new/') @require_admin() def new_project_form(): @@ -92,9 +96,8 @@ def new_project_form(): @app.route('/projects/new/', methods=['POST']) @require_admin() def new_project(): - id = request.form.get('id') - Q = Query() - matches = db.search(Q.id == id.lower()) + post_id = request.form.get('id') + matches = db.search(Query().id == post_id.lower()) if len(matches) != 0: abort(400) name = request.form.get('name') @@ -103,12 +106,13 @@ def new_project(): link = request.form.get('link') db.insert({ 'name': name, - 'id': id, + 'id': post_id, 'summary': summary, 'description': description, 'link': link, + 'featured': 0, }) - return redirect(url_for('projects', project_name=id)) + return redirect(url_for('projects', project_name=post_id)) @app.route('/projects//edit/', methods=['GET']) @@ -154,7 +158,7 @@ def delete_project_confirm(project_name): @app.route('/') def index(): - return render_template('index.html') + return render_template('index.html', projects=from_json(db.search(Query().featured == 1), List[Project])) app.secret_key = os.environ.get('app_secret', '') diff --git a/templates/gallery_all.html b/templates/gallery_all.html new file mode 100644 index 0000000..d6cc8f4 --- /dev/null +++ b/templates/gallery_all.html @@ -0,0 +1,5 @@ +{% extends "base.html" %} +{% block body %} +

Projects

+ {% include "gallery.html" %} +{% endblock %} \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index 27b3232..1d0d753 100644 --- a/templates/index.html +++ b/templates/index.html @@ -7,6 +7,7 @@

As long as it is not webdesign, I will program nearly anything for you

Projects

+

All projects

{% include "gallery.html" %} {% endblock %} {% block title %} -- cgit