|
|
|
@ -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")
|
|
|
|
|