From cbf65f221ab43ee815c3a3bdce8b9cf86bdef455 Mon Sep 17 00:00:00 2001 From: Xevion Date: Tue, 21 Jan 2020 23:16:19 -0600 Subject: [PATCH] add in Episode route, forward/back buttons preparing to add in CSS and stuff, but I'm kind of not-at-all-wanting-to-do-that --- app/models.py | 10 +++++++--- app/routes.py | 14 ++++++++++---- app/templates/episode.html | 5 +++++ app/templates/season.html | 4 ++++ 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/app/models.py b/app/models.py index aa454a4..d0b53f4 100644 --- a/app/models.py +++ b/app/models.py @@ -99,13 +99,16 @@ class Episode(db.Model): db.session.add(s) db.session.commit() + def rebuild(self): + self.clear() + self.build() + def clear(self): """delete all sections relevant to this episode in order to reprocess""" sections = Section.query.filter_by(episode_id=self.id).all() print(f'Clearing {len(sections)} Sections of Ep {self.number} Season {self.season_id}') for section in sections: - section.clear(commit=False) - db.session.delete(section) + section.clear(commit=False, delete=True) db.session.commit() @staticmethod @@ -139,12 +142,13 @@ class Section(db.Model): db.session.add(q) if commit: db.session.commit() - def clear(self, doprint=True, commit=True): + def clear(self, doprint=True, commit=True, delete=False): """delete all quotes relevant to this section""" quotes = Quote.query.filter_by(section_id=self.id).all() if doprint: print(f'Clearing {len(quotes)} quotes from Section ID {self.id}') for quote in quotes: db.session.delete(quote) + if delete: db.session.delete(self) if commit: db.session.commit() def __repr__(self): diff --git a/app/routes.py b/app/routes.py index 4d3235b..a3ff73c 100644 --- a/app/routes.py +++ b/app/routes.py @@ -7,9 +7,15 @@ def index(): return render_template('view.html', seasons=Season.query.all()) @app.route('/season//') -def season(season): +def viewSeason(season): return render_template('season.html', season=Season.query.filter_by(id=season).first_or_404()) -@app.route('/season//') -def episode(season, episode): - return render_template('episode.html', episode=Episode.query.filter_by(season_id=season, number=episode).first_or_404()) \ No newline at end of file +@app.route('/season///') +def viewEpisode(season, episode): + return render_template('episode.html', episode=Episode.query.filter_by(season_id=season, number=episode).first_or_404()) + +@app.route('/season///rebuild') +def rebuildEpisode(season, episode): + e = Episode.query.filter_by(season_id=season, number=episode).first_or_404() + e.rebuild() + return redirect(url_for('viewEpisode', season=season, episode=episode)) \ No newline at end of file diff --git a/app/templates/episode.html b/app/templates/episode.html index bbdfcf8..1280fe3 100644 --- a/app/templates/episode.html +++ b/app/templates/episode.html @@ -1,5 +1,10 @@ {% extends 'content.html' %} {% block body %} +Go to Season {{ episode.season_id }} +
+Rebuild Episode +
+
{% for section in episode.sections %} {% for quote in section.quotes %} {{ quote.speaker }}: {{ quote.text }} diff --git a/app/templates/season.html b/app/templates/season.html index ceca297..c7594e0 100644 --- a/app/templates/season.html +++ b/app/templates/season.html @@ -1,6 +1,10 @@ {% extends 'base.html' %} {% block body %} {{ super() }} + +See all Seasons +

+ Season {{ season.id }}
{% for episode in season.episodes %}