diff --git a/etiquette/etiquette.py b/etiquette/etiquette.py index 565093d..2341162 100644 --- a/etiquette/etiquette.py +++ b/etiquette/etiquette.py @@ -322,7 +322,7 @@ def get_album_html(albumid): ) return response -@site.route('/album/') +@site.route('/album/.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/') def get_file(photoid): requested_photoid = photoid @@ -573,14 +581,34 @@ def get_thumbnail(photoid): return send_file(path) @site.route('/album/', methods=['POST']) +@site.route('/album/.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/', methods=['POST']) +@site.route('/photo/.json', methods=['POST']) @give_session_token def post_edit_photo(photoid): ''' diff --git a/etiquette/phototagger.py b/etiquette/phototagger.py index 1e72132..10e894f 100644 --- a/etiquette/phototagger.py +++ b/etiquette/phototagger.py @@ -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') diff --git a/etiquette/static/common.js b/etiquette/static/common.js index 9866419..436bcfa 100644 --- a/etiquette/static/common.js +++ b/etiquette/static/common.js @@ -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} diff --git a/etiquette/templates/album.html b/etiquette/templates/album.html index 4dbcfe2..8181800 100644 --- a/etiquette/templates/album.html +++ b/etiquette/templates/album.html @@ -51,4 +51,9 @@ \ No newline at end of file