From 1ba241186299df50a94efd3d410a4422bdc2d6c3 Mon Sep 17 00:00:00 2001 From: James Taylor Date: Mon, 17 Jun 2019 20:47:58 -0700 Subject: Inherit from base template --- youtube/html_common.py | 109 ------------------------------------------ youtube/templates/base.html | 111 +++++++++++++++++++++++++++++++++++++++++++ youtube/templates/error.html | 25 ++++------ youtube/templates/watch.html | 30 +++--------- youtube/watch.py | 5 +- 5 files changed, 128 insertions(+), 152 deletions(-) create mode 100644 youtube/templates/base.html diff --git a/youtube/html_common.py b/youtube/html_common.py index 8e65a1f..b8ea0d6 100644 --- a/youtube/html_common.py +++ b/youtube/html_common.py @@ -104,115 +104,6 @@ medium_channel_item_template = Template(''' - -header_template = Template(''' -
- - - -
-
- - -$playlists - - - -
- Local playlists -
-
-''') -playlist_option_template = Template('''''') -def get_header(search_box_value=""): - playlists = '' - for name in local_playlist.get_playlist_names(): - playlists += playlist_option_template.substitute(name = name) - return header_template.substitute(playlists = playlists, search_box_value = html.escape(search_box_value)) - - - - - - - - - - - def badges_html(badges): return ' | '.join(map(html.escape, badges)) diff --git a/youtube/templates/base.html b/youtube/templates/base.html new file mode 100644 index 0000000..e98f972 --- /dev/null +++ b/youtube/templates/base.html @@ -0,0 +1,111 @@ + + + + + {% block page_title %}{% endblock %} + + + + + + + +
+ + +
+
+ + + {% for playlist_name in header_playlist_names %} + + {% endfor %} + + + +
+ Local playlists +
+
+
+{% block main %} +{% endblock %} +
+ + diff --git a/youtube/templates/error.html b/youtube/templates/error.html index f253807..1f33c44 100644 --- a/youtube/templates/error.html +++ b/youtube/templates/error.html @@ -1,17 +1,8 @@ - - - - - Error - - - - - - -{{ header|safe }} -
-{{ error_message }} -
- - +{% extends "base.html" %} + +{% block page_title %}Error{% endblock %} + +{% block main %} + {{ error_message }} +{% endblock %} + diff --git a/youtube/templates/watch.html b/youtube/templates/watch.html index 7e83306..f00413d 100644 --- a/youtube/templates/watch.html +++ b/youtube/templates/watch.html @@ -1,13 +1,6 @@ - - - - - {{ title }} - - - - - - - -{{ header|safe }} -
+{% endblock style %} + +{% block main %}
@@ -212,11 +203,4 @@ {{ related|safe }} -
- - - - - - - +{% endblock main %} diff --git a/youtube/watch.py b/youtube/watch.py index 48fd7e3..72268a7 100644 --- a/youtube/watch.py +++ b/youtube/watch.py @@ -1,5 +1,5 @@ from youtube import yt_app -from youtube import util, html_common, comments +from youtube import util, html_common, comments, local_playlist import settings from flask import request @@ -214,9 +214,8 @@ def get_watch_page(): 'note': yt_dl_downloader._format_note(format), }) - return flask.render_template('watch.html', - header = html_common.get_header(), + header_playlist_names = local_playlist.get_playlist_names(), uploader_channel_url = '/' + info['uploader_url'], upload_date = upload_date, views = (lambda x: '{:,}'.format(x) if x is not None else "")(info.get("view_count", None)), -- cgit v1.2.3