From 0e54a68e08481fde76b936074e6feaabc86dc2bc Mon Sep 17 00:00:00 2001 From: cinnaboot Date: Wed, 9 Oct 2019 08:46:40 -0400 Subject: [PATCH] add sorting options to movie_listing --- video_metadata/schema.sql | 35 ++++++++++--------- video_metadata/static/style.css | 17 ++++++--- .../templates/tmdb/list_movie_test.html | 16 ++++++--- video_metadata/views/tmdb.py | 32 +++++++++++------ 4 files changed, 65 insertions(+), 35 deletions(-) diff --git a/video_metadata/schema.sql b/video_metadata/schema.sql index 2f6241c..1334674 100644 --- a/video_metadata/schema.sql +++ b/video_metadata/schema.sql @@ -1,21 +1,4 @@ -DROP TABLE IF EXISTS movie_queries; -CREATE TABLE movie_queries( - query_id integer primary key autoincrement, - query text, - year integer -); - -DROP TABLE IF EXISTS movie_details; -CREATE TABLE movie_details( - movie_id primary key not null, - title text, - overview text, - release_date date, - original_language text, - poster_path text -); - DROP TABLE IF EXISTS movie_query_mapping; CREATE TABLE movie_query_mapping( query_id int, @@ -28,6 +11,7 @@ DROP TABLE IF EXISTS movie_paths; CREATE TABLE movie_paths( movie_id int not null, movie_path text unique not null, + add_date date, -- NOTE: date the path was mapped foreign key(movie_id) references movie_details(movie_id) ); @@ -45,6 +29,23 @@ CREATE TABLE movie_genre_mapping( foreign key(movie_id) references movie_details(movie_id) ); +DROP TABLE IF EXISTS movie_queries; +CREATE TABLE movie_queries( + query_id integer primary key autoincrement, + query text, + year integer +); + +DROP TABLE IF EXISTS movie_details; +CREATE TABLE movie_details( + movie_id primary key not null, + title text, + overview text, + release_date date, + original_language text, + poster_path text +); + DROP TABLE IF EXISTS actor_details; CREATE TABLE actor_details( actor_id integer primary key not null, diff --git a/video_metadata/static/style.css b/video_metadata/static/style.css index a5569db..884ad89 100644 --- a/video_metadata/static/style.css +++ b/video_metadata/static/style.css @@ -18,10 +18,6 @@ nav ul li a, nav ul li span, header .action { display: block; padding: 0.5rem; } input { color: #333; background-color: #eee; } input.danger { color: #cc2f2e; } .debug { background: lightgrey; padding: 1em; overflow: auto; border: 1px solid darkgrey } -.search_result { overflow: auto; max-height: 100px; max-width: 300px; margin-bottom: 1em; padding: 0.5em 1em; background: lightblue; border: 1px solid blue } -.search_result h3, .search_result ul { border: 0; padding: 0; margin: 0 } -.search_result ul { font-size: 0.75em } -.arrow_submit { width: 3em; font-weight: bold; } .content li { list-style: ' - '; } .folder { background: lightblue; } .file { background: orange; } @@ -39,3 +35,16 @@ input.danger { color: #cc2f2e; } .query_description { border: 0; padding: 0; margin: 0; } #query_close { float: right; } + +.search_result { + overflow: auto; + max-height: 100px; max-width: 300px; + border: 1px solid blue; + margin-bottom: 1em; padding: 0.5em 1em; + background: lightblue; +} +.search_result h3, .search_result ul { border: 0; padding: 0; margin: 0 } +.search_result ul { font-size: 0.75em } +.play_link { float: right; } + +.test li { list-style: none; display: inline; padding-left: 0.5em; } diff --git a/video_metadata/templates/tmdb/list_movie_test.html b/video_metadata/templates/tmdb/list_movie_test.html index c7df2ef..87d6d29 100644 --- a/video_metadata/templates/tmdb/list_movie_test.html +++ b/video_metadata/templates/tmdb/list_movie_test.html @@ -1,16 +1,24 @@ {% extends 'base.html' %} {% block header %} -

{% block title %}movie list test{% endblock %}

+

{% block title %}movie list test{% endblock %}

+ {% endblock %} {% block content %} -
+
{% for r in view_results %}
+ play

{{ r.title }}

    -
  • test link
  • Release Date: {{ r.release_date }}
  • Description:

    {{ r.overview }}

    @@ -18,5 +26,5 @@
{% endfor %} -
+
{% endblock %} diff --git a/video_metadata/views/tmdb.py b/video_metadata/views/tmdb.py index 1444e8a..473ddb7 100644 --- a/video_metadata/views/tmdb.py +++ b/video_metadata/views/tmdb.py @@ -98,17 +98,30 @@ class result_encoder(json.JSONEncoder): # flask routes @bp.route('/list_movie_test') -def list_movie_test(): +@bp.route('/list_movie_test/') +def list_movie_test(sorting = 'title'): + if sorting == 'add-date': + orderby = 'mp.add_date' + elif sorting == 'add-date-desc': + orderby = 'mp.add_date DESC' + elif sorting == 'release-date': + orderby = 'md.release_date' + elif sorting == 'release-date-desc': + orderby = 'md.release_date DESC' + else: + orderby = 'md.title' + # TODO: order by genres, unwatched folder... + conn = db.get_db() cur = conn.cursor() view_results = [] - query = '''SELECT - movie_details.*, movie_paths.movie_path + query = f'''SELECT + md.*, mp.movie_path FROM - movie_details - JOIN movie_paths ON movie_paths.movie_id=movie_details.movie_id + movie_details md + JOIN movie_paths mp ON mp.movie_id=md.movie_id ORDER BY - movie_details.title''' + {orderby}''' # TODO: should probably loop on movie_id, and add a list of movie_paths because # there can be multiple paths associated with a movie_id @@ -190,8 +203,8 @@ def create_mapping(): cur = conn.cursor() current_app.logger.debug(f'{util.getFunctionName()}, mapping path "{rel_path}" for id: {movie_id}') try: - cur.execute('INSERT INTO movie_paths(movie_id, movie_path) VALUES(?, ?)', - (movie_id, rel_path)) + cur.execute('INSERT INTO movie_paths(movie_id, movie_path, add_date) VALUES(?, ?, datetime())', + (movie_id, rel_path )) except DatabaseError as e: errors.append(str(e)) @@ -209,7 +222,7 @@ def create_mapping(): ################### # helpers -def doQueryAlgorithm(query:query_data) -> list: +def doQueryAlgorithm(query:query_data) -> dict: errors, view_results = [], [] response = response_data() @@ -400,7 +413,6 @@ def storeTMDBQueryResults(query_obj, result_list): current_app.logger.debug(f'{util.getFunctionName()}, adding query string ' f'"{query_obj.parsed_query_str}" into local cache') - #current_app.logger.debug(f'{util.getFunctionName()}, result_list:\n{result_list} ') try: cur.execute('BEGIN TRANSACTION')