Change home cards config to list type

This commit is contained in:
Jonathan Wong
2015-12-06 23:38:41 -08:00
parent 8f367d140f
commit 8ba68dcfcf
9 changed files with 81 additions and 37 deletions

View File

@@ -260,8 +260,6 @@ def initialize_scheduler():
Start the scheduled background tasks. Re-schedule if interval settings changed.
"""
with SCHED_LOCK:
# Check if scheduler should be started
@@ -435,7 +433,7 @@ def dbcheck():
'CREATE TABLE IF NOT EXISTS notify_log (id INTEGER PRIMARY KEY AUTOINCREMENT, '
'session_key INTEGER, rating_key INTEGER, user_id INTEGER, user TEXT, '
'agent_id INTEGER, agent_name TEXT, on_play INTEGER, on_stop INTEGER, on_watched INTEGER, '
'on_pause INTEGER, on_resume INTEGER, on_buffer INTEGER)'
'on_pause INTEGER, on_resume INTEGER, on_buffer INTEGER, on_created INTEGER)'
)
# library_sections table :: This table keeps record of the servers library sections

View File

@@ -118,12 +118,12 @@ _CONFIG_DEFINITIONS = {
'GROWL_ON_INTDOWN': (int, 'Growl', 0),
'GROWL_ON_EXTUP': (int, 'Growl', 0),
'GROWL_ON_INTUP': (int, 'Growl', 0),
'HOME_LIBRARY_CARDS': (str, 'General', 'library_statistics_first'),
'HOME_LIBRARY_CARDS': (list, 'General', ['first_run']),
'HOME_STATS_LENGTH': (int, 'General', 30),
'HOME_STATS_TYPE': (int, 'General', 0),
'HOME_STATS_COUNT': (int, 'General', 5),
'HOME_STATS_CARDS': (str, 'General', 'watch_statistics, top_tv, popular_tv, top_movies, popular_movies, ' \
'top_music, popular_music, last_watched, top_users, top_platforms, most_concurrent'),
'HOME_STATS_CARDS': (list, 'General', ['top_tv', 'popular_tv', 'top_movies', 'popular_movies', 'top_music', \
'popular_music', 'last_watched', 'top_users', 'top_platforms', 'most_concurrent']),
'HTTPS_CERT': (str, 'General', ''),
'HTTPS_KEY': (str, 'General', ''),
'HTTP_HOST': (str, 'General', '0.0.0.0'),
@@ -508,3 +508,17 @@ class Config(object):
self.MOVIE_LOGGING_ENABLE = 0
self.TV_LOGGING_ENABLE = 0
self.CONFIG_VERSION = '1'
if self.CONFIG_VERSION == '1':
# Change home_stats_cards to list
if self.HOME_STATS_CARDS:
home_stats_cards = ''.join(self.HOME_STATS_CARDS).split(', ')
if 'watch_statistics' in home_stats_cards:
home_stats_cards.remove('watch_statistics')
self.HOME_STATS_CARDS = home_stats_cards
# Change home_library_cards to list
if self.HOME_LIBRARY_CARDS:
home_library_cards = ''.join(self.HOME_LIBRARY_CARDS).split(', ')
if 'library_statistics' in home_library_cards:
home_library_cards.remove('library_statistics')
self.HOME_LIBRARY_CARDS = home_library_cards
self.CONFIG_VERSION = '2'

View File

@@ -158,7 +158,7 @@ class DataFactory(object):
return dict
def get_home_stats(self, grouping=0, time_range='30', stats_type=0, stats_count='5', stats_cards='', notify_watched_percent='85'):
def get_home_stats(self, grouping=0, time_range='30', stats_type=0, stats_count='5', stats_cards=[], notify_watched_percent='85'):
monitor_db = database.MonitorDatabase()
group_by = 'session_history.reference_id' if grouping else 'session_history.id'
@@ -654,7 +654,7 @@ class DataFactory(object):
return home_stats
def get_library_stats(self, library_cards=''):
def get_library_stats(self, library_cards=[]):
monitor_db = database.MonitorDatabase()
library_stats = []
@@ -1219,6 +1219,26 @@ class DataFactory(object):
return True
def get_library_sections(self):
monitor_db = database.MonitorDatabase()
try:
query = 'SELECT section_id, section_name FROM library_sections'
result = monitor_db.select(query=query)
except:
logger.warn("Unable to execute database query for get_library_sections.")
return None
libraries = []
for item in result:
library = {'section_id': item['section_id'],
'section_name': item['section_name']
}
libraries.append(library)
return libraries
def update_library_sections(self):
from plexpy import pmsconnect

View File

@@ -68,6 +68,12 @@ def refresh_libraries():
monitor_db.upsert('library_sections', key_dict=section_keys, value_dict=section_values)
cards.append(section['key'])
if populate_cards:
plexpy.CONFIG.__setattr__('HOME_LIBRARY_CARDS', cards)
plexpy.CONFIG.write()
logger.info("Libraries list refreshed.")
else:
logger.warn("Unable to refresh libraries list.")

View File

@@ -80,7 +80,7 @@ class WebInterface(object):
config = {
"launch_browser": checked(plexpy.CONFIG.LAUNCH_BROWSER),
"refresh_users_on_startup": checked(plexpy.CONFIG.REFRESH_USERS_ON_STARTUP),
"refresh_librareis_on_startup": checked(plexpy.CONFIG.REFRESH_LIBRARIES_ON_STARTUP),
"refresh_libraries_on_startup": checked(plexpy.CONFIG.REFRESH_LIBRARIES_ON_STARTUP),
"pms_identifier": plexpy.CONFIG.PMS_IDENTIFIER,
"pms_ip": plexpy.CONFIG.PMS_IP,
"pms_is_remote": checked(plexpy.CONFIG.PMS_IS_REMOTE),
@@ -133,7 +133,7 @@ class WebInterface(object):
time_range = plexpy.CONFIG.HOME_STATS_LENGTH
stats_type = plexpy.CONFIG.HOME_STATS_TYPE
stats_count = plexpy.CONFIG.HOME_STATS_COUNT
stats_cards = plexpy.CONFIG.HOME_STATS_CARDS.split(', ')
stats_cards = plexpy.CONFIG.HOME_STATS_CARDS
notify_watched_percent = plexpy.CONFIG.NOTIFY_WATCHED_PERCENT
stats_data = data_factory.get_home_stats(grouping=grouping,
@@ -149,7 +149,7 @@ class WebInterface(object):
def library_stats(self, **kwargs):
data_factory = datafactory.DataFactory()
library_cards = plexpy.CONFIG.HOME_LIBRARY_CARDS.split(', ')
library_cards = plexpy.CONFIG.HOME_LIBRARY_CARDS
stats_data = data_factory.get_library_stats(library_cards=library_cards)
@@ -476,13 +476,13 @@ class WebInterface(object):
"home_stats_length": plexpy.CONFIG.HOME_STATS_LENGTH,
"home_stats_type": checked(plexpy.CONFIG.HOME_STATS_TYPE),
"home_stats_count": plexpy.CONFIG.HOME_STATS_COUNT,
"home_stats_cards": plexpy.CONFIG.HOME_STATS_CARDS,
"home_library_cards": plexpy.CONFIG.HOME_LIBRARY_CARDS,
"home_stats_cards": json.dumps(plexpy.CONFIG.HOME_STATS_CARDS),
"home_library_cards": json.dumps(plexpy.CONFIG.HOME_LIBRARY_CARDS),
"buffer_threshold": plexpy.CONFIG.BUFFER_THRESHOLD,
"buffer_wait": plexpy.CONFIG.BUFFER_WAIT,
"group_history_tables": checked(plexpy.CONFIG.GROUP_HISTORY_TABLES)
}
return serve_template(templatename="settings.html", title="Settings", config=config)
@cherrypy.expose
@@ -544,13 +544,19 @@ class WebInterface(object):
refresh_libraries = True
refresh_users = True
if 'home_stats_cards' in kwargs:
if kwargs['home_stats_cards'] != 'watch_statistics':
kwargs['home_stats_cards'] = ', '.join(kwargs['home_stats_cards'])
if 'home_stats_cards' not in kwargs:
kwargs['home_stats_cards'] = []
elif kwargs['home_stats_cards'] == 'first_run_wizard':
kwargs['home_stats_cards'] = plexpy.CONFIG.HOME_STATS_CARDS
elif type(kwargs['home_stats_cards']) != list:
kwargs['home_stats_cards'] = [kwargs['home_stats_cards']]
if 'home_library_cards' in kwargs:
if kwargs['home_library_cards'] != 'library_statistics':
kwargs['home_library_cards'] = ', '.join(kwargs['home_library_cards'])
if 'home_library_cards' not in kwargs:
kwargs['home_library_cards'] = []
elif kwargs['home_library_cards'] == 'first_run_wizard':
kwargs['home_library_cards'] = plexpy.CONFIG.HOME_LIBRARY_CARDS
elif type(kwargs['home_library_cards']) != list:
kwargs['home_library_cards'] = [kwargs['home_library_cards']]
plexpy.CONFIG.process_kwargs(kwargs)
@@ -1279,10 +1285,10 @@ class WebInterface(object):
logger.warn('Unable to retrieve data.')
@cherrypy.expose
def get_server_children(self, **kwargs):
def get_library_sections(self, **kwargs):
pms_connect = pmsconnect.PmsConnect()
result = pms_connect.get_server_children()
data_factory = datafactory.DataFactory()
result = data_factory.get_library_sections()
if result:
cherrypy.response.headers['Content-type'] = 'application/json'