From 1ad83937b45bd72407e1283b0aeb9ce5eb081633 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sat, 13 May 2017 16:13:26 -0700 Subject: [PATCH] Add 'Create Album' endpoint and interface. --- .../etiquette_flask/etiquette_flask.py | 18 ++++++++++++++++-- frontends/etiquette_flask/static/common.js | 17 ++++++++++++++++- frontends/etiquette_flask/templates/album.html | 9 ++------- .../etiquette_flask/templates/albums.html | 2 ++ 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/frontends/etiquette_flask/etiquette_flask/etiquette_flask.py b/frontends/etiquette_flask/etiquette_flask/etiquette_flask.py index ded6aaf..7be70b6 100644 --- a/frontends/etiquette_flask/etiquette_flask/etiquette_flask.py +++ b/frontends/etiquette_flask/etiquette_flask/etiquette_flask.py @@ -684,7 +684,6 @@ def post_album_add_tag(albumid): response['tagname'] = tag.name return jsonify.make_json_response(response) - @site.route('/album//edit', methods=['POST']) @session_manager.give_token def post_album_edit(albumid): @@ -696,7 +695,22 @@ def post_album_edit(albumid): title = request.form.get('title', None) description = request.form.get('description', None) album.edit(title=title, description=description) - response = {'title': album.title, 'description': album.description} + response = etiquette.jsonify.album(album, minimal=True) + return jsonify.make_json_response(response) + +@site.route('/albums/create_album', methods=['POST']) +def post_albums_create(): + print(dict(request.form)) + title = request.form.get('title', None) + description = request.form.get('description', None) + parent = request.form.get('parent', None) + if parent is not None: + parent = P_album(parent) + + album = P.new_album(title=title, description=description) + if parent is not None: + parent.add(album) + response = etiquette.jsonify.album(album, minimal=False) return jsonify.make_json_response(response) diff --git a/frontends/etiquette_flask/static/common.js b/frontends/etiquette_flask/static/common.js index 94ad5bc..97ba1b4 100644 --- a/frontends/etiquette_flask/static/common.js +++ b/frontends/etiquette_flask/static/common.js @@ -49,8 +49,23 @@ function bind_box_to_button(box, button, ctrl_enter) button.click(); } }; - } + +function create_album_and_follow(parent) +{ + var url = "/albums/create_album"; + var data = new FormData(); + if (parent !== undefined) + { + data.append("parent", parent); + } + function receive_callback(response) + { + window.location.href = "/album/" + response["id"]; + } + post(url, data, receive_callback); +} + function entry_with_history_hook(box, button) { //console.log(event.keyCode); diff --git a/frontends/etiquette_flask/templates/album.html b/frontends/etiquette_flask/templates/album.html index b2eacc7..7364314 100644 --- a/frontends/etiquette_flask/templates/album.html +++ b/frontends/etiquette_flask/templates/album.html @@ -74,20 +74,15 @@ p {% endif %} {% set sub_albums = album.children() %} - {% if sub_albums %}

Sub-albums

- {% endif %} {% set photos = album.photos() %} - {% if photos or sub_albums %} - {% endif %} - {% if photos %}

Photos

{% if view != "list" %} diff --git a/frontends/etiquette_flask/templates/albums.html b/frontends/etiquette_flask/templates/albums.html index dcc4970..46eb4ce 100644 --- a/frontends/etiquette_flask/templates/albums.html +++ b/frontends/etiquette_flask/templates/albums.html @@ -5,6 +5,7 @@ Albums +