Skip to content

Commit

Permalink
hmm
Browse files Browse the repository at this point in the history
  • Loading branch information
chee committed Nov 17, 2020
1 parent 1e4f788 commit 0c97e42
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
1 change: 0 additions & 1 deletion app/config.py
Expand Up @@ -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')}"
Expand Down
24 changes: 13 additions & 11 deletions app/routes.py
Expand Up @@ -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():
Expand Down Expand Up @@ -123,9 +123,11 @@ def new_collection(username):
@app.route('/<username>/<slug>/')
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)
Expand Down Expand Up @@ -171,31 +173,31 @@ def piece_json(username, collection_slug, piece_slug):
))

@login_required
@app.route('/<username>/<slug>/new', methods=['GET', 'POST'])
@app.route('/<username>/<slug>/new/', methods=['GET', 'POST'])
def new_piece(username, slug):
@app.route('/<username>/<category_slug>/new', methods=['GET', 'POST'])
@app.route('/<username>/<category_slug>/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()
if form.validate_on_submit():
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,
Expand All @@ -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)

0 comments on commit 0c97e42

Please sign in to comment.