def show_change_setting(album, setting, value): show = Show(album, current_app.config, session) try: show.change_setting(setting, value).save() except: return jsonify(result='Failed') return jsonify(result='OK')
def show_change_password(album): if request.method == 'POST': show = Show(album, current_app.config, session) username = request.form['username'] password = request.form['password'] show.set_user(username, current_app.config['SECRET_KEY'], password).save() return goback(True)
def show_edit_users(album): show = Show(album, current_app.config, session) users = show.data['users'] return render_themed('edit_users.html', album=album, show=show, users=users)
def show_nonpaginated(album, template='grid_full'): show = Show(album, current_app.config, session) if len(show.data['files']) == 0: abort(404) files = show.data['files'] return render_themed(template + '.html', album=album, files=files)
def image_page(album, filename): show = Show(album, current_app.config, session) image = Image(album, filename, current_app.config) exif_manager = ExifManager(image) exif_array = exif_manager.get_exif() if exif_array is None: exif_array = {} return render_themed('image.html', album=album, filename=filename, exif=exif_array, show=show)
def toggle_publish_image(album, filename): """Toggle publish image""" show = Show(album, current_app.config, session) try: show.toggle_image(filename).save() except: return jsonify(result='Failed') return jsonify(result='OK')
def add_image_to_show(album, filename): """Add an image to the show""" show = Show(album, current_app.config, session) try: show.add_image(filename).save() except: return jsonify(result='Failed') return jsonify(result='OK')
def remove_image_from_show(album, filename): """Remove an image from the show""" show = Show(album, current_app.config, session) try: show.remove_image(filename).save() except: return jsonify(result='Failed') return jsonify(result='OK')
def image_page(album, filename, template='image'): image = Image(album, filename, current_app.config) show = Show(album, current_app.config, session) exif_manager = ExifManager(image) exif_array = exif_manager.get_exif() return render_themed(template + '.html', album=album, filename=filename, exif=exif_array, show=show)
def list_album(album, page, template='list'): if template in current_app.config['FRONTEND_LIST_TEMPLATES']: show = Show(album, current_app.config, session) paginator = get_paginator(album, page, 'frontend.list_album', template) return render_themed(template + '.html', album=album, show=show, files=paginator.entries, paginator=paginator, page=page) else: abort(404)
def show_index(): dir_list = os.listdir(current_app.config['ALBUMS_DIR']) full_album_list = [os.path.basename(album) for album in dir_list] shows = {} for album in full_album_list: show = Show(album, current_app.config, session) if show.is_enabled: shows[album] = show album_list = shows.keys() album_list.sort(reverse=True) return render_themed('index.html', albums=album_list, shows=shows)
def get_paginator(album, page, endpoint, template): show = Show(album, current_app.config, session) if len(show.data['files']) == 0: abort(404) files = show.data['files'] if show.get_setting('reverse') == 'yes': files.reverse() try: return Paginator(album, files, current_app.config['THUMBNAILS_PER_PAGE'], page, endpoint, template) except: abort(404)
def _paginated_overview(album, page, endpoint='admin.list', template='grid'): show = Show(album, current_app.config, session) files = os.listdir(os.path.join(current_app.config['ALBUMS_DIR'], album)) ext = re.compile(".(jpg|png|gif|bmp)$", re.IGNORECASE) files = [f for f in files if ext.search(f)] #if len(files) == 0: #abort(404) files.sort() if show.get_setting('reverse') == 'yes': files.reverse() try: return Paginator(album, files, current_app.config['THUMBNAILS_PER_PAGE'], page, endpoint, template) except: abort(404)
def list_album(album, page, template='grid'): show = Show(album, current_app.config, session) ext = re.compile(".(jpg|png|gif|bmp)$", re.IGNORECASE) album_dir = os.path.join(current_app.config['ALBUMS_DIR'], album) all_files = [f for f in os.listdir(album_dir) if ext.search(f)] all_files.sort() if show.get_setting('reverse') == 'yes': all_files.reverse() paginator = _paginated_overview(album, page, 'admin.list_album', template) return render_themed(template + '.html', album=album, show=show, files=paginator.entries, paginator=paginator, page=page, all_files=all_files)
def authenticate(album): """Check user credentials and initialize session""" show = Show(album, current_app.config, session) if request.method == 'POST': form = LoginForm() if form.validate_on_submit(): if show.check_auth(request.form['username'], current_app.config['SECRET_KEY'], request.form['password']): next_url = None if session.has_key('next_url'): next_url = session['next_url'] session.clear() session['username'] = request.form['username'] session['album'] = album if next_url is not None: session['next_url'] = next_url return True return False
def decorated_function(album, *args, **kwargs): show = Show(album, current_app.config, session) if show.need_authentication: session['next_url'] = request.url return redirect(url_for('.login', album=album)) return f(album, *args, **kwargs)
def show_remove_user(album, username): show = Show(album, current_app.config, session) show.remove_user(username).save() return jsonify(result='OK')
def sort_show_by_exifdate(album): """Sort the show by exif datetime """ show = Show(album, current_app.config, session) show.sort_by_exif_datetime().save() return goback(True)
def sort_show_by_filename(album): """Sort the show by filename """ show = Show(album, current_app.config, session) show.sort_by_filename().save() return goback(True)
def add_all_images_to_show(album): show = Show(album, current_app.config, session) show.add_all_images().save() return goback(True)