mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-08-20 05:13:21 -07:00
Template the Datatables JS
Add Links to user screen Add Public IP list to user screen Add Watch history to user screen
This commit is contained in:
parent
c4504d8be0
commit
6a026d510d
12 changed files with 536 additions and 335 deletions
|
@ -75,14 +75,14 @@ class DataTables(object):
|
|||
% (column_data['column_string'], table_name, where,
|
||||
order, custom_where)
|
||||
|
||||
# logger.debug(u"Query string: %s" % query)
|
||||
|
||||
filtered = self.ssp_db.select(query)
|
||||
if search_value == '':
|
||||
totalcount = len(filtered)
|
||||
else:
|
||||
totalcount = self.ssp_db.select('SELECT COUNT(*) from %s' % table_name)[0][0]
|
||||
|
||||
# logger.debug(u"Query string: %s" % query)
|
||||
|
||||
result = filtered[start:(start + length)]
|
||||
output = {'result': result,
|
||||
'filteredCount': len(filtered),
|
||||
|
|
|
@ -14,8 +14,8 @@
|
|||
# along with PlexPy. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from plexpy import logger, helpers, request, datatables, config, db
|
||||
|
||||
from xml.dom import minidom
|
||||
|
||||
import plexpy
|
||||
import json
|
||||
|
||||
|
@ -104,6 +104,70 @@ class PlexWatch(object):
|
|||
|
||||
return dict
|
||||
|
||||
def get_user_unique_ips(self, start='', length='', kwargs=None, custom_where=''):
|
||||
data_tables = datatables.DataTables()
|
||||
|
||||
start = int(start)
|
||||
length = int(length)
|
||||
filtered = []
|
||||
totalcount = 0
|
||||
search_value = ""
|
||||
search_regex = ""
|
||||
order_column = 0
|
||||
order_dir = "desc"
|
||||
|
||||
if 'order[0][dir]' in kwargs:
|
||||
order_dir = kwargs.get('order[0][dir]', "desc")
|
||||
|
||||
if 'order[0][column]' in kwargs:
|
||||
order_column = kwargs.get('order[0][column]', 1)
|
||||
|
||||
if 'search[value]' in kwargs:
|
||||
search_value = kwargs.get('search[value]', "")
|
||||
|
||||
if 'search[regex]' in kwargs:
|
||||
search_regex = kwargs.get('search[regex]', "")
|
||||
|
||||
columns = ['time as last_seen',
|
||||
'ip_address',
|
||||
'COUNT(ip_address) as play_count',
|
||||
'platform',
|
||||
'user',
|
||||
'orig_title as last_watched'
|
||||
]
|
||||
|
||||
query = data_tables.ssp_query(table_name=self.get_user_table_name(),
|
||||
columns=columns,
|
||||
start=start,
|
||||
length=length,
|
||||
order_column=int(order_column),
|
||||
order_dir=order_dir,
|
||||
search_value=search_value,
|
||||
search_regex=search_regex,
|
||||
custom_where=custom_where,
|
||||
group_by='ip_address',
|
||||
kwargs=kwargs)
|
||||
|
||||
results = query['result']
|
||||
|
||||
rows = []
|
||||
for item in results:
|
||||
row = {"last_seen": item['last_seen'],
|
||||
"ip_address": item['ip_address'],
|
||||
"play_count": item['play_count'],
|
||||
"platform": item['platform'],
|
||||
"last_watched": item['last_watched']
|
||||
}
|
||||
|
||||
rows.append(row)
|
||||
|
||||
dict = {'recordsFiltered': query['filteredCount'],
|
||||
'recordsTotal': query['totalCount'],
|
||||
'data': rows,
|
||||
}
|
||||
|
||||
return dict
|
||||
|
||||
def get_history(self, start='', length='', kwargs=None, custom_where=''):
|
||||
data_tables = datatables.DataTables()
|
||||
|
||||
|
|
|
@ -92,11 +92,11 @@ class WebInterface(object):
|
|||
return serve_template(templatename="users.html", title="Users")
|
||||
|
||||
@cherrypy.expose
|
||||
def user(self):
|
||||
return serve_template(templatename="user.html", title="User")
|
||||
def user(self, user=None):
|
||||
return serve_template(templatename="user.html", title="User", user=user)
|
||||
|
||||
@cherrypy.expose
|
||||
def get_stream_data(self, row_id=None, user='', **kwargs):
|
||||
def get_stream_data(self, row_id=None, user=None, **kwargs):
|
||||
|
||||
plex_watch = plexwatch.PlexWatch()
|
||||
stream_data = plex_watch.get_stream_details(row_id)
|
||||
|
@ -580,4 +580,17 @@ class WebInterface(object):
|
|||
cherrypy.response.headers['Content-type'] = 'application/json'
|
||||
return result
|
||||
else:
|
||||
logger.warn('Unable to retrieve data.')
|
||||
logger.warn('Unable to retrieve data.')
|
||||
|
||||
@cherrypy.expose
|
||||
def get_user_ips(self, start=0, length=100, custom_where='', **kwargs):
|
||||
|
||||
if 'user' in kwargs:
|
||||
user = kwargs.get('user', "")
|
||||
custom_where = 'user = "%s"' % user
|
||||
|
||||
plex_watch = plexwatch.PlexWatch()
|
||||
history = plex_watch.get_user_unique_ips(start, length, kwargs, custom_where)
|
||||
|
||||
cherrypy.response.headers['Content-type'] = 'application/json'
|
||||
return json.dumps(history)
|
Loading…
Add table
Add a link
Reference in a new issue