Add include_activity parameter to get_history API

This commit is contained in:
JonnyWong16 2020-10-13 16:26:35 -07:00
parent a120f52e0d
commit 7b936fd664
No known key found for this signature in database
GPG key ID: B1F1F9807184697A
2 changed files with 11 additions and 5 deletions

View file

@ -51,15 +51,18 @@ class DataFactory(object):
def __init__(self): def __init__(self):
pass pass
def get_datatables_history(self, kwargs=None, custom_where=None, grouping=None): def get_datatables_history(self, kwargs=None, custom_where=None, grouping=None, include_activity=None):
data_tables = datatables.DataTables() data_tables = datatables.DataTables()
if custom_where is None: if custom_where is None:
custon_where = [] custom_where = []
if grouping is None: if grouping is None:
grouping = plexpy.CONFIG.GROUP_HISTORY_TABLES grouping = plexpy.CONFIG.GROUP_HISTORY_TABLES
if include_activity is None:
include_activity = plexpy.CONFIG.HISTORY_TABLE_ACTIVITY
if session.get_session_user_id(): if session.get_session_user_id():
session_user_id = str(session.get_session_user_id()) session_user_id = str(session.get_session_user_id())
added = False added = False
@ -125,7 +128,7 @@ class DataFactory(object):
'NULL AS session_key' 'NULL AS session_key'
] ]
if plexpy.CONFIG.HISTORY_TABLE_ACTIVITY: if include_activity:
table_name_union = 'sessions' table_name_union = 'sessions'
# Very hacky way to match the custom where parameters for the unioned table # Very hacky way to match the custom where parameters for the unioned table
custom_where_union = [[c[0].split('.')[-1], c[1]] for c in custom_where] custom_where_union = [[c[0].split('.')[-1], c[1]] for c in custom_where]

View file

@ -1824,7 +1824,7 @@ class WebInterface(object):
@requireAuth() @requireAuth()
@sanitize_out() @sanitize_out()
@addtoapi() @addtoapi()
def get_history(self, user=None, user_id=None, grouping=None, **kwargs): def get_history(self, user=None, user_id=None, grouping=None, include_activity=None, **kwargs):
""" Get the Tautulli history. """ Get the Tautulli history.
``` ```
@ -1833,6 +1833,7 @@ class WebInterface(object):
Optional parameters: Optional parameters:
grouping (int): 0 or 1 grouping (int): 0 or 1
include_activity (int): 0 or 1
user (str): "Jon Snow" user (str): "Jon Snow"
user_id (int): 133788 user_id (int): 133788
rating_key (int): 4348 rating_key (int): 4348
@ -1921,6 +1922,7 @@ class WebInterface(object):
kwargs['json_data'] = build_datatables_json(kwargs, dt_columns, "date") kwargs['json_data'] = build_datatables_json(kwargs, dt_columns, "date")
grouping = helpers.bool_true(grouping, return_none=True) grouping = helpers.bool_true(grouping, return_none=True)
include_activity = helpers.bool_true(include_activity, return_none=True)
custom_where = [] custom_where = []
if user_id: if user_id:
@ -1961,7 +1963,8 @@ class WebInterface(object):
custom_where.append(['session_history_metadata.guid', 'LIKE ' + guid + '%']) # SQLite LIKE wildcard custom_where.append(['session_history_metadata.guid', 'LIKE ' + guid + '%']) # SQLite LIKE wildcard
data_factory = datafactory.DataFactory() data_factory = datafactory.DataFactory()
history = data_factory.get_datatables_history(kwargs=kwargs, custom_where=custom_where, grouping=grouping) history = data_factory.get_datatables_history(kwargs=kwargs, custom_where=custom_where,
grouping=grouping, include_activity=include_activity)
return history return history