From dd90f2e37595d33b527622207e9e2e50da54913b Mon Sep 17 00:00:00 2001 From: Tim Date: Fri, 17 Jul 2015 21:47:27 +0200 Subject: [PATCH] Fix broken search on history tables. Fix bug in history search which wouldn't search for full title. Fix bug where user info pages crashes if user no longer in friends list. Fix bug with query structure, mainly affected incomplete user IP list. User user id on Top user in home stats. Add missing Xbox icon. --- data/interfaces/default/history.html | 1 + data/interfaces/default/home_stats.html | 3 ++- .../default/images/platforms/xbox.png | Bin 0 -> 1223 bytes .../default/js/tables/history_table.js | 10 ++++++-- data/interfaces/default/user.html | 1 + plexpy/datafactory.py | 24 +++++++++++++----- plexpy/datatables.py | 6 ++--- 7 files changed, 32 insertions(+), 13 deletions(-) create mode 100644 data/interfaces/default/images/platforms/xbox.png diff --git a/data/interfaces/default/history.html b/data/interfaces/default/history.html index babc260a..c5e6b12c 100644 --- a/data/interfaces/default/history.html +++ b/data/interfaces/default/history.html @@ -44,6 +44,7 @@ from plexpy import helpers + diff --git a/data/interfaces/default/home_stats.html b/data/interfaces/default/home_stats.html index 310e5883..ca3ae372 100644 --- a/data/interfaces/default/home_stats.html +++ b/data/interfaces/default/home_stats.html @@ -28,6 +28,7 @@ users_watched Returns the count for the associated stat. == Only if 'stat_id' is 'top_user' == thumb Returns url of the user's gravatar. Returns '' if none exists. user Returns the username for the associated stat. +user_id Returns the user id for the associated stat. friendly_name Returns the friendly name of the user for the associated stat. == Only if 'stat_id' is 'top_platform' == @@ -112,7 +113,7 @@ DOCUMENTATION :: END

Most Active User

- +
${a['rows'][0]['friendly_name']}
diff --git a/data/interfaces/default/images/platforms/xbox.png b/data/interfaces/default/images/platforms/xbox.png new file mode 100644 index 0000000000000000000000000000000000000000..45ba510799aeda169ac335e841ffb89bbd1c456f GIT binary patch literal 1223 zcmV;&1UUPNP)Px$J5WqiMG$-tA0HnOdJqtM5FQ{N94#CXbrBsX9UUhf9wQzdDIE}b5D{|`7E%@# zRu&!~9v&ec5O)w3Qx+RC8x>j=5^53?XcG{45E?id8af&rF&rE)93CYe9wHtSXA=@` z5*sla67)KZsViXf&6BtSu8#5amE*uw57ZGm} z8AKTpYZ4eq7#TnrqG1|T0009zNkl5C!0K3}I%@Ff%j%%*_8Xy#Eud z62~3GWF~4SSKHrJvq z*2Z{*&Q5uoi6spq7r&V1Am*fw(F$#}N=sL_Rm@b9&*tZMF$U#=Nw>wNGCDMjgcMx1F!>-6hT%7)E znvEL>=VtGfO$3z))AsusY`;wPPu`rO?YB6B(H^qT_@KjQ(%Bu45X?Vx*($>=zCf2r z1aVG}S^`e16LgEVAx|^uWjf<96QkDy$XlY{I)vEK#OWf&9vyg5g=X$=zg=oXz31G-5vEb46-bX$XjA9Pz15o(gIdO6>l5O_i?*tBDf3IB>j7p8S9x98L}?@;w6hXfPFOayVh_nz0aq$Z_u-hxPWt zXd#%ZWSzsBdY?l;@fQY%l}RG7&?$$N&my>$uftZ`#VCZ)qh{V lnb9$3ilQirq9}@@{0A<8NeuY1n^ph-002ovPDHLkV1h@m*Sr7# literal 0 HcmV?d00001 diff --git a/data/interfaces/default/js/tables/history_table.js b/data/interfaces/default/js/tables/history_table.js index 8082b100..8b442f57 100644 --- a/data/interfaces/default/js/tables/history_table.js +++ b/data/interfaces/default/js/tables/history_table.js @@ -89,8 +89,8 @@ history_table_options = { }, { "targets": [5], - "data":"title", - "name":"title", + "data":"full_title", + "name":"full_title", "createdCell": function (td, cellData, rowData, row, col) { if (cellData !== '') { if (rowData['media_type'] === 'movie' || rowData['media_type'] === 'episode') { @@ -198,6 +198,12 @@ history_table_options = { "data":"video_decision", "searchable":false, "visible":false + }, + { + "targets": [16], + "data":"user_id", + "searchable":false, + "visible":false } diff --git a/data/interfaces/default/user.html b/data/interfaces/default/user.html index 9c44b57d..315081f3 100644 --- a/data/interfaces/default/user.html +++ b/data/interfaces/default/user.html @@ -198,6 +198,7 @@ from plexpy import helpers + diff --git a/plexpy/datafactory.py b/plexpy/datafactory.py index 1f4ea71a..7f7bc9c5 100644 --- a/plexpy/datafactory.py +++ b/plexpy/datafactory.py @@ -146,7 +146,7 @@ class DataFactory(object): '.user ELSE users.friendly_name END) as friendly_name', t1 + '.player as platform', t1 + '.ip_address', - t2 + '.full_title as title', + t2 + '.full_title as full_title', t1 + '.started', t1 + '.paused_counter', t1 + '.stopped', @@ -195,7 +195,7 @@ class DataFactory(object): "friendly_name": item['friendly_name'], "platform": item["platform"], "ip_address": item["ip_address"], - "title": item["title"], + "full_title": item["full_title"], "started": item["started"], "paused_counter": item["paused_counter"], "stopped": item["stopped"], @@ -259,7 +259,7 @@ class DataFactory(object): columns = ['session_history.started as last_seen', 'session_history.ip_address as ip_address', - 'COUNT(session_history.ip_address) as play_count', + 'COUNT(session_history.id) as play_count', 'session_history.player as platform', 'session_history_metadata.full_title as last_watched', 'session_history.user as user', @@ -413,9 +413,17 @@ class DataFactory(object): 'LIMIT 1' result = monitor_db.select(query, args=[user, user]) elif user_id: - query = 'SELECT user_id, username, friendly_name, email, thumb, ' \ - 'is_home_user, is_allow_sync, is_restricted FROM users WHERE user_id = ? LIMIT 1' - result = monitor_db.select(query, args=[user_id]) + query = 'SELECT user_id, username, friendly_name, email, ' \ + 'thumb, is_home_user, is_allow_sync, is_restricted ' \ + 'FROM users ' \ + 'WHERE user_id = ? ' \ + 'UNION ALL ' \ + 'SELECT user_id, user, null, null, null, null, null, null ' \ + 'FROM session_history ' \ + 'WHERE user_id = ? ' \ + 'GROUP BY user ' \ + 'LIMIT 1' + result = monitor_db.select(query, args=[user_id, user_id]) if result: for item in result: if not item['friendly_name']: @@ -540,7 +548,8 @@ class DataFactory(object): 'users.friendly_name end) as friendly_name,' \ 'COUNT(session_history.id) as total_plays, ' \ 'MAX(session_history.started) as last_watch, ' \ - 'users.thumb ' \ + 'users.thumb, ' \ + 'users.user_id ' \ 'FROM session_history ' \ 'JOIN session_history_metadata ON session_history.id = session_history_metadata.id ' \ 'LEFT OUTER JOIN users ON session_history.user_id = users.user_id ' \ @@ -560,6 +569,7 @@ class DataFactory(object): user_thumb = item[4] row = {'user': item[0], + 'user_id': item[5], 'friendly_name': item[1], 'total_plays': item[2], 'last_play': item[3], diff --git a/plexpy/datatables.py b/plexpy/datatables.py index 39ad17c2..4c821999 100644 --- a/plexpy/datatables.py +++ b/plexpy/datatables.py @@ -80,9 +80,9 @@ class DataTables(object): % (column_data['column_string'], table_name, join, group_by, where, order) else: - query = 'SELECT * FROM (SELECT * FROM (SELECT %s FROM %s %s GROUP BY %s) %s %s) %s' \ - % (column_data['column_string'], table_name, join, group_by, - where, order, custom_where) + query = 'SELECT * FROM (SELECT %s FROM %s %s %s GROUP BY %s) %s %s' \ + % (column_data['column_string'], table_name, join, custom_where, group_by, + where, order) else: if custom_where == '': query = 'SELECT %s FROM %s %s %s %s' \