adding paginated listings on index, improved submission flows, better html templating

graphs-n-shit
lza_menace 4 years ago
parent 95c5882e39
commit d199943b45

@ -7,6 +7,7 @@ from flask import Flask, g, request, redirect, url_for, abort
from flask import jsonify, render_template, flash, session
from flask import send_from_directory, make_response
from flask_session import Session
from playhouse.flask_utils import PaginatedQuery
from werkzeug.utils import secure_filename
from suchwow.models import Meme, db
@ -37,13 +38,19 @@ def login_required(f):
@app.route("/")
def index():
return render_template("index.html")
page = request.args.get('page')
if page.isdigit() is False:
flash("Wow, wtf hackerman. Cool it.")
page = 1
memes = Meme.select().order_by(Meme.timestamp).paginate(int(page), 10)
return render_template("index.html", memes=memes, page=page)
@app.route("/meme/<id>")
def view(id):
def meme(id):
if Meme.filter(id=id):
m = Meme.get(Meme.id == id)
return render_template("view.html", meme=m)
meme = Meme.get(Meme.id == id)
return render_template("meme.html", meme=meme)
else:
return "no meme there brah"
@ -55,27 +62,31 @@ def uploaded_file(filename):
@login_required
def submit():
if request.method == "POST":
meme_title = request.form.get('title')
# check if the post request has the file part
if "file" not in request.files:
flash("No file part")
flash("You didn't upload a caliente meme, bro! You're fuckin up!")
return redirect(request.url)
file = request.files["file"]
# if user does not select file, browser also
# submit an empty part without filename
if file.filename == "":
flash("No selected file")
flash("You didn't upload a caliente meme, bro! You're fuckin up!")
return redirect(request.url)
if meme_title is "":
flash("You didn't give your meme a spicy title, bro! You're fuckin up!")
return redirect(request.url)
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
save_path = os.path.join(app.config["UPLOAD_FOLDER"], filename)
file.save(save_path)
meme = Meme(
title=request.form.get('title'),
title=meme_title,
submitter=session["auth"]["preferred_username"],
image_name=filename,
)
meme.save()
return redirect(url_for("view", id=meme.id))
return redirect(url_for("meme", id=meme.id))
return render_template("submit.html")
@app.route("/login")

@ -3,15 +3,29 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Meme Factory</title>
<title>SuchWOW!</title>
<meta name="author" content="name">
<meta name="description" content="description here">
<meta name="keywords" content="keywords,here">
</head>
<body>
<a href="/">Home</a><br>
<a href="/view">See da meemz</a>
{% if session.auth == None %}
<a href="{{ url_for('login') }}">Login</a><br>
{% else %}
<a href="{{ url_for('logout') }}">Logout</a><br>
{% endif %}
<hr>
{% with messages = get_flashed_messages() %}
{% if messages %}
<ul class=flashes>
{% for message in messages %}
<li>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
{% endwith %}
<hr>
{% block content %}{% endblock %}
</body>
</html>

@ -1,7 +1,19 @@
{% extends 'base.html' %}
{% block content %}
<a href="{{ url_for('login') }}">Login</a><br>
<a href="{{ url_for('submit') }}">Submit A Meme</a><br>
<a href="{{ url_for('debug') }}">Visit the secret page!</a>
<a href="{{ url_for('debug') }}">Debug</a>
{% block header %}
<h1>{% block title %}Latest Submissions{% endblock %}</h1>
{% endblock %}
<ul>
{% for meme in memes %}
<li><a href="{{ url_for('meme', id=meme.id) }}">{{ meme.title }}</a></li>
{% endfor %}
</ul>
{{ page }}
{% endblock %}

Loading…
Cancel
Save