def checkSeries(id): series = Serie.query.get_or_404(id) if request.method == 'GET': return redirect(url_for('showSeries', id=series.id)) url = request.referrer if not validate_token(): return redirect(url_for('checkSeries', id=series.id)) add = request.form.get('add', None) if add: if series not in current_user.favorite_series: current_user.favorite_series.append(series) flash('Added to watchlist!', 'success') else: current_user.favorite_series.remove(series) flash('Removed from watchlist!', 'success') db.session.commit() if url is not None: return redirect(url) return redirect(url_for('showSeries', id=series.id))
def checkEpisode(id): episode = Episode.query.get_or_404(id) if request.method == 'GET': return redirect(url_for('showEpisode', id=episode.id)) url = request.referrer if not validate_token(): return redirect(url_for('checkEpisode', id=episode.id)) add = request.form.get('add', None) if add: if episode not in current_user.watched_episodes: current_user.watched_episodes.append(episode) flash('Added to watched!', 'success') else: if episode in current_user.watched_episodes: current_user.watched_episodes.remove(episode) flash('Removed from watched!', 'success') fav = UserSerie.query.\ filter_by(user=current_user, \ serie=episode.serie).first() if fav is not None: fav.last_watched = datetime.now() db.session.add(fav) db.session.commit() if url is not None: return redirect(url) return redirect(url_for('showEpisode', id=episode.id))
def addShow(): tvdb_id = request.form.get('tvdb_id', None) name = request.form.get('name', None) first_aired = request.form.get('first_aired', None) overview = request.form.get('overview', None) if not validate_token(): return abort(404) if tvdb_id is None or name is None: return abort(404) new = Serie(name, tvdb_id) new.first_aired = first_aired.replace('-', '') new.overview = overview db.session.add(new) db.session.commit() try: id = new.id except: return abort(404) return redirect(url_for('showSeries', id=id))