mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-06 05:01:14 -07:00
Allow sort on duration column in history.
Minor code clean-up
This commit is contained in:
parent
f0864d3531
commit
7dbaf46408
2 changed files with 41 additions and 34 deletions
|
@ -36,7 +36,7 @@
|
||||||
<th align='left' id="started"><i class='fa fa-sort'></i> Started</th>
|
<th align='left' id="started"><i class='fa fa-sort'></i> Started</th>
|
||||||
<th align='left' id="paused"><i class='fa fa-sort'></i> Paused</th>
|
<th align='left' id="paused"><i class='fa fa-sort'></i> Paused</th>
|
||||||
<th align='left' id="stopped"><i class='fa fa-sort'></i> Stopped</th>
|
<th align='left' id="stopped"><i class='fa fa-sort'></i> Stopped</th>
|
||||||
<th align='left' id="duration"> Duration</th>
|
<th align='left' id="duration"><i class='fa fa-sort'></i> Duration</th>
|
||||||
<th align='left' id="percent_complete"> Completed</th>
|
<th align='left' id="percent_complete"> Completed</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
@ -188,7 +188,6 @@
|
||||||
{
|
{
|
||||||
"targets": [9],
|
"targets": [9],
|
||||||
"data":"duration",
|
"data":"duration",
|
||||||
"orderable": false,
|
|
||||||
"render": function ( data, type, full ) {
|
"render": function ( data, type, full ) {
|
||||||
return Math.round(moment.duration(data, 'seconds').as('minutes')) + ' mins';
|
return Math.round(moment.duration(data, 'seconds').as('minutes')) + ' mins';
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# This file is part of PlexPy.
|
# This file is part of PlexPy.
|
||||||
#
|
#
|
||||||
# PlexPy is free software: you can redistribute it and/or modify
|
# PlexPy is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
@ -45,7 +45,6 @@ except ImportError:
|
||||||
|
|
||||||
|
|
||||||
def serve_template(templatename, **kwargs):
|
def serve_template(templatename, **kwargs):
|
||||||
|
|
||||||
interface_dir = os.path.join(str(plexpy.PROG_DIR), 'data/interfaces/')
|
interface_dir = os.path.join(str(plexpy.PROG_DIR), 'data/interfaces/')
|
||||||
template_dir = os.path.join(str(interface_dir), plexpy.CONFIG.INTERFACE)
|
template_dir = os.path.join(str(interface_dir), plexpy.CONFIG.INTERFACE)
|
||||||
|
|
||||||
|
@ -59,7 +58,6 @@ def serve_template(templatename, **kwargs):
|
||||||
|
|
||||||
|
|
||||||
class WebInterface(object):
|
class WebInterface(object):
|
||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
def index(self):
|
def index(self):
|
||||||
raise cherrypy.HTTPRedirect("home")
|
raise cherrypy.HTTPRedirect("home")
|
||||||
|
@ -79,11 +77,13 @@ class WebInterface(object):
|
||||||
else:
|
else:
|
||||||
time_format = 'HH:mm'
|
time_format = 'HH:mm'
|
||||||
|
|
||||||
return serve_template(templatename="history.html", title="History", date_format=date_format, time_format=time_format)
|
return serve_template(templatename="history.html", title="History", date_format=date_format,
|
||||||
|
time_format=time_format)
|
||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
def checkGithub(self):
|
def checkGithub(self):
|
||||||
from plexpy import versioncheck
|
from plexpy import versioncheck
|
||||||
|
|
||||||
versioncheck.checkGithub()
|
versioncheck.checkGithub()
|
||||||
raise cherrypy.HTTPRedirect("home")
|
raise cherrypy.HTTPRedirect("home")
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ class WebInterface(object):
|
||||||
def toggleVerbose(self):
|
def toggleVerbose(self):
|
||||||
plexpy.VERBOSE = not plexpy.VERBOSE
|
plexpy.VERBOSE = not plexpy.VERBOSE
|
||||||
logger.initLogger(console=not plexpy.QUIET,
|
logger.initLogger(console=not plexpy.QUIET,
|
||||||
log_dir=plexpy.CONFIG.LOG_DIR, verbose=plexpy.VERBOSE)
|
log_dir=plexpy.CONFIG.LOG_DIR, verbose=plexpy.VERBOSE)
|
||||||
logger.info("Verbose toggled, set to %s", plexpy.VERBOSE)
|
logger.info("Verbose toggled, set to %s", plexpy.VERBOSE)
|
||||||
logger.debug("If you read this message, debug logging is available")
|
logger.debug("If you read this message, debug logging is available")
|
||||||
raise cherrypy.HTTPRedirect("logs")
|
raise cherrypy.HTTPRedirect("logs")
|
||||||
|
@ -116,16 +116,16 @@ class WebInterface(object):
|
||||||
order_dir = "desc"
|
order_dir = "desc"
|
||||||
|
|
||||||
if 'order[0][dir]' in kwargs:
|
if 'order[0][dir]' in kwargs:
|
||||||
order_dir = kwargs.get('order[0][dir]',"desc")
|
order_dir = kwargs.get('order[0][dir]', "desc")
|
||||||
|
|
||||||
if 'order[0][column]' in kwargs:
|
if 'order[0][column]' in kwargs:
|
||||||
order_column = kwargs.get('order[0][column]',"0")
|
order_column = kwargs.get('order[0][column]', "0")
|
||||||
|
|
||||||
if 'search[value]' in kwargs:
|
if 'search[value]' in kwargs:
|
||||||
search_value = kwargs.get('search[value]',"")
|
search_value = kwargs.get('search[value]', "")
|
||||||
|
|
||||||
if 'search[regex]' in kwargs:
|
if 'search[regex]' in kwargs:
|
||||||
search_regex = kwargs.get('search[regex]',"")
|
search_regex = kwargs.get('search[regex]', "")
|
||||||
|
|
||||||
filtered = []
|
filtered = []
|
||||||
if search_value == "":
|
if search_value == "":
|
||||||
|
@ -158,7 +158,8 @@ class WebInterface(object):
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
def config(self):
|
def config(self):
|
||||||
interface_dir = os.path.join(plexpy.PROG_DIR, 'data/interfaces/')
|
interface_dir = os.path.join(plexpy.PROG_DIR, 'data/interfaces/')
|
||||||
interface_list = [name for name in os.listdir(interface_dir) if os.path.isdir(os.path.join(interface_dir, name))]
|
interface_list = [name for name in os.listdir(interface_dir) if
|
||||||
|
os.path.isdir(os.path.join(interface_dir, name))]
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
"http_host": plexpy.CONFIG.HTTP_HOST,
|
"http_host": plexpy.CONFIG.HTTP_HOST,
|
||||||
|
@ -290,16 +291,16 @@ class WebInterface(object):
|
||||||
order_dir = "desc"
|
order_dir = "desc"
|
||||||
|
|
||||||
if 'order[0][dir]' in kwargs:
|
if 'order[0][dir]' in kwargs:
|
||||||
order_dir = kwargs.get('order[0][dir]',"desc")
|
order_dir = kwargs.get('order[0][dir]', "desc")
|
||||||
|
|
||||||
if 'order[0][column]' in kwargs:
|
if 'order[0][column]' in kwargs:
|
||||||
order_column = kwargs.get('order[0][column]',"1")
|
order_column = kwargs.get('order[0][column]', "1")
|
||||||
|
|
||||||
if 'search[value]' in kwargs:
|
if 'search[value]' in kwargs:
|
||||||
search_value = kwargs.get('search[value]',"")
|
search_value = kwargs.get('search[value]', "")
|
||||||
|
|
||||||
if 'search[regex]' in kwargs:
|
if 'search[regex]' in kwargs:
|
||||||
search_regex = kwargs.get('search[regex]',"")
|
search_regex = kwargs.get('search[regex]', "")
|
||||||
|
|
||||||
myDB = db.DBConnection()
|
myDB = db.DBConnection()
|
||||||
db_table = db.DBConnection().get_history_table_name()
|
db_table = db.DBConnection().get_history_table_name()
|
||||||
|
@ -321,15 +322,23 @@ class WebInterface(object):
|
||||||
elif order_column == '8':
|
elif order_column == '8':
|
||||||
sortcolumn = 'stopped'
|
sortcolumn = 'stopped'
|
||||||
elif order_column == '9':
|
elif order_column == '9':
|
||||||
sortbyhavepercent = True
|
sortcolumn = 'duration'
|
||||||
|
|
||||||
if search_value == "":
|
if search_value == "":
|
||||||
query = 'SELECT * from %s order by %s COLLATE NOCASE %s' % (db_table, sortcolumn, order_dir)
|
query = 'SELECT id, time, user, platform, ip_address, title, time, paused_counter, stopped, xml, \
|
||||||
|
round((julianday(datetime(stopped, "unixepoch", "localtime")) - \
|
||||||
|
julianday(datetime(time, "unixepoch", "localtime"))) * 86400) - \
|
||||||
|
(case when paused_counter is null then 0 else paused_counter end) as duration \
|
||||||
|
from %s order by %s COLLATE NOCASE %s' % (db_table, sortcolumn, order_dir)
|
||||||
filtered = myDB.select(query)
|
filtered = myDB.select(query)
|
||||||
totalcount = len(filtered)
|
totalcount = len(filtered)
|
||||||
else:
|
else:
|
||||||
query = 'SELECT * from ' + db_table + ' WHERE user LIKE "%' + search_value + \
|
query = 'SELECT id, time, user, platform, ip_address, title, time, paused_counter, stopped, xml, \
|
||||||
'%" OR title LIKE "%' + search_value + '%"' + 'ORDER BY %s COLLATE NOCASE %s' % (sortcolumn, order_dir)
|
round((julianday(datetime(stopped, "unixepoch", "localtime")) - \
|
||||||
|
julianday(datetime(time, "unixepoch", "localtime"))) * 86400) - \
|
||||||
|
(case when paused_counter is null then 0 else paused_counter end) as duration \
|
||||||
|
from ' + db_table + ' WHERE user LIKE "%' + search_value + '%" OR title LIKE "%' + search_value \
|
||||||
|
+ '%"' + 'ORDER BY %s COLLATE NOCASE %s' % (sortcolumn, order_dir)
|
||||||
filtered = myDB.select(query)
|
filtered = myDB.select(query)
|
||||||
totalcount = myDB.select('SELECT COUNT(*) from processed')[0][0]
|
totalcount = myDB.select('SELECT COUNT(*) from processed')[0][0]
|
||||||
|
|
||||||
|
@ -337,16 +346,16 @@ class WebInterface(object):
|
||||||
rows = []
|
rows = []
|
||||||
for item in history:
|
for item in history:
|
||||||
row = {"id": item['id'],
|
row = {"id": item['id'],
|
||||||
"date": item['time'],
|
"date": item['time'],
|
||||||
"user": item["user"],
|
"user": item["user"],
|
||||||
"platform": item["platform"],
|
"platform": item["platform"],
|
||||||
"ip_address": item["ip_address"],
|
"ip_address": item["ip_address"],
|
||||||
"title": item["title"],
|
"title": item["title"],
|
||||||
"started": item["time"],
|
"started": item["time"],
|
||||||
"paused": item["paused_counter"],
|
"paused": item["paused_counter"],
|
||||||
"stopped": item["stopped"],
|
"stopped": item["stopped"],
|
||||||
"duration": "",
|
"duration": item["duration"],
|
||||||
"percent_complete": 0,
|
"percent_complete": 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
if item['paused_counter'] > 0:
|
if item['paused_counter'] > 0:
|
||||||
|
@ -364,8 +373,6 @@ class WebInterface(object):
|
||||||
else:
|
else:
|
||||||
paused_counter = 0
|
paused_counter = 0
|
||||||
|
|
||||||
row['duration'] = stopped - item['time'] + paused_counter
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
xml_parse = minidom.parseString(helpers.latinToAscii(item['xml']))
|
xml_parse = minidom.parseString(helpers.latinToAscii(item['xml']))
|
||||||
except IOError, e:
|
except IOError, e:
|
||||||
|
@ -380,7 +387,7 @@ class WebInterface(object):
|
||||||
view_offset = helpers.cast_to_float(s.getAttribute('viewOffset'))
|
view_offset = helpers.cast_to_float(s.getAttribute('viewOffset'))
|
||||||
duration = helpers.cast_to_float(s.getAttribute('duration'))
|
duration = helpers.cast_to_float(s.getAttribute('duration'))
|
||||||
if duration > 0:
|
if duration > 0:
|
||||||
row['percent_complete'] = (view_offset / duration)*100
|
row['percent_complete'] = (view_offset / duration) * 100
|
||||||
else:
|
else:
|
||||||
row['percent_complete'] = 0
|
row['percent_complete'] = 0
|
||||||
|
|
||||||
|
@ -389,7 +396,7 @@ class WebInterface(object):
|
||||||
dict = {'recordsFiltered': len(filtered),
|
dict = {'recordsFiltered': len(filtered),
|
||||||
'recordsTotal': totalcount,
|
'recordsTotal': totalcount,
|
||||||
'data': rows,
|
'data': rows,
|
||||||
}
|
}
|
||||||
s = json.dumps(dict)
|
s = json.dumps(dict)
|
||||||
cherrypy.response.headers['Content-type'] = 'application/json'
|
cherrypy.response.headers['Content-type'] = 'application/json'
|
||||||
return s
|
return s
|
||||||
|
@ -469,6 +476,7 @@ class WebInterface(object):
|
||||||
def osxnotifyregister(self, app):
|
def osxnotifyregister(self, app):
|
||||||
cherrypy.response.headers['Cache-Control'] = "max-age=0,no-cache,no-store"
|
cherrypy.response.headers['Cache-Control'] = "max-age=0,no-cache,no-store"
|
||||||
from osxnotify import registerapp as osxnotify
|
from osxnotify import registerapp as osxnotify
|
||||||
|
|
||||||
result, msg = osxnotify.registerapp(app)
|
result, msg = osxnotify.registerapp(app)
|
||||||
if result:
|
if result:
|
||||||
osx_notify = notifiers.OSX_NOTIFY()
|
osx_notify = notifiers.OSX_NOTIFY()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue