def edit_release(game_slug="", release_id=""): form = ReleaseForm() error = None game = Game.query.filter(Game.slug==game_slug).one() release = db.session.query(Release).filter(Release.id==release_id).one() if form.validate_on_submit(): release.release_date = form.release_date.data release.release_version = form.release_version.data release.engine_id = form.engine_id.data release.release_description = form.release_description.data release.engine_version = form.engine_version.data platforms = [] for platform in release.platforms: if not platform.platform_id in form.platforms.data: pl = PlatformRelease.query.filter_by(id=platform.id).first() db.session.delete(pl) platforms.append(platform.platform_id) for platform in form.platforms.data: if not platform in platforms: db.session.add(PlatformRelease(release_id=release.id, platform_id=platform)) db.session.commit() flash('Release data was saved.') return redirect(url_for('game_details', game_slug=game_slug)) else: form.release_date.data = release.release_date form.release_version.data = release.release_version form.engine_id.data = release.engine_id form.release_description.data = release.release_description form.engine_version.data = release.engine_version form.platforms.data = [] for platform in release.platforms: form.platforms.data.append(platform.platform_id) return render_template('add_release.html', game=game, navigation=return_navigation(), error=error, site_data=site_data(), form=form)
def add_release(game_slug=""): form = ReleaseForm() error = None game = Game.query.filter(Game.slug==game_slug).one() if form.validate_on_submit(): release = Release(game_id=game.id, release_date=form.release_date.data, release_version=form.release_version.data, engine_id=form.engine_id.data, release_description = form.release_description.data, engine_version = form.engine_version.data, user_id=g.user.id) save_release(release, form.platforms.data) db.session.commit() flash('New release data was added.') return redirect(url_for("upload_file", game_slug=game_slug)+'?release='+str(release.id)) return render_template('add_release.html', game=game, navigation=return_navigation(), error=error, site_data=site_data(), form=form)