From e9bdbb863cbc2360ad2d5b7b55bd46151318e6b8 Mon Sep 17 00:00:00 2001 From: JonnyWong16 Date: Tue, 20 Mar 2018 11:24:12 -0700 Subject: [PATCH] Make self-hosted option global --- data/interfaces/default/settings.html | 33 +++++++----- .../newsletters/recently_added.html | 25 +++++---- .../newsletters/recently_added_master.html | 23 ++++---- plexpy/config.py | 3 +- plexpy/newsletters.py | 53 ++++++++----------- plexpy/webserve.py | 4 +- 6 files changed, 77 insertions(+), 64 deletions(-) diff --git a/data/interfaces/default/settings.html b/data/interfaces/default/settings.html index 8f2d9536..4a189582 100644 --- a/data/interfaces/default/settings.html +++ b/data/interfaces/default/settings.html @@ -989,20 +989,28 @@

Newsletters

-
- -
-
-
- - - /newsletter - +
+ +

Enable to self-host newsletters without uploading images to Imgur.

+
+
+
+ +
+
+
+ + + /newsletter + +
+
- +

Set your Tautulli base URL for self-hosted newsletters. (e.g. http://mydomain.com)

-

Set your Tautulli base URL for self-hosted newsletters. (e.g. http://mydomain.com)

@@ -1756,7 +1764,8 @@ $(document).ready(function() { initConfigCheckbox('#check_github'); initConfigCheckbox('#notify_upload_posters'); initConfigCheckbox('#monitor_pms_updates'); - + initConfigCheckbox('#newsletter_self_hosted'); + $('#menu_link_shutdown').click(function() { $('#confirm-message').text("Are you sure you want to shutdown Tautulli?"); $('#confirm-modal').modal(); diff --git a/data/interfaces/newsletters/recently_added.html b/data/interfaces/newsletters/recently_added.html index e91471ef..631a12f1 100644 --- a/data/interfaces/newsletters/recently_added.html +++ b/data/interfaces/newsletters/recently_added.html @@ -1,6 +1,11 @@ % if data: <% + import plexpy + recently_added = data['recently_added'] + base_url = '' + if self_hosted and plexpy.CONFIG.NEWSLETTER_BASE_URL: + base_url = plexpy.CONFIG.NEWSLETTER_BASE_URL + '/' %> @@ -567,7 +572,7 @@
- + @@ -601,14 +606,14 @@ % else:
% endif - % if preview: -
+ % if self_hosted: +
% else:
% endif
-
+
@@ -684,14 +689,14 @@ % else:
% endif - % if preview: -
+ % if self_hosted: +
% else:
% endif
-
+
@@ -789,14 +794,14 @@ % else:
% endif - % if preview: -
+ % if self_hosted: +
% else:
% endif
-
+
diff --git a/data/interfaces/newsletters/recently_added_master.html b/data/interfaces/newsletters/recently_added_master.html index 9f222fb9..be440475 100644 --- a/data/interfaces/newsletters/recently_added_master.html +++ b/data/interfaces/newsletters/recently_added_master.html @@ -1,6 +1,11 @@ % if data: <% + import plexpy + recently_added = data['recently_added'] + base_url = '' + if self_hosted and plexpy.CONFIG.NEWSLETTER_BASE_URL: + base_url = plexpy.CONFIG.NEWSLETTER_BASE_URL + '/' %> @@ -601,14 +606,14 @@ % else:
% endif - % if preview: -
+ % if self_hosted: +
% else:
% endif
-
+
@@ -684,14 +689,14 @@ % else:
% endif - % if preview: -
+ % if self_hosted: +
% else:
% endif
-
+
@@ -789,14 +794,14 @@ % else:
% endif - % if preview: -
+ % if self_hosted: +
% else:
% endif
-
+
diff --git a/plexpy/config.py b/plexpy/config.py index 265532c8..b4006e78 100644 --- a/plexpy/config.py +++ b/plexpy/config.py @@ -248,7 +248,6 @@ _CONFIG_DEFINITIONS = { 'HIPCHAT_ON_CONCURRENT': (int, 'Hipchat', 0), 'HIPCHAT_ON_NEWDEVICE': (int, 'Hipchat', 0), 'INTERFACE': (str, 'General', 'default'), - 'INTERFACE_NEWSLETTERS': (str, 'General', 'newsletters'), 'IP_LOGGING_ENABLE': (int, 'General', 0), 'IFTTT_KEY': (str, 'IFTTT', ''), 'IFTTT_EVENT': (str, 'IFTTT', 'tautulli'), @@ -308,7 +307,9 @@ _CONFIG_DEFINITIONS = { 'MONITOR_REMOTE_ACCESS': (int, 'Monitoring', 0), 'MONITORING_INTERVAL': (int, 'Monitoring', 60), 'MONITORING_USE_WEBSOCKET': (int, 'Monitoring', 0), + 'NEWSLETTER_TEMPLATES': (str, 'Newsletter', 'newsletters'), 'NEWSLETTER_DIR': (str, 'Newsletter', ''), + 'NEWSLETTER_SELF_HOSTED': (int, 'Newsletter', 0), 'NEWSLETTER_BASE_URL': (str, 'Newsletter', ''), 'NMA_APIKEY': (str, 'NMA', ''), 'NMA_ENABLED': (int, 'NMA', 0), diff --git a/plexpy/newsletters.py b/plexpy/newsletters.py index abaac46b..f72d7127 100644 --- a/plexpy/newsletters.py +++ b/plexpy/newsletters.py @@ -262,7 +262,7 @@ def send_newsletter(newsletter_id=None, subject=None, body=None, newsletter_log_ def serve_template(templatename, **kwargs): interface_dir = os.path.join(str(plexpy.PROG_DIR), 'data/interfaces/') - template_dir = os.path.join(str(interface_dir), plexpy.CONFIG.INTERFACE_NEWSLETTERS) + template_dir = os.path.join(str(interface_dir), plexpy.CONFIG.NEWSLETTER_TEMPLATES) _hplookup = TemplateLookup(directories=[template_dir], default_filters=['unicode', 'h']) @@ -289,8 +289,7 @@ def generate_newsletter_uuid(): class Newsletter(object): NAME = '' - _DEFAULT_CONFIG = {'last_days': 7, - 'self_hosted': 0} + _DEFAULT_CONFIG = {'last_days': 7} _DEFAULT_EMAIL_CONFIG = EMAIL().return_default_config() _DEFAULT_EMAIL_CONFIG['from_name'] = 'Tautulli Newsletter' _DEFAULT_EMAIL_CONFIG['notifier'] = 0 @@ -337,7 +336,7 @@ class Newsletter(object): self.data = {} self.newsletter = None - self.is_preview = bool(self.config['self_hosted']) + self.is_preview = False def set_config(self, config=None, default=None): return self._validate_config(config=config, default=default) @@ -372,6 +371,7 @@ class Newsletter(object): self.is_preview = True self.retrieve_data() + return {'title': self.NAME, 'parameters': self.parameters, 'data': self.data} @@ -392,17 +392,13 @@ class Newsletter(object): title=self.subject_formatted, parameters=self.parameters, data=self.data, - preview=self.is_preview + self_hosted=self.is_preview or plexpy.CONFIG.NEWSLETTER_SELF_HOSTED ) def send(self): self.newsletter = self.generate_newsletter() self._save() - - if self.is_preview: - return True - return self._send() def _save(self): @@ -498,12 +494,6 @@ class Newsletter(object): def _return_config_options(self): config_options = [ - {'label': 'Self-Hosted', - 'value': self.config['self_hosted'], - 'description': 'Self-host this newsletter.', - 'name': 'newsletter_config_self_hosted', - 'input_type': 'checkbox' - }, {'label': 'Number of Days', 'value': self.config['last_days'], 'name': 'newsletter_config_last_days', @@ -670,23 +660,24 @@ class RecentlyAdded(Newsletter): artists = recently_added.get('artist', []) albums = [a for artist in artists for a in artist['album']] - for item in movies + shows + albums: - poster_info = get_poster_info(poster_thumb=item['thumb'], - poster_key=item['rating_key'], - poster_title=item['title']) - if poster_info: - item['poster_url'] = poster_info['poster_url'] or common.ONLINE_POSTER_THUMB + if not plexpy.CONFIG.NEWSLETTER_SELF_HOSTED: + for item in movies + shows + albums: + poster_info = get_poster_info(poster_thumb=item['thumb'], + poster_key=item['rating_key'], + poster_title=item['title']) + if poster_info: + item['poster_url'] = poster_info['poster_url'] or common.ONLINE_POSTER_THUMB - art_info = get_poster_info(poster_thumb=item['art'], - poster_key=item['rating_key'], - poster_title=item['title'], - art=True, - width='500', - height='280', - opacity='25', - background='282828', - blur='3') - item['art_url'] = art_info.get('art_url', '') + art_info = get_poster_info(poster_thumb=item['art'], + poster_key=item['rating_key'], + poster_title=item['title'], + art=True, + width='500', + height='280', + opacity='25', + background='282828', + blur='3') + item['art_url'] = art_info.get('art_url', '') self.data['recently_added'] = recently_added diff --git a/plexpy/webserve.py b/plexpy/webserve.py index 72041e12..0624f613 100644 --- a/plexpy/webserve.py +++ b/plexpy/webserve.py @@ -2747,6 +2747,7 @@ class WebInterface(object): "tvmaze_lookup": checked(plexpy.CONFIG.TVMAZE_LOOKUP), "show_advanced_settings": plexpy.CONFIG.SHOW_ADVANCED_SETTINGS, "newsletter_dir": plexpy.CONFIG.NEWSLETTER_DIR, + "newsletter_self_hosted": checked(plexpy.CONFIG.NEWSLETTER_SELF_HOSTED), "newsletter_base_url": plexpy.CONFIG.NEWSLETTER_BASE_URL } @@ -2768,7 +2769,8 @@ class WebInterface(object): "monitor_pms_updates", "monitor_remote_access", "get_file_sizes", "log_blacklist", "http_hash_password", "allow_guest_access", "cache_images", "http_proxy", "http_basic_auth", "notify_concurrent_by_ip", "history_table_activity", "plexpy_auto_update", - "themoviedb_lookup", "tvmaze_lookup", "http_plex_admin" + "themoviedb_lookup", "tvmaze_lookup", "http_plex_admin", + "newsletter_self_hosted" ] for checked_config in checked_configs: if checked_config not in kwargs: