def storymap_delete(user, id): """Delete storymap""" try: key_prefix = storage.key_prefix(user['uid'], id) key_list, marker = storage.list_keys(key_prefix, 50) for key in key_list: storage.delete(key) del user['storymaps'][id] save_user(user) return jsonify({}) except Exception as e: traceback.print_exc() return jsonify({'error': str(e)})
def storymap_copy(user, id): """ Copy storymap @id = storymap to copy @title = name of new copy """ try: title = _request_get_required('title') dst_id = _make_storymap_id(user, title) src_key_prefix = storage.key_prefix(user['uid'], id) dst_key_prefix = storage.key_prefix(user['uid'], dst_id) src_re = re.compile(r'%s' % src_key_prefix) src_key_list, more = storage.list_keys(src_key_prefix, 999, '') for src_key in src_key_list: file_name = src_key.split(src_key_prefix)[-1] dst_key_name = "%s%s" % (dst_key_prefix, file_name) if file_name.endswith('.json'): json_string = storage.get_contents_as_string(src_key) storage.save_json(dst_key_name, src_re.sub(dst_key_prefix, json_string)) else: storage.copy_key(src_key, dst_key_name) # Update meta user['storymaps'][dst_id] = { 'id': dst_id, 'title': title, 'draft_on': user['storymaps'][id]['draft_on'], 'published_on': user['storymaps'][id]['published_on'] } _user.save(user) # Write new embed pages _write_embed_draft(dst_key_prefix, user['storymaps'][dst_id]) if user['storymaps'][dst_id].get('published_on'): _write_embed_published(dst_key_prefix, user['storymaps'][dst_id]) return jsonify(user['storymaps'][dst_id]) except Exception, e: traceback.print_exc() return jsonify({'error': str(e)})