From 8e3a6338c79e095d6dc511dd77b26f5769259b30 Mon Sep 17 00:00:00 2001 From: lza_menace Date: Mon, 20 Dec 2021 01:50:49 -0800 Subject: [PATCH] setup per meme views, use html includes --- suchwowx/models.py | 1 + suchwowx/routes.py | 25 ++++++++++++++++---- suchwowx/templates/includes/head.html | 9 ++++++++ suchwowx/templates/index.html | 15 +++--------- suchwowx/templates/meme.html | 33 +++++++++++++++++++++++++++ suchwowx/templates/new.html | 15 +++--------- suchwowx/templates/next.html | 17 -------------- 7 files changed, 69 insertions(+), 46 deletions(-) create mode 100644 suchwowx/templates/includes/head.html create mode 100644 suchwowx/templates/meme.html delete mode 100644 suchwowx/templates/next.html diff --git a/suchwowx/models.py b/suchwowx/models.py index 67909f0..e312557 100644 --- a/suchwowx/models.py +++ b/suchwowx/models.py @@ -2,6 +2,7 @@ from uuid import uuid4 from datetime import datetime from suchwowx.factory import db +from suchwowx import config def rand_id(): diff --git a/suchwowx/routes.py b/suchwowx/routes.py index 157749f..642d358 100644 --- a/suchwowx/routes.py +++ b/suchwowx/routes.py @@ -3,7 +3,8 @@ from os import path from secrets import token_urlsafe from json import loads, dumps -from flask import Blueprint, render_template, request, current_app, redirect +from flask import Blueprint, render_template, request, current_app +from flask import send_from_directory, redirect from suchwowx.models import Meme from suchwowx.factory import db @@ -12,6 +13,11 @@ from suchwowx import config bp = Blueprint('meta', 'meta') +@bp.route('/') +def index(): + memes = Meme.query.filter().order_by(Meme.create_date.desc()) + return render_template('index.html', memes=memes) + @bp.route('/new', methods=['GET', 'POST']) def new(): meme = None @@ -67,7 +73,16 @@ def new(): meme=meme ) -@bp.route('/') -def index(): - memes = Meme.query.filter().order_by(Meme.create_date.desc()) - return render_template('index.html', memes=memes) +@bp.route('/uploads/') +def uploaded_file(filename): + """ + Retrieve an uploaded file from uploads directory. + """ + return send_from_directory(f'{config.DATA_FOLDER}/uploads', filename) + +@bp.route('/meme/') +def meme(meme_id): + meme = Meme.query.filter(Meme.id == meme_id).first() + if not meme: + return redirect('/') + return render_template('meme.html', meme=meme) diff --git a/suchwowx/templates/includes/head.html b/suchwowx/templates/includes/head.html new file mode 100644 index 0000000..16c322d --- /dev/null +++ b/suchwowx/templates/includes/head.html @@ -0,0 +1,9 @@ + + + + SuchWowX! + + + + + diff --git a/suchwowx/templates/index.html b/suchwowx/templates/index.html index 87f9cdb..5f866ff 100644 --- a/suchwowx/templates/index.html +++ b/suchwowx/templates/index.html @@ -1,20 +1,11 @@ - - - - SuchWowX! - - - - - + {% include 'includes/head.html' %}

- SuchWowX.
- + SuchWowX.

Memes. Interplanetary! @@ -25,7 +16,7 @@

{% for meme in memes %}
-

Meme: {{ meme }}

+

Meme: {{ meme }}

Upload path: {{ meme.upload_path }}

Meta IPFS: {{ meme.meta_ipfs_hash }}

Meme IPFS: {{ meme.meme_ipfs_hash }}

diff --git a/suchwowx/templates/meme.html b/suchwowx/templates/meme.html new file mode 100644 index 0000000..fd80698 --- /dev/null +++ b/suchwowx/templates/meme.html @@ -0,0 +1,33 @@ + + + {% include 'includes/head.html' %} + +
+
+

+ SuchWowX. +

+

+ Memes. Interplanetary! +

+ Go Home + + {% if meme %} +
+
+

Meme: {{ meme }}

+

Upload path: {{ meme.upload_path }}

+

Meta IPFS: {{ meme.meta_ipfs_hash }}

+

Meme IPFS: {{ meme.meme_ipfs_hash }}

+

Title: {{ meme.title }}

+

Description: {{ meme.description }}

+

Creator handle: {{ meme.creator_handle }}

+ +
+
+ {% endif %} + +
+
+ + diff --git a/suchwowx/templates/new.html b/suchwowx/templates/new.html index e3a2e00..6be9798 100644 --- a/suchwowx/templates/new.html +++ b/suchwowx/templates/new.html @@ -1,27 +1,18 @@ - - - - SuchWowX! - - - - - + {% include 'includes/head.html' %}

- SuchWowX.
- + SuchWowX.

Memes. Interplanetary!

Go Back -
+
diff --git a/suchwowx/templates/next.html b/suchwowx/templates/next.html deleted file mode 100644 index 5216092..0000000 --- a/suchwowx/templates/next.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - ♥ - - - - ♠ - - -