diff --git a/etiquette/jsonify.py b/etiquette/jsonify.py index 1cc714a..500d4d8 100644 --- a/etiquette/jsonify.py +++ b/etiquette/jsonify.py @@ -18,6 +18,14 @@ def album(a, minimal=False): return j +def bookmark(b): + j = { + 'id': b.id, + 'url': b.url, + 'title': b.title, + } + return j + def exception(e): j = { 'error_type': e.error_type, diff --git a/frontends/etiquette_flask/etiquette_flask/etiquette_flask.py b/frontends/etiquette_flask/etiquette_flask/etiquette_flask.py index afd3dee..2173b3b 100644 --- a/frontends/etiquette_flask/etiquette_flask/etiquette_flask.py +++ b/frontends/etiquette_flask/etiquette_flask/etiquette_flask.py @@ -378,11 +378,26 @@ def get_albums_json(): @site.route('/bookmarks') @session_manager.give_token -def get_bookmarks(): +def get_bookmarks_html(): session = session_manager.get(request) bookmarks = list(P.get_bookmarks()) return flask.render_template('bookmarks.html', bookmarks=bookmarks, session=session) +@site.route('/bookmarks.json') +@session_manager.give_token +def get_bookmarks_json(): + bookmarks = [etiquette.jsonify.bookmark(b) for b in P.get_bookmarks()] + return jsonify.make_json_response(bookmarks) + +@site.route('/bookmarks/create_bookmark', methods=['POST']) +@decorators.required_fields(['url'], forbid_whitespace=True) +def post_bookmarks_create(): + url = request.form['url'] + title = request.form.get('title', None) + bookmark = P.new_bookmark(url=url, title=title) + response = etiquette.jsonify.bookmark(bookmark) + response = jsonify.make_json_response(response) + return response @site.route('/file/') def get_file(photoid): diff --git a/frontends/etiquette_flask/templates/bookmarks.html b/frontends/etiquette_flask/templates/bookmarks.html index a60bc32..72be585 100644 --- a/frontends/etiquette_flask/templates/bookmarks.html +++ b/frontends/etiquette_flask/templates/bookmarks.html @@ -44,11 +44,11 @@ {% for bookmark in bookmarks %}
- {% if bookmark.title %} + {%- if bookmark.title -%} {{bookmark.title}} - {% else %} + {%- else -%} {{bookmark.id}} - {% endif %} + {%- endif -%} {{bookmark.url}}