checkpoint

This commit is contained in:
voussoir 2016-10-20 20:15:24 -07:00
parent de60770d20
commit 198900c990
4 changed files with 45 additions and 3 deletions

View file

@ -322,7 +322,7 @@ def get_album_html(albumid):
)
return response
@site.route('/album/<albumid>')
@site.route('/album/<albumid>.json')
@give_session_token
def get_album_json(albumid):
album = get_album_core(albumid)
@ -330,11 +330,19 @@ def get_album_json(albumid):
@site.route('/albums')
@give_session_token
def get_albums():
def get_albums_html():
albums = P.get_albums()
albums = [a for a in albums if a.parent() is None]
return flask.render_template('albums.html', albums=albums)
@site.route('/albums.json')
@give_session_token
def get_albums_json():
albums = P.get_albums()
albums = [a for a in albums if a.parent() is None]
albums = [jsonify_album(album, minimal=True) for album in albums]
return make_json_response(albums)
@site.route('/file/<photoid>')
def get_file(photoid):
requested_photoid = photoid
@ -573,14 +581,34 @@ def get_thumbnail(photoid):
return send_file(path)
@site.route('/album/<albumid>', methods=['POST'])
@site.route('/album/<albumid>.json', methods=['POST'])
@give_session_token
def post_edit_album(albumid):
'''
Edit the album's title and description.
Apply a tag to every photo in the album.
'''
response = {}
album = P_album(albumid)
if 'add_tag' in request.form:
action = 'add_tag'
tag = request.form[action].strip()
try:
tag = P_tag(tag)
except phototagger.NoSuchTag:
response = {'error': 'That tag doesnt exist', 'tagname': tag}
return make_json_response(response, status=404)
recursive = request.form.get('recursive', False)
recursive = truthystring(recursive)
album.add_tag_to_all(tag, nested_children=recursive)
response['action'] = action
response['tagname'] = tag.name
return make_json_response(response)
@site.route('/photo/<photoid>', methods=['POST'])
@site.route('/photo/<photoid>.json', methods=['POST'])
@give_session_token
def post_edit_photo(photoid):
'''

View file

@ -1570,6 +1570,8 @@ class Album(ObjectBase, GroupableMixin):
def add_photo(self, photo, commit=True):
if self.has_photo(photo):
return
if self.photodb != photo.photodb:
raise ValueError('Not the same PhotoDB')
self.photodb.cur.execute('INSERT INTO album_photo_rel VALUES(?, ?)', [self.id, photo.id])
if commit:
log.debug('Committing - add photo to album')

View file

@ -12,7 +12,14 @@ function create_message_bubble(message_positivity, message_text, lifespan)
message_area.appendChild(message);
setTimeout(function(){message_area.removeChild(message);}, lifespan);
}
function add_album_tag(albumid, tagname, callback)
{
if (tagname === ""){return}
var url = "/album/" + albumid;
data = new FormData();
data.append("add_tag", tagname);
return post(url, data, callback);
}
function add_photo_tag(photoid, tagname, callback)
{
if (tagname === ""){return}

View file

@ -51,4 +51,9 @@
</html>
<script type="text/javascript">
function submit_tag(callback)
{
add_photo_tag('{{album["id"]}}', add_tag_box.value, callback);
add_tag_box.value = "";
}
</script>