2018-12-09 23:15:10 +00:00
|
|
|
from dynamic_preferences.registries import global_preferences_registry
|
2018-12-29 15:11:20 +00:00
|
|
|
from YtManagerApp.dynamic_preferences_registry import Initialized, YouTubeAPIKey, AllowRegistrations, SyncSchedule, SchedulerConcurrency
|
|
|
|
|
|
|
|
|
|
|
|
class AppConfig(object):
|
|
|
|
# Properties
|
|
|
|
props = {
|
|
|
|
'initialized': Initialized,
|
|
|
|
'youtube_api_key': YouTubeAPIKey,
|
|
|
|
'allow_registrations': AllowRegistrations,
|
|
|
|
'sync_schedule': SyncSchedule,
|
|
|
|
'concurrency': SchedulerConcurrency
|
|
|
|
}
|
|
|
|
|
|
|
|
# Init
|
|
|
|
def __init__(self, pref_manager):
|
|
|
|
self.__pref_manager = pref_manager
|
|
|
|
|
|
|
|
def __getattr__(self, item):
|
|
|
|
prop_class = AppConfig.props[item]
|
|
|
|
prop_full_name = prop_class.section.name + "__" + prop_class.name
|
|
|
|
return self.__pref_manager[prop_full_name]
|
|
|
|
|
|
|
|
def __setattr__(self, key, value):
|
|
|
|
if key in AppConfig.props:
|
|
|
|
prop_class = AppConfig.props[key]
|
|
|
|
prop_full_name = prop_class.section.name + "__" + prop_class.name
|
|
|
|
self.__pref_manager[prop_full_name] = value
|
|
|
|
else:
|
|
|
|
super().__setattr__(key, value)
|
|
|
|
|
2018-12-29 21:16:04 +00:00
|
|
|
def for_sub(self, subscription, pref: str):
|
|
|
|
value = getattr(subscription, pref)
|
|
|
|
if value is None:
|
|
|
|
value = subscription.user.preferences[pref]
|
|
|
|
|
|
|
|
return value
|
|
|
|
|
2018-12-09 23:15:10 +00:00
|
|
|
|
|
|
|
global_prefs = global_preferences_registry.manager()
|
2018-12-29 15:11:20 +00:00
|
|
|
appconfig = AppConfig(global_prefs)
|