def gallery_list(): """Admin Gallery list Page. for look up all albums and create a new album. Methods: GET and POST Args: GET: none POST: title: string of album title Returns: GET: all albums POST: status: {status: success} """ if request.method == 'POST': title = request.form['title'] album = Gallery(title=title) album.save() return json.dumps({'success': 'true'}) else: albums = Gallery.objects.order_by('-publish_time') return render_template('admin/gallery/list.html', albums=albums)
def photo_del(album_id, photo_title): """Admin Photo Delete Action Used for delete Photo. Methods: GET Args: album_id: album_id ObjectID photo_title: string title of photo Returns: none """ Gallery.objects(pk=album_id).update_one(pull__content={'title': photo_title}) return redirect(url_for('admin.album_detail', album_id=album_id))
def album_detail(album_id): """Album Detail Admin Page. Used for upload new photos to UpYun and set deail about album.Also, if the album index is not set, use the first photo. Methods: GET and POST Args: GET: album ObjectID PSOT(*for ajax only): files: [name: 'Filedata'] album_id: album ObjectID Returns: GET: album data POST: status: {success: true/false, url: url} """ if request.method == 'POST': data = request.files['Filedata'] album_id = request.form['album_id'] filename = secure_filename(data.filename) helper = UpYunHelper() url = helper.up_to_upyun('gallery', data, filename) if url: photo = PhotoEm( path = url, title = filename ) Gallery.objects(pk=album_id).update(set__index=url) Gallery.objects(pk=album_id).update_one(push__content=photo) return json.dumps({'success': 'true', 'url': url}) else: return json.dumps({'success': 'false'}) else: album = Gallery.objects(pk=album_id)[0] return render_template('admin/gallery/detail.html', album=album)