def edit(id): tab = Tab.query.get(id) form = TabFrom( id=tab.id, tab_title=tab.title, format=tab.format_id, difficulty=tab.difficulty_id, style=tab.style_id, audio_url=tab.audio_url, tags=tab.tags, artist=tab.artist_id, ) if request.method == "GET": return render_template("tab_management.html", action="edit", form=form, artist=tab.artist) elif request.method == "POST": if form.validate_on_submit(): tab.title = form.tab_title.data tab.format_id = form.format.data tab.difficulty_id = form.difficulty.data tab.style_id = form.style.data tab.artist_id = form.artist.data tab.audio_url = form.audio_url.data tab.set_tags(form.tags.data) db.session.commit() flash(u"Update tab success", "success") return redirect(url_for("bp_admin_tab.edit", id=id)) else: flash(validator.catch_errors(form.errors), "error") return render_template("tab_management.html", action="edit", form=form)
def add(): artist_id = request.args["artist_id"] if "artist_id" in request.args else "" form = TabFrom(artist=artist_id) if request.method == "GET": return render_template( "tab_management.html", action="add", form=form, artist=Artist.query.filter_by(id=artist_id).first() ) elif request.method == "POST": if form.validate_on_submit(): tab = Tab( str(uuid4()), form.tab_title.data, form.format.data, form.artist.data, form.difficulty.data, form.style.data, form.audio_url.data, form.tags.data, ) db.session.add(tab) db.session.commit() flash(u"Add new tab success, please upload tab files", "success") return redirect(url_for("bp_admin_tabfile.edit", tab_id=tab.id, show_wizard=True)) else: flash(validator.catch_errors(form.errors), "error") return render_template("tab_management.html", action="add", form=form)
def edit(id): tab = Tab.query.get(id) form = TabFrom(id=tab.id, tab_title=tab.title, format=tab.format_id, difficulty=tab.difficulty_id, style=tab.style_id, audio_url=tab.audio_url, tags=tab.tags, artist=tab.artist_id) if request.method == 'GET': return render_template('tab_management.html', action='edit', form=form, artist=tab.artist) elif request.method == 'POST': if form.validate_on_submit(): tab.title = form.tab_title.data tab.format_id = form.format.data tab.difficulty_id = form.difficulty.data tab.style_id = form.style.data tab.artist_id = form.artist.data tab.audio_url = form.audio_url.data tab.set_tags(form.tags.data) db.session.commit() flash(u'Update tab success', 'success') return redirect(url_for('bp_admin_tab.edit', id=id)) else: flash(validator.catch_errors(form.errors), 'error') return render_template('tab_management.html', action='edit', form=form)
def add(): artist_id = request.args['artist_id'] if 'artist_id' in request.args else '' form = TabFrom(artist=artist_id) if request.method == 'GET': return render_template( 'tab_management.html', action='add', form=form, artist=Artist.query.filter_by(id=artist_id).first()) elif request.method == 'POST': if form.validate_on_submit(): tab = Tab(str(uuid4()), form.tab_title.data, form.format.data, form.artist.data, form.difficulty.data, form.style.data, form.audio_url.data, form.tags.data) db.session.add(tab) db.session.commit() flash(u'Add new tab success, please upload tab files', 'success') return redirect( url_for('bp_admin_tabfile.edit', tab_id=tab.id, show_wizard=True)) else: flash(validator.catch_errors(form.errors), 'error') return render_template('tab_management.html', action='add', form=form)
def add(): form = ArtistFrom() if request.method == 'GET': return render_template('artist_management.html', action='add', form=form) elif request.method == 'POST': if form.validate_on_submit(): artist_id = str(uuid4()) # upload photo file file = form.photo.data photo_filename = '' uploadfailed = False if file: photo_filename = artist_id + '.' + file.filename.rsplit( '.', 1)[1] if not oshelper.upload_file( file, oshelper.get_artistphoto_upload_abspath(), photo_filename): photo_filename = '' uploadfailed = True # add artist to db artist = Artist(artist_id, form.name.data, form.letter.data, photo_filename, form.region.data, form.category.data) db.session.add(artist) # flush data db.session.commit() flash(u'Add new artist success', 'success') if not uploadfailed: return redirect(url_for('bp_admin_artist.list')) else: # flash(u'Upload photo failed. Please try again!', 'warning') return redirect(url_for('bp_admin_artist.edit', id=artist_id)) else: error_message = validator.catch_errors(form.errors) flash(error_message, 'error') return render_template('artist_management.html', action='add', form=form)
def edit(id): artist = Artist.query.get(id) form = ArtistFrom(id=artist.id, name=artist.name, letter=artist.letter, photo=artist.letter, region=artist.region_id, category=artist.category_id) photo_relative_path = artist.photo_relative_path + '?dummy=' + str( random()) if request.method == 'GET': return render_template('artist_management.html', action='edit', form=form, photo_path=photo_relative_path) elif request.method == 'POST': if form.validate_on_submit(): # update artist artist.name = form.name.data artist.letter = form.letter.data artist.region_id = form.region.data artist.category_id = form.category.data # upload photo file file = form.photo.data if file: photo_filename = artist.id + '.' + file.filename.rsplit( '.', 1)[1] if oshelper.upload_file( file, oshelper.get_artistphoto_upload_abspath(), photo_filename): artist.photo = photo_filename # flush data db.session.commit() flash(u'Update artist success', 'success') return redirect(url_for('bp_admin_artist.edit', id=id)) else: error_message = validator.catch_errors(form.errors) flash(error_message, 'error') return render_template('artist_management.html', action='edit', form=form, photo_path=artist.photo_relative_path)
def edit(id): artist = Artist.query.get(id) form = ArtistFrom( id=artist.id, name=artist.name, letter=artist.letter, photo=artist.letter, region=artist.region_id, category=artist.category_id, ) photo_relative_path = artist.photo_relative_path + "?dummy=" + str(random()) if request.method == "GET": return render_template("artist_management.html", action="edit", form=form, photo_path=photo_relative_path) elif request.method == "POST": if form.validate_on_submit(): # update artist artist.name = form.name.data artist.letter = form.letter.data artist.region_id = form.region.data artist.category_id = form.category.data # upload photo file file = form.photo.data if file: photo_filename = artist.id + "." + file.filename.rsplit(".", 1)[1] if oshelper.upload_file(file, oshelper.get_artistphoto_upload_abspath(), photo_filename): artist.photo = photo_filename # flush data db.session.commit() flash(u"Update artist success", "success") return redirect(url_for("bp_admin_artist.edit", id=id)) else: error_message = validator.catch_errors(form.errors) flash(error_message, "error") return render_template( "artist_management.html", action="edit", form=form, photo_path=artist.photo_relative_path )
def add(): form = ArtistFrom() if request.method == "GET": return render_template("artist_management.html", action="add", form=form) elif request.method == "POST": if form.validate_on_submit(): artist_id = str(uuid4()) # upload photo file file = form.photo.data photo_filename = "" uploadfailed = False if file: photo_filename = artist_id + "." + file.filename.rsplit(".", 1)[1] if not oshelper.upload_file(file, oshelper.get_artistphoto_upload_abspath(), photo_filename): photo_filename = "" uploadfailed = True # add artist to db artist = Artist( artist_id, form.name.data, form.letter.data, photo_filename, form.region.data, form.category.data ) db.session.add(artist) # flush data db.session.commit() flash(u"Add new artist success", "success") if not uploadfailed: return redirect(url_for("bp_admin_artist.list")) else: # flash(u'Upload photo failed. Please try again!', 'warning') return redirect(url_for("bp_admin_artist.edit", id=artist_id)) else: error_message = validator.catch_errors(form.errors) flash(error_message, "error") return render_template("artist_management.html", action="add", form=form)