From cfad775a0ab750eaac42cbac9117d70fe6269b21 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Wed, 24 Mar 2021 20:29:15 -0700 Subject: [PATCH] Move published_string to a property of the Video object. --- .../ycdl_flask/backend/endpoints/channel_endpoints.py | 7 ------- frontends/ycdl_flask/templates/channel.html | 2 +- ycdl/objects.py | 9 +++++++++ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/frontends/ycdl_flask/backend/endpoints/channel_endpoints.py b/frontends/ycdl_flask/backend/endpoints/channel_endpoints.py index 89c12b4..40c0773 100644 --- a/frontends/ycdl_flask/backend/endpoints/channel_endpoints.py +++ b/frontends/ycdl_flask/backend/endpoints/channel_endpoints.py @@ -1,4 +1,3 @@ -import datetime import flask; from flask import request import itertools import traceback @@ -57,12 +56,6 @@ def get_channel(channel_id=None, state=None): videos = list(videos) - for video in videos: - published = video.published - published = datetime.datetime.utcfromtimestamp(published) - published = published.strftime('%Y %m %d') - video._published_str = published - all_states = common.ycdldb.get_all_states() return flask.render_template( diff --git a/frontends/ycdl_flask/templates/channel.html b/frontends/ycdl_flask/templates/channel.html index 4951727..dc1346b 100644 --- a/frontends/ycdl_flask/templates/channel.html +++ b/frontends/ycdl_flask/templates/channel.html @@ -208,7 +208,7 @@ https://stackoverflow.com/a/35153397 >
- {{video._published_str}} - {{video.title}} + {{video.published_string}} - {{video.title}} ({{video.duration | seconds_to_hms}}) ({{video.views}}) {% if channel is none %} diff --git a/ycdl/objects.py b/ycdl/objects.py index 28bab5d..df2b4fe 100644 --- a/ycdl/objects.py +++ b/ycdl/objects.py @@ -1,3 +1,5 @@ +import datetime + from . import constants from . import exceptions from . import ytrss @@ -221,3 +223,10 @@ class Video(Base): if commit: self.ycdldb.commit() + + @property + def published_string(self): + published = self.published + published = datetime.datetime.utcfromtimestamp(published) + published = published.strftime('%Y-%m-%d') + return published