mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-11 07:46:07 -07:00
Fix libraries/users table respect grouping setting
This commit is contained in:
parent
22e6d4067d
commit
1c4d01d6ec
4 changed files with 22 additions and 8 deletions
2
API.md
2
API.md
|
@ -833,6 +833,7 @@ Required parameters:
|
||||||
None
|
None
|
||||||
|
|
||||||
Optional parameters:
|
Optional parameters:
|
||||||
|
grouping (int): 0 or 1
|
||||||
order_column (str): "library_thumb", "section_name", "section_type", "count", "parent_count",
|
order_column (str): "library_thumb", "section_name", "section_type", "count", "parent_count",
|
||||||
"child_count", "last_accessed", "last_played", "plays", "duration"
|
"child_count", "last_accessed", "last_played", "plays", "duration"
|
||||||
order_dir (str): "desc" or "asc"
|
order_dir (str): "desc" or "asc"
|
||||||
|
@ -2341,6 +2342,7 @@ Required parameters:
|
||||||
None
|
None
|
||||||
|
|
||||||
Optional parameters:
|
Optional parameters:
|
||||||
|
grouping (int): 0 or 1
|
||||||
order_column (str): "user_thumb", "friendly_name", "last_seen", "ip_address", "platform",
|
order_column (str): "user_thumb", "friendly_name", "last_seen", "ip_address", "platform",
|
||||||
"player", "last_played", "plays", "duration"
|
"player", "last_played", "plays", "duration"
|
||||||
order_dir (str): "desc" or "asc"
|
order_dir (str): "desc" or "asc"
|
||||||
|
|
|
@ -239,7 +239,7 @@ class Libraries(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def get_datatables_list(self, kwargs=None):
|
def get_datatables_list(self, kwargs=None, grouping=None):
|
||||||
default_return = {'recordsFiltered': 0,
|
default_return = {'recordsFiltered': 0,
|
||||||
'recordsTotal': 0,
|
'recordsTotal': 0,
|
||||||
'draw': 0,
|
'draw': 0,
|
||||||
|
@ -250,9 +250,14 @@ class Libraries(object):
|
||||||
|
|
||||||
custom_where = [['library_sections.deleted_section', 0]]
|
custom_where = [['library_sections.deleted_section', 0]]
|
||||||
|
|
||||||
|
if grouping is None:
|
||||||
|
grouping = plexpy.CONFIG.GROUP_HISTORY_TABLES
|
||||||
|
|
||||||
if session.get_session_shared_libraries():
|
if session.get_session_shared_libraries():
|
||||||
custom_where.append(['library_sections.section_id', session.get_session_shared_libraries()])
|
custom_where.append(['library_sections.section_id', session.get_session_shared_libraries()])
|
||||||
|
|
||||||
|
group_by = 'session_history.reference_id' if grouping else 'session_history.id'
|
||||||
|
|
||||||
columns = ['library_sections.section_id',
|
columns = ['library_sections.section_id',
|
||||||
'library_sections.section_name',
|
'library_sections.section_name',
|
||||||
'library_sections.section_type',
|
'library_sections.section_type',
|
||||||
|
@ -262,7 +267,7 @@ class Libraries(object):
|
||||||
'library_sections.thumb AS library_thumb',
|
'library_sections.thumb AS library_thumb',
|
||||||
'library_sections.custom_thumb_url AS custom_thumb',
|
'library_sections.custom_thumb_url AS custom_thumb',
|
||||||
'library_sections.art',
|
'library_sections.art',
|
||||||
'COUNT(session_history.id) AS plays',
|
'COUNT(DISTINCT %s) AS plays' % group_by,
|
||||||
'SUM(CASE WHEN session_history.stopped > 0 THEN (session_history.stopped - session_history.started) \
|
'SUM(CASE WHEN session_history.stopped > 0 THEN (session_history.stopped - session_history.started) \
|
||||||
ELSE 0 END) - SUM(CASE WHEN session_history.paused_counter IS NULL THEN 0 ELSE \
|
ELSE 0 END) - SUM(CASE WHEN session_history.paused_counter IS NULL THEN 0 ELSE \
|
||||||
session_history.paused_counter END) AS duration',
|
session_history.paused_counter END) AS duration',
|
||||||
|
|
|
@ -70,7 +70,7 @@ class Users(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def get_datatables_list(self, kwargs=None):
|
def get_datatables_list(self, kwargs=None, grouping=None):
|
||||||
default_return = {'recordsFiltered': 0,
|
default_return = {'recordsFiltered': 0,
|
||||||
'recordsTotal': 0,
|
'recordsTotal': 0,
|
||||||
'draw': 0,
|
'draw': 0,
|
||||||
|
@ -81,18 +81,23 @@ class Users(object):
|
||||||
|
|
||||||
custom_where = [['users.deleted_user', 0]]
|
custom_where = [['users.deleted_user', 0]]
|
||||||
|
|
||||||
|
if grouping is None:
|
||||||
|
grouping = plexpy.CONFIG.GROUP_HISTORY_TABLES
|
||||||
|
|
||||||
if session.get_session_user_id():
|
if session.get_session_user_id():
|
||||||
custom_where.append(['users.user_id', session.get_session_user_id()])
|
custom_where.append(['users.user_id', session.get_session_user_id()])
|
||||||
|
|
||||||
if kwargs.get('user_id'):
|
if kwargs.get('user_id'):
|
||||||
custom_where.append(['users.user_id', kwargs.get('user_id')])
|
custom_where.append(['users.user_id', kwargs.get('user_id')])
|
||||||
|
|
||||||
|
group_by = 'session_history.reference_id' if grouping else 'session_history.id'
|
||||||
|
|
||||||
columns = ['users.user_id',
|
columns = ['users.user_id',
|
||||||
'(CASE WHEN users.friendly_name IS NULL OR TRIM(users.friendly_name) = "" \
|
'(CASE WHEN users.friendly_name IS NULL OR TRIM(users.friendly_name) = "" \
|
||||||
THEN users.username ELSE users.friendly_name END) AS friendly_name',
|
THEN users.username ELSE users.friendly_name END) AS friendly_name',
|
||||||
'users.thumb AS user_thumb',
|
'users.thumb AS user_thumb',
|
||||||
'users.custom_avatar_url AS custom_thumb',
|
'users.custom_avatar_url AS custom_thumb',
|
||||||
'COUNT(session_history.id) AS plays',
|
'COUNT(DISTINCT %s) AS plays' % group_by,
|
||||||
'SUM(CASE WHEN session_history.stopped > 0 THEN (session_history.stopped - session_history.started) \
|
'SUM(CASE WHEN session_history.stopped > 0 THEN (session_history.stopped - session_history.started) \
|
||||||
ELSE 0 END) - SUM(CASE WHEN session_history.paused_counter IS NULL THEN 0 ELSE \
|
ELSE 0 END) - SUM(CASE WHEN session_history.paused_counter IS NULL THEN 0 ELSE \
|
||||||
session_history.paused_counter END) AS duration',
|
session_history.paused_counter END) AS duration',
|
||||||
|
|
|
@ -353,7 +353,7 @@ class WebInterface(object):
|
||||||
@requireAuth()
|
@requireAuth()
|
||||||
@sanitize_out()
|
@sanitize_out()
|
||||||
@addtoapi("get_libraries_table")
|
@addtoapi("get_libraries_table")
|
||||||
def get_library_list(self, **kwargs):
|
def get_library_list(self, grouping=None, **kwargs):
|
||||||
""" Get the data on the Tautulli libraries table.
|
""" Get the data on the Tautulli libraries table.
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -361,6 +361,7 @@ class WebInterface(object):
|
||||||
None
|
None
|
||||||
|
|
||||||
Optional parameters:
|
Optional parameters:
|
||||||
|
grouping (int): 0 or 1
|
||||||
order_column (str): "library_thumb", "section_name", "section_type", "count", "parent_count",
|
order_column (str): "library_thumb", "section_name", "section_type", "count", "parent_count",
|
||||||
"child_count", "last_accessed", "last_played", "plays", "duration"
|
"child_count", "last_accessed", "last_played", "plays", "duration"
|
||||||
order_dir (str): "desc" or "asc"
|
order_dir (str): "desc" or "asc"
|
||||||
|
@ -423,7 +424,7 @@ class WebInterface(object):
|
||||||
kwargs['json_data'] = build_datatables_json(kwargs, dt_columns, "section_name")
|
kwargs['json_data'] = build_datatables_json(kwargs, dt_columns, "section_name")
|
||||||
|
|
||||||
library_data = libraries.Libraries()
|
library_data = libraries.Libraries()
|
||||||
library_list = library_data.get_datatables_list(kwargs=kwargs)
|
library_list = library_data.get_datatables_list(kwargs=kwargs, grouping=grouping)
|
||||||
|
|
||||||
return library_list
|
return library_list
|
||||||
|
|
||||||
|
@ -1016,7 +1017,7 @@ class WebInterface(object):
|
||||||
@requireAuth()
|
@requireAuth()
|
||||||
@sanitize_out()
|
@sanitize_out()
|
||||||
@addtoapi("get_users_table")
|
@addtoapi("get_users_table")
|
||||||
def get_user_list(self, **kwargs):
|
def get_user_list(self, grouping=None, **kwargs):
|
||||||
""" Get the data on Tautulli users table.
|
""" Get the data on Tautulli users table.
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -1024,6 +1025,7 @@ class WebInterface(object):
|
||||||
None
|
None
|
||||||
|
|
||||||
Optional parameters:
|
Optional parameters:
|
||||||
|
grouping (int): 0 or 1
|
||||||
order_column (str): "user_thumb", "friendly_name", "last_seen", "ip_address", "platform",
|
order_column (str): "user_thumb", "friendly_name", "last_seen", "ip_address", "platform",
|
||||||
"player", "last_played", "plays", "duration"
|
"player", "last_played", "plays", "duration"
|
||||||
order_dir (str): "desc" or "asc"
|
order_dir (str): "desc" or "asc"
|
||||||
|
@ -1082,7 +1084,7 @@ class WebInterface(object):
|
||||||
kwargs['json_data'] = build_datatables_json(kwargs, dt_columns, "friendly_name")
|
kwargs['json_data'] = build_datatables_json(kwargs, dt_columns, "friendly_name")
|
||||||
|
|
||||||
user_data = users.Users()
|
user_data = users.Users()
|
||||||
user_list = user_data.get_datatables_list(kwargs=kwargs)
|
user_list = user_data.get_datatables_list(kwargs=kwargs, grouping=grouping)
|
||||||
|
|
||||||
return user_list
|
return user_list
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue