From 0c97e4260fcc5168323a7471bfa2a5bfafa693d1 Mon Sep 17 00:00:00 2001 From: chee Date: Tue, 17 Nov 2020 12:43:09 +0000 Subject: [PATCH] hmm --- app/config.py | 1 - app/routes.py | 24 +++++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/app/config.py b/app/config.py index 6f21334..aab1665 100644 --- a/app/config.py +++ b/app/config.py @@ -3,7 +3,6 @@ from dotenv import load_dotenv load_dotenv() - class Config(object): SECRET_KEY = os.environ.get('CC0_SECRET_KEY') SQLALCHEMY_DATABASE_URI = os.environ.get("CC0_SQLALCHEMY_DATABASE_URI") or f"sqlite:///{os.path.join(basedir, 'app.db')}" diff --git a/app/routes.py b/app/routes.py index 269f8e7..3ae9118 100644 --- a/app/routes.py +++ b/app/routes.py @@ -11,8 +11,8 @@ def render_json(thing): return Response(stringify_json(thing), mimetype="application/json") -def render_404(): - return Response("404", status=404) +def render_404(thing=""): + return Response(f"404 {thing} not found", status=404) @app.route('/') def index(): @@ -123,9 +123,11 @@ def new_collection(username): @app.route('///') def collection(username, slug): ch = CopyrightHolder.query.filter_by(username=username).first() + if ch is None: + return render_404("copyright_holder") collection = ch.collections.filter_by(slug=slug).first() if collection is None: - return render_404() + return render_404("collection") return render_template("collection.html", copyright_holder=ch, collection=collection) @@ -171,16 +173,16 @@ def piece_json(username, collection_slug, piece_slug): )) @login_required -@app.route('///new', methods=['GET', 'POST']) -@app.route('///new/', methods=['GET', 'POST']) -def new_piece(username, slug): +@app.route('///new', methods=['GET', 'POST']) +@app.route('///new/', methods=['GET', 'POST']) +def new_piece(username, category_slug): ch = CopyrightHolder.query.filter_by(username=username).first() if ch is None: return render_404() if current_user.id != ch.id: flash("hey, that's not yours") return redirect(url_for('index')) - collection = Collection.query.filter_by(slug=slug).first() + collection = Collection.query.filter_by(slug=category_slug).first() if collection is None: return render_404() form = PieceForm() @@ -188,14 +190,14 @@ def new_piece(username, slug): piece_slug = slugify(form.name.data) existing = Piece.query.filter_by(slug=piece_slug).first() if existing is not None: - flash(f"that name would need the path {username}/{slug}/{piece_slug}, which is taken") + flash(f"that name would need the path {username}/{category_slug}/{piece_slug}, which is taken") return redirect(url_for('new_piece', username=username, - slug=slug)) + slug=category_slug)) file = form.file.data url = get_url_for(file, username=username, - collection_slug=slug, + collection_slug=category_slug, piece_slug=piece_slug) type = get_type_for(file) piece = Piece(name=form.name.data, @@ -211,7 +213,7 @@ def new_piece(username, slug): flash(f"{piece.name} created") return redirect(url_for('collection', username=username, - slug=slug)) + slug=category_slug)) return render_template('new_piece.html', title=f"add to '{collection.name}'", form=form)