Add /bookmarks/create_bookmark endpoint. No interface yet.

This commit is contained in:
voussoir 2017-06-12 20:15:02 -07:00
parent ac2b820a30
commit 8a0bbbcc56
3 changed files with 27 additions and 4 deletions

View file

@ -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,

View file

@ -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/<photoid>')
def get_file(photoid):

View file

@ -44,11 +44,11 @@
{% for bookmark in bookmarks %}
<div class="bookmark_card">
<a href="{{bookmark.url}}" class="bookmark_title">
{% if bookmark.title %}
{%- if bookmark.title -%}
{{bookmark.title}}
{% else %}
{%- else -%}
{{bookmark.id}}
{% endif %}
{%- endif -%}
</a>
<a href="{{bookmark.url}}" class="bookmark_url">{{bookmark.url}}</a>
</div>