Compare commits

..

9 Commits

Author SHA1 Message Date
JonnyWong16
e91ba46265 v2.1.6-beta 2018-05-09 20:26:06 -07:00
JonnyWong16
62104c95e3 Move newsletter filename setting and rename config tab 2018-05-08 19:39:27 -07:00
JonnyWong16
178bd89e7c Better init config checkboxes JS 2018-05-08 17:40:17 -07:00
JonnyWong16
365260401c Hide newsletter agent options when save only checked 2018-05-08 17:25:25 -07:00
JonnyWong16
04029bd4d3 Fix NoneType error in newsletter ID name for parameters 2018-05-08 12:56:12 -07:00
JonnyWong16
9cf1128712 Update newsletter preview note for image hosting 2018-05-08 11:22:16 -07:00
JonnyWong16
2eebce9f6c Add HTTP root to newsletter ID name note 2018-05-08 11:01:20 -07:00
JonnyWong16
b08e071b81 Note newesletter ID name and filename as optional 2018-05-08 10:59:00 -07:00
JonnyWong16
7778d84728 Add setting to specify newsletter ID name for static URLs 2018-05-08 10:54:07 -07:00
14 changed files with 197 additions and 141 deletions

View File

@@ -1,5 +1,12 @@
# Changelog # Changelog
## v2.1.6-beta (2018-05-09)
* Newsletters:
* Change: Setting to specify static URL ID name instead of using the newsletter ID number.
* Change: Reorganize newsletter config options.
## v2.1.5-beta (2018-05-07) ## v2.1.5-beta (2018-05-07)
* Newsletters: * Newsletters:

View File

@@ -4092,4 +4092,9 @@ a:hover .overlay-refresh-image:hover {
} }
a[data-tab-destination] { a[data-tab-destination] {
cursor: pointer; cursor: pointer;
}
.modal-config-section {
margin-top: 10px !important;
padding-top: 10px;
border-top: 1px solid #444;
} }

View File

@@ -1,17 +1,17 @@
function initConfigCheckbox(elem) { function initConfigCheckbox(elem, toggleElem = null, reverse = false) {
var config = $(elem).closest('div').next(); var config = toggleElem ? $(toggleElem) : $(elem).closest('div').next();
config.css('overflow', 'hidden'); config.css('overflow', 'hidden');
if ($(elem).is(":checked")) { if ($(elem).is(":checked")) {
config.show(); config.toggle(!reverse);
} else { } else {
config.hide(); config.toggle(reverse);
} }
$(elem).click(function () { $(elem).click(function () {
var config = $(this).closest('div').next(); var config = toggleElem ? $(toggleElem) : $(this).closest('div').next();
if ($(this).is(":checked")) { if ($(this).is(":checked")) {
config.slideDown(); config.slideToggleBool(!reverse);
} else { } else {
config.slideUp(); config.slideToggleBool(reverse);
} }
}); });
} }
@@ -449,4 +449,8 @@ function forceMinMax(elem) {
function capitalizeFirstLetter(string) { function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1); return string.charAt(0).toUpperCase() + string.slice(1);
}
$.fn.slideToggleBool = function(bool, options) {
return bool ? $(this).slideDown(options) : $(this).slideUp(options);
} }

View File

@@ -20,7 +20,7 @@
<div class="row"> <div class="row">
<ul class="nav nav-tabs list-unstyled" role="tablist"> <ul class="nav nav-tabs list-unstyled" role="tablist">
<li role="presentation" class="active"><a href="#tabs-newsletter_config" aria-controls="tabs-newsletter_config" role="tab" data-toggle="tab">Configuration</a></li> <li role="presentation" class="active"><a href="#tabs-newsletter_config" aria-controls="tabs-newsletter_config" role="tab" data-toggle="tab">Configuration</a></li>
<li role="presentation"><a href="#tabs-newsletter_agent" aria-controls="tabs-newsletter_agent" role="tab" data-toggle="tab">Notification Agent</a></li> <li role="presentation"><a href="#tabs-newsletter_saving_sending" aria-controls="tabs-newsletter_saving_sending" role="tab" data-toggle="tab">Saving & Sending</a></li>
<li role="presentation"><a href="#tabs-newsletter_text" aria-controls="tabs-newsletter_text" role="tab" data-toggle="tab">Newsletter Text</a></li> <li role="presentation"><a href="#tabs-newsletter_text" aria-controls="tabs-newsletter_text" role="tab" data-toggle="tab">Newsletter Text</a></li>
<li role="presentation"><a href="#tabs-test_newsletter" aria-controls="tabs-test_newsletter" role="tab" data-toggle="tab">Test Newsletter</a></li> <li role="presentation"><a href="#tabs-test_newsletter" aria-controls="tabs-test_newsletter" role="tab" data-toggle="tab">Test Newsletter</a></li>
</ul> </ul>
@@ -70,7 +70,7 @@
<p class="help-block">Set the time frame to include in the newsletter. Note: Days uses calendar days (i.e. since midnight).</p> <p class="help-block">Set the time frame to include in the newsletter. Note: Days uses calendar days (i.e. since midnight).</p>
</div> </div>
</div> </div>
<div class="col-md-12" style="padding-top: 10px; border-top: 1px solid #444;"> <div class="col-md-12 modal-config-section">
<input type="hidden" id="newsletter_id" name="newsletter_id" value="${newsletter['id']}" /> <input type="hidden" id="newsletter_id" name="newsletter_id" value="${newsletter['id']}" />
<input type="hidden" id="agent_id" name="agent_id" value="${newsletter['agent_id']}" /> <input type="hidden" id="agent_id" name="agent_id" value="${newsletter['agent_id']}" />
% for item in newsletter['config_options']: % for item in newsletter['config_options']:
@@ -165,15 +165,15 @@
% endif % endif
% endfor % endfor
</div> </div>
<div class="col-md-12" style="margin-top: 10px; padding-top: 10px; border-top: 1px solid #444;"> <div class="col-md-12 modal-config-section">
<div class="form-group"> <div class="form-group">
<label for="newsletter_config_filename">Filename</label> <label for="id_name">Unique ID Name</label>
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
<input type="text" class="form-control" id="newsletter_config_filename" name="newsletter_config_filename" value="${newsletter['config']['filename']}" size="30"> <input type="text" class="form-control" id="id_name" name="id_name" value="${newsletter['id_name']}" size="30">
</div> </div>
</div> </div>
<p class="help-block">The filename to use when saving the newsletter (ending with <span class="inline-pre">.html</span>). You may use any of the <a href="#newsletter-text-sub-modal" data-toggle="modal">newsletter text parameters</a>. Leave blank for default.</p> <p class="help-block">Optional: Enter a unique ID name to create a static URL to the last sent scheduled newsletter at <span class="inline-pre">${http_root}newsletter/id/&lt;id_name&gt;</span>. Only letters (a-z), numbers (0-9), underscores (_) and hyphens (-) are allowed. Leave blank to disable.</p>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="friendly_name">Description</label> <label for="friendly_name">Description</label>
@@ -187,16 +187,29 @@
</div> </div>
</div> </div>
</div> </div>
<div role="tabpanel" class="tab-pane" id="tabs-newsletter_agent"> <div role="tabpanel" class="tab-pane" id="tabs-newsletter_saving_sending">
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
<label>Saving</label>
<div class="checkbox"> <div class="checkbox">
<label> <label>
<input type="checkbox" id="newsletter_config_save_only_checkbox" data-id="newsletter_config_save_only" class="checkboxes" value="1" ${checked(newsletter['config']['save_only'])}> Save Newsletter File Only <input type="checkbox" id="newsletter_config_save_only_checkbox" data-id="newsletter_config_save_only" class="checkboxes" value="1" ${checked(newsletter['config']['save_only'])}> Save HTML File Only
</label> </label>
<p class="help-block">Enable to save the newsletter file without sending it to any notification agent.</p> <p class="help-block">Enable to save the newsletter HTML file without sending it to any notification agent.</p>
<input type="hidden" id="newsletter_config_save_only" name="newsletter_config_save_only" value="${newsletter['config']['save_only']}"> <input type="hidden" id="newsletter_config_save_only" name="newsletter_config_save_only" value="${newsletter['config']['save_only']}">
</div> </div>
<div class="form-group">
<label for="newsletter_config_filename">HTML File Name</label>
<div class="row">
<div class="col-md-12">
<input type="text" class="form-control" id="newsletter_config_filename" name="newsletter_config_filename" value="${newsletter['config']['filename']}" size="30">
</div>
</div>
<p class="help-block">Optional: Enter the file name to use when saving the newsletter (ending with <span class="inline-pre">.html</span>). You may use any of the <a href="#newsletter-text-sub-modal" data-toggle="modal">newsletter text parameters</a>. Leave blank for default.</p>
</div>
</div>
<div class="col-md-12 modal-config-section" id="newsletter_agent_options">
<label>Sending</label>
<div class="checkbox"> <div class="checkbox">
<label> <label>
<input type="checkbox" id="newsletter_config_formatted_checkbox" data-id="newsletter_config_formatted" class="checkboxes" value="1" ${checked(newsletter['config']['formatted'])}> Send Newsletter as an HTML Formatted Email <input type="checkbox" id="newsletter_config_formatted_checkbox" data-id="newsletter_config_formatted" class="checkboxes" value="1" ${checked(newsletter['config']['formatted'])}> Send Newsletter as an HTML Formatted Email
@@ -250,100 +263,100 @@
Note: Self-hosted newsletters must be enabled under <a data-tab-destination="tabs-notifications" data-dismiss="modal" data-target="#newsletter_self_hosted">Newsletters</a> to include a link to the newsletter. Note: Self-hosted newsletters must be enabled under <a data-tab-destination="tabs-notifications" data-dismiss="modal" data-target="#newsletter_self_hosted">Newsletters</a> to include a link to the newsletter.
</p> </p>
</div> </div>
</div> <div id="newsletter-email-config">
<div id="newsletter-email-config" class="col-md-12" style="padding-top: 10px; border-top: 1px solid #444;"> % for item in newsletter['email_config_options']:
% for item in newsletter['email_config_options']: % if item['input_type'] == 'help':
% if item['input_type'] == 'help': <div class="form-group">
<div class="form-group"> <label>${item['label']}</label>
<label>${item['label']}</label> <p class="help-block">${item['description'] | n}</p>
<p class="help-block">${item['description'] | n}</p>
</div>
% elif item['input_type'] == 'text' or item['input_type'] == 'password':
<div class="form-group">
<label for="${item['name']}">${item['label']}</label>
<div class="row">
<div class="col-md-12">
<input type="${item['input_type']}" class="form-control" id="${item['name']}" name="${item['name']}" value="${item['value']}" size="30" ${'readonly' if item.get('readonly') else ''}>
</div>
</div> </div>
<p class="help-block">${item['description'] | n}</p> % elif item['input_type'] == 'text' or item['input_type'] == 'password':
</div> <div class="form-group">
% elif item['input_type'] == 'number': <label for="${item['name']}">${item['label']}</label>
<div class="form-group"> <div class="row">
<label for="${item['name']}">${item['label']}</label> <div class="col-md-12">
<div class="row"> <input type="${item['input_type']}" class="form-control" id="${item['name']}" name="${item['name']}" value="${item['value']}" size="30" ${'readonly' if item.get('readonly') else ''}>
<div class="col-md-3"> </div>
<input type="${item['input_type']}" class="form-control" id="${item['name']}" name="${item['name']}" value="${item['value']}" size="30">
</div> </div>
<p class="help-block">${item['description'] | n}</p>
</div> </div>
<p class="help-block">${item['description'] | n}</p> % elif item['input_type'] == 'number':
</div> <div class="form-group">
% elif item['input_type'] == 'button': <label for="${item['name']}">${item['label']}</label>
<div class="form-group"> <div class="row">
<label for="${item['name']}">${item['label']}</label> <div class="col-md-3">
<div class="row"> <input type="${item['input_type']}" class="form-control" id="${item['name']}" name="${item['name']}" value="${item['value']}" size="30">
<div class="col-md-12"> </div>
<input type="button" class="btn btn-bright" id="${item['name']}" name="${item['name']}" value="${item['value']}">
</div> </div>
<p class="help-block">${item['description'] | n}</p>
</div> </div>
<p class="help-block">${item['description'] | n}</p> % elif item['input_type'] == 'button':
</div> <div class="form-group">
% elif item['input_type'] == 'checkbox' and item['name'] != 'newsletter_email_html_support': <label for="${item['name']}">${item['label']}</label>
<div class="checkbox"> <div class="row">
<label> <div class="col-md-12">
<input type="checkbox" data-id="${item['name']}" class="checkboxes" value="1" ${checked(item['value'])}> ${item['label']} <input type="button" class="btn btn-bright" id="${item['name']}" name="${item['name']}" value="${item['value']}">
</label> </div>
<p class="help-block">${item['description'] | n}</p>
<input type="hidden" id="${item['name']}" name="${item['name']}" value="${item['value']}">
</div>
% elif item['input_type'] == 'select':
<div class="form-group">
<label for="${item['name']}">${item['label']}</label>
<div class="row">
<div class="col-md-12">
<select class="form-control" id="${item['name']}" name="${item['name']}">
% for key, value in sorted(item['select_options'].iteritems()):
% if key == item['value']:
<option value="${key}" selected>${value}</option>
% else:
<option value="${key}">${value}</option>
% endif
% endfor
</select>
</div> </div>
<p class="help-block">${item['description'] | n}</p>
</div> </div>
<p class="help-block">${item['description'] | n}</p> % elif item['input_type'] == 'checkbox' and item['name'] != 'newsletter_email_html_support':
</div> <div class="checkbox">
% elif item['input_type'] == 'selectize': <label>
<div class="form-group"> <input type="checkbox" data-id="${item['name']}" class="checkboxes" value="1" ${checked(item['value'])}> ${item['label']}
<label for="${item['name']}">${item['label']}</label> </label>
<div class="row"> <p class="help-block">${item['description'] | n}</p>
<div class="col-md-12"> <input type="hidden" id="${item['name']}" name="${item['name']}" value="${item['value']}">
<select class="form-control" id="${item['name']}" name="${item['name']}"> </div>
<option value="select-all">Select All</option> % elif item['input_type'] == 'select':
<option value="remove-all">Remove All</option> <div class="form-group">
% if isinstance(item['select_options'], dict): <label for="${item['name']}">${item['label']}</label>
% for section, options in item['select_options'].iteritems(): <div class="row">
<optgroup label="${section}"> <div class="col-md-12">
% for option in sorted(options, key=lambda x: x['text'].lower()): <select class="form-control" id="${item['name']}" name="${item['name']}">
% for key, value in sorted(item['select_options'].iteritems()):
% if key == item['value']:
<option value="${key}" selected>${value}</option>
% else:
<option value="${key}">${value}</option>
% endif
% endfor
</select>
</div>
</div>
<p class="help-block">${item['description'] | n}</p>
</div>
% elif item['input_type'] == 'selectize':
<div class="form-group">
<label for="${item['name']}">${item['label']}</label>
<div class="row">
<div class="col-md-12">
<select class="form-control" id="${item['name']}" name="${item['name']}">
<option value="select-all">Select All</option>
<option value="remove-all">Remove All</option>
% if isinstance(item['select_options'], dict):
% for section, options in item['select_options'].iteritems():
<optgroup label="${section}">
% for option in sorted(options, key=lambda x: x['text'].lower()):
<option value="${option['value']}">${option['text']}</option>
% endfor
</optgroup>
% endfor
% else:
<option value="border-all"></option>
% for option in sorted(item['select_options'], key=lambda x: x['text'].lower()):
<option value="${option['value']}">${option['text']}</option> <option value="${option['value']}">${option['text']}</option>
% endfor % endfor
</optgroup> % endif
% endfor </select>
% else: </div>
<option value="border-all"></option>
% for option in sorted(item['select_options'], key=lambda x: x['text'].lower()):
<option value="${option['value']}">${option['text']}</option>
% endfor
% endif
</select>
</div> </div>
<p class="help-block">${item['description'] | n}</p>
</div> </div>
<p class="help-block">${item['description'] | n}</p> % endif
% endfor
<input type="hidden" id="newsletter_email_html_support" name="newsletter_email_html_support" value="1">
</div> </div>
% endif
% endfor
<input type="hidden" id="newsletter_email_html_support" name="newsletter_email_html_support" value="1">
</div> </div>
</div> </div>
</div> </div>
@@ -477,12 +490,23 @@
function validateFilename() { function validateFilename() {
var filename = $('#newsletter_config_filename').val(); var filename = $('#newsletter_config_filename').val();
if (filename !== '' && !(filename.endsWith('.html'))) { if (filename !== '' && !(filename.endsWith('.html'))) {
showMsg('<i class="fa fa-times"></i> Failed to save newsletter. Invalid filename.', false, true, 5000, true); showMsg('<i class="fa fa-times"></i> Failed to save newsletter. Invalid file name.', false, true, 5000, true);
return false; return false;
} else { } else {
return true; return true;
} }
} }
function validateIDName() {
var id_name = $('#id_name').val();
if (/^[a-zA-Z0-9_-]*$/.test(id_name)) {
return true;
} else {
showMsg('<i class="fa fa-times"></i> Failed to save newsletter. Invalid unique ID name.', false, true, 5000, true);
return false;
}
}
var $incl_libraries = $('#newsletter_config_incl_libraries').selectize({ var $incl_libraries = $('#newsletter_config_incl_libraries').selectize({
plugins: ['remove_button'], plugins: ['remove_button'],
maxItems: null, maxItems: null,
@@ -510,6 +534,8 @@
var incl_libraries = $incl_libraries[0].selectize; var incl_libraries = $incl_libraries[0].selectize;
incl_libraries.setValue(${json.dumps(next((c['value'] for c in newsletter['config_options'] if c['name'] == 'newsletter_config_incl_libraries'), [])) | n}); incl_libraries.setValue(${json.dumps(next((c['value'] for c in newsletter['config_options'] if c['name'] == 'newsletter_config_incl_libraries'), [])) | n});
initConfigCheckbox('#newsletter_config_save_only_checkbox', '#newsletter_agent_options', true);
function toggleEmailSelect () { function toggleEmailSelect () {
if ($('#newsletter_config_formatted_checkbox').is(':checked')) { if ($('#newsletter_config_formatted_checkbox').is(':checked')) {
$('#newsletter_body').hide(); $('#newsletter_body').hide();
@@ -668,7 +694,7 @@
if ($('#custom_cron').val() === '0'){ if ($('#custom_cron').val() === '0'){
$("#cron_value").val(cron_widget.cron('value')); $("#cron_value").val(cron_widget.cron('value'));
} }
if (validateFilename()){ if (validateFilename() && validateIDName()){
doAjaxCall('set_newsletter_config', $(this), 'tabs', true, true, saveCallback); doAjaxCall('set_newsletter_config', $(this), 'tabs', true, true, saveCallback);
} }
} }

View File

@@ -123,7 +123,7 @@
% endif % endif
% endfor % endfor
</div> </div>
<div class="col-md-12" style="margin-top: 10px; padding-top: 10px; border-top: 1px solid #444;"> <div class="col-md-12 modal-config-section">
<div class="form-group"> <div class="form-group">
<label for="friendly_name">Description</label> <label for="friendly_name">Description</label>
<div class="row"> <div class="row">

View File

@@ -969,13 +969,6 @@
Note: The <span class="inline-pre">${http_root}newsletter</span> endpoint on your domain must be publicly accessible from the internet. Note: The <span class="inline-pre">${http_root}newsletter</span> endpoint on your domain must be publicly accessible from the internet.
</p> </p>
<p class="help-block settings-warning base-url-warning">Warning: Public Tautulli domain not set under <a data-tab-destination="tabs-web_interface" data-target="#http_base_url">Web Interface</a>.</p> <p class="help-block settings-warning base-url-warning">Warning: Public Tautulli domain not set under <a data-tab-destination="tabs-web_interface" data-target="#http_base_url">Web Interface</a>.</p>
<div class="checkbox">
<label>
<input type="checkbox" id="newsletter_static_url" name="newsletter_static_url" value="1" ${config['newsletter_static_url']}> Enable Static Newsletter URL
</label>
<p class="help-block">Enable static newsletter URLs to the last sent scheduled newsletter at <span class="inline-pre">${http_root}newsletter/id/&lt;newsletter_id&gt;</span>.</p>
</div>
</div> </div>
<div class="form-group advanced-setting"> <div class="form-group advanced-setting">
@@ -1119,7 +1112,7 @@
Add a new newsletter agent, or configure an existing newsletter agent by clicking the settings icon on the right. Add a new newsletter agent, or configure an existing newsletter agent by clicking the settings icon on the right.
</p> </p>
<p class="help-block settings-warning" id="newsletter_upload_warning"> <p class="help-block settings-warning" id="newsletter_upload_warning">
Warning: <a data-tab-destination="tabs-notifications" data-target="#notify_upload_posters">Image Hosting</a> must be enabled for images to display on the newsletter.</span> Warning: The <a data-tab-destination="tabs-notifications" data-target="#notify_upload_posters">Image Hosting</a> setting must be enabled for images to display on the newsletter.</span>
</p> </p>
<br/> <br/>
<div id="plexpy-newsletters-table"> <div id="plexpy-newsletters-table">

View File

@@ -11,10 +11,10 @@
else: else:
base_url = '' base_url = ''
service = get_img_service() service = get_img_service(include_self=True)
if get_img_service(include_self=True) == 'self-hosted' and plexpy.CONFIG.HTTP_BASE_URL: if service == 'self-hosted' and plexpy.CONFIG.HTTP_BASE_URL:
base_url_image = plexpy.CONFIG.HTTP_BASE_URL + plexpy.HTTP_ROOT + 'newsletter/image/' base_url_image = plexpy.CONFIG.HTTP_BASE_URL + plexpy.HTTP_ROOT + 'newsletter/image/'
elif service and preview: elif service and service != 'self-hosted' and preview:
base_url_image = 'newsletter/image/' base_url_image = 'newsletter/image/'
else: else:
base_url_image = '' base_url_image = ''
@@ -624,7 +624,9 @@
</head> </head>
<body class="" style="font-family: 'Open Sans', Helvetica, Arial, sans-serif;-webkit-font-smoothing: antialiased;font-size: 14px;line-height: 1.4;margin: 0;padding: 0;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%;"> <body class="" style="font-family: 'Open Sans', Helvetica, Arial, sans-serif;-webkit-font-smoothing: antialiased;font-size: 14px;line-height: 1.4;margin: 0;padding: 0;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%;">
% if preview and service: % if preview and service:
<div class="local-preview-note" style="text-align: center;padding-top: 10px;"><p style="font-family: 'Open Sans', Helvetica, Arial, sans-serif;font-weight: 400;margin: 0;color: #282A2D;font-size: 12px;">Note: Local preview only - images have not been uploaded to ${service.capitalize()}</p></div> <!-- IGNORE SAVE --> <div class="local-preview-note" style="text-align: center;padding-top: 10px;"><p style="font-family: 'Open Sans', Helvetica, Arial, sans-serif;font-weight: 400;margin: 0;color: #282A2D;font-size: 12px;">Note: Local preview images only - images will be uploaded to ${service.capitalize()} when the newsletter is sent.</p></div> <!-- IGNORE SAVE -->
% elif preview and not service:
<div class="local-preview-note" style="text-align: center;padding-top: 10px;"><p style="font-family: 'Open Sans', Helvetica, Arial, sans-serif;font-weight: 400;margin: 0;color: #282A2D;font-size: 12px;">Warning: The Image Hosting setting must be enabled for images to display on the newsletter.</p></div> <!-- IGNORE SAVE -->
% endif % endif
<table border="0" cellpadding="0" cellspacing="0" class="body" style="border-collapse: separate;mso-table-lspace: 0pt;mso-table-rspace: 0pt;width: 100%;"> <table border="0" cellpadding="0" cellspacing="0" class="body" style="border-collapse: separate;mso-table-lspace: 0pt;mso-table-rspace: 0pt;width: 100%;">
<tr> <tr>

View File

@@ -11,10 +11,10 @@
else: else:
base_url = '' base_url = ''
service = get_img_service() service = get_img_service(include_self=True)
if get_img_service(include_self=True) == 'self-hosted' and plexpy.CONFIG.HTTP_BASE_URL: if service == 'self-hosted' and plexpy.CONFIG.HTTP_BASE_URL:
base_url_image = plexpy.CONFIG.HTTP_BASE_URL + plexpy.HTTP_ROOT + 'newsletter/image/' base_url_image = plexpy.CONFIG.HTTP_BASE_URL + plexpy.HTTP_ROOT + 'newsletter/image/'
elif service and preview: elif service and service != 'self-hosted' and preview:
base_url_image = 'newsletter/image/' base_url_image = 'newsletter/image/'
else: else:
base_url_image = '' base_url_image = ''
@@ -624,7 +624,9 @@
</head> </head>
<body class=""> <body class="">
% if preview and service: % if preview and service:
<div class="local-preview-note"><p>Note: Local preview only - images have not been uploaded to ${service.capitalize()}</p></div> <!-- IGNORE SAVE --> <div class="local-preview-note"><p>Note: Local preview images only - images will be uploaded to ${service.capitalize()} when the newsletter is sent.</p></div> <!-- IGNORE SAVE -->
% elif preview and not service:
<div class="local-preview-note"><p>Warning: The Image Hosting setting must be enabled for images to display on the newsletter.</p></div> <!-- IGNORE SAVE -->
% endif % endif
<table border="0" cellpadding="0" cellspacing="0" class="body"> <table border="0" cellpadding="0" cellspacing="0" class="body">
<tr> <tr>

View File

@@ -637,7 +637,7 @@ def dbcheck():
# newsletters table :: This table keeps record of the newsletter settings # newsletters table :: This table keeps record of the newsletter settings
c_db.execute( c_db.execute(
'CREATE TABLE IF NOT EXISTS newsletters (id INTEGER PRIMARY KEY AUTOINCREMENT, ' 'CREATE TABLE IF NOT EXISTS newsletters (id INTEGER PRIMARY KEY AUTOINCREMENT, '
'agent_id INTEGER, agent_name TEXT, agent_label TEXT, ' 'agent_id INTEGER, agent_name TEXT, agent_label TEXT, id_name TEXT NOT NULL DEFAULT "", '
'friendly_name TEXT, newsletter_config TEXT, email_config TEXT, ' 'friendly_name TEXT, newsletter_config TEXT, email_config TEXT, '
'subject TEXT, body TEXT, message TEXT, ' 'subject TEXT, body TEXT, message TEXT, '
'cron TEXT NOT NULL DEFAULT "0 0 * * 0", active INTEGER DEFAULT 0)' 'cron TEXT NOT NULL DEFAULT "0 0 * * 0", active INTEGER DEFAULT 0)'
@@ -1504,6 +1504,15 @@ def dbcheck():
'ALTER TABLE newsletter_log ADD COLUMN filename TEXT' 'ALTER TABLE newsletter_log ADD COLUMN filename TEXT'
) )
# Upgrade newsletters table from earlier versions
try:
c_db.execute('SELECT id_name FROM newsletters')
except sqlite3.OperationalError:
logger.debug(u"Altering database. Updating database table newsletters.")
c_db.execute(
'ALTER TABLE newsletters ADD COLUMN id_name TEXT NOT NULL DEFAULT ""'
)
# Upgrade library_sections table from earlier versions (remove UNIQUE constraint on section_id) # Upgrade library_sections table from earlier versions (remove UNIQUE constraint on section_id)
try: try:
result = c_db.execute('SELECT SQL FROM sqlite_master WHERE type="table" AND name="library_sections"').fetchone() result = c_db.execute('SELECT SQL FROM sqlite_master WHERE type="table" AND name="library_sections"').fetchone()

View File

@@ -527,7 +527,8 @@ NEWSLETTER_PARAMETERS = [
{'name': 'Newsletter URL', 'type': 'str', 'value': 'newsletter_url', 'description': 'The self-hosted URL to the newsletter.'}, {'name': 'Newsletter URL', 'type': 'str', 'value': 'newsletter_url', 'description': 'The self-hosted URL to the newsletter.'},
{'name': 'Newsletter Static URL', 'type': 'str', 'value': 'newsletter_static_url', 'description': 'The static self-hosted URL to the latest scheduled newsletter for the agent.'}, {'name': 'Newsletter Static URL', 'type': 'str', 'value': 'newsletter_static_url', 'description': 'The static self-hosted URL to the latest scheduled newsletter for the agent.'},
{'name': 'Newsletter UUID', 'type': 'str', 'value': 'newsletter_uuid', 'description': 'The unique identifier for the newsletter.'}, {'name': 'Newsletter UUID', 'type': 'str', 'value': 'newsletter_uuid', 'description': 'The unique identifier for the newsletter.'},
{'name': 'Newsletter ID', 'type': 'int', 'value': 'newsletter_id', 'description': 'The ID number for the newsletter agent.'}, {'name': 'Newsletter ID', 'type': 'int', 'value': 'newsletter_id', 'description': 'The unique ID number for the newsletter agent.'},
{'name': 'Newsletter ID Name', 'type': 'int', 'value': 'newsletter_id_name', 'description': 'The unique ID name for the newsletter agent.'},
] ]
}, },
{ {

View File

@@ -87,6 +87,7 @@ def notify(newsletter_id=None, notify_action=None, **kwargs):
message = newsletter_config['message'] message = newsletter_config['message']
newsletter_agent = newsletters.get_agent_class(newsletter_id=newsletter_id, newsletter_agent = newsletters.get_agent_class(newsletter_id=newsletter_id,
newsletter_id_name=newsletter_config['id_name'],
agent_id=newsletter_config['agent_id'], agent_id=newsletter_config['agent_id'],
config=newsletter_config['config'], config=newsletter_config['config'],
email_config=newsletter_config['email_config'], email_config=newsletter_config['email_config'],
@@ -152,21 +153,21 @@ def set_notify_success(newsletter_log_id):
db.upsert(table_name='newsletter_log', key_dict=keys, value_dict=values) db.upsert(table_name='newsletter_log', key_dict=keys, value_dict=values)
def get_newsletter(newsletter_uuid=None, newsletter_id=None): def get_newsletter(newsletter_uuid=None, newsletter_id_name=None):
db = database.MonitorDatabase() db = database.MonitorDatabase()
if newsletter_uuid: if newsletter_uuid:
result = db.select_single('SELECT newsletter_id, start_date, end_date, uuid, filename FROM newsletter_log ' result = db.select_single('SELECT start_date, end_date, uuid, filename FROM newsletter_log '
'WHERE uuid = ?', [newsletter_uuid]) 'WHERE uuid = ?', [newsletter_uuid])
elif newsletter_id: elif newsletter_id_name:
result = db.select_single('SELECT newsletter_id, start_date, end_date, uuid, filename FROM newsletter_log ' result = db.select_single('SELECT start_date, end_date, uuid, filename FROM newsletter_log '
'WHERE newsletter_id = ? AND notify_action != "test" ' 'JOIN newsletters ON newsletters.id = newsletter_log.newsletter_id '
'ORDER BY timestamp DESC LIMIT 1', [newsletter_id]) 'WHERE id_name = ? AND notify_action != "test" '
'ORDER BY timestamp DESC LIMIT 1', [newsletter_id_name])
else: else:
result = None result = None
if result: if result:
newsletter_id = result['newsletter_id']
newsletter_uuid = result['uuid'] newsletter_uuid = result['uuid']
start_date = result['start_date'] start_date = result['start_date']
end_date = result['end_date'] end_date = result['end_date']

View File

@@ -63,12 +63,13 @@ def available_notification_actions():
return actions return actions
def get_agent_class(newsletter_id=None, agent_id=None, config=None, email_config=None, start_date=None, end_date=None, def get_agent_class(newsletter_id=None, newsletter_id_name=None, agent_id=None, config=None, email_config=None,
subject=None, body=None, message=None): start_date=None, end_date=None, subject=None, body=None, message=None):
if str(agent_id).isdigit(): if str(agent_id).isdigit():
agent_id = int(agent_id) agent_id = int(agent_id)
kwargs = {'newsletter_id': newsletter_id, kwargs = {'newsletter_id': newsletter_id,
'newsletter_id_name': newsletter_id_name,
'config': config, 'config': config,
'email_config': email_config, 'email_config': email_config,
'start_date': start_date, 'start_date': start_date,
@@ -139,7 +140,8 @@ def get_newsletter_config(newsletter_id=None):
subject = result.pop('subject') subject = result.pop('subject')
body = result.pop('body') body = result.pop('body')
message = result.pop('message') message = result.pop('message')
newsletter_agent = get_agent_class(newsletter_id=newsletter_id, agent_id=result['agent_id'], newsletter_agent = get_agent_class(newsletter_id=newsletter_id, newsletter_id_name=result['id_name'],
agent_id=result['agent_id'],
config=config, email_config=email_config, config=config, email_config=email_config,
subject=subject, body=body, message=message) subject=subject, body=body, message=message)
except Exception as e: except Exception as e:
@@ -178,6 +180,7 @@ def add_newsletter_config(agent_id=None, **kwargs):
values = {'agent_id': agent['id'], values = {'agent_id': agent['id'],
'agent_name': agent['name'], 'agent_name': agent['name'],
'agent_label': agent['label'], 'agent_label': agent['label'],
'id_name': '',
'friendly_name': '', 'friendly_name': '',
'newsletter_config': json.dumps(agent_class.config), 'newsletter_config': json.dumps(agent_class.config),
'email_config': json.dumps(agent_class.email_config), 'email_config': json.dumps(agent_class.email_config),
@@ -225,7 +228,7 @@ def set_newsletter_config(newsletter_id=None, agent_id=None, **kwargs):
body = kwargs.pop('body') body = kwargs.pop('body')
message = kwargs.pop('message') message = kwargs.pop('message')
agent_class = get_agent_class(newsletter_id=newsletter_id, agent_id=agent['id'], agent_class = get_agent_class(agent_id=agent['id'],
config=newsletter_config, email_config=email_config, config=newsletter_config, email_config=email_config,
subject=subject, body=body, message=message) subject=subject, body=body, message=message)
@@ -233,6 +236,7 @@ def set_newsletter_config(newsletter_id=None, agent_id=None, **kwargs):
values = {'agent_id': agent['id'], values = {'agent_id': agent['id'],
'agent_name': agent['name'], 'agent_name': agent['name'],
'agent_label': agent['label'], 'agent_label': agent['label'],
'id_name': kwargs.get('id_name', ''),
'friendly_name': kwargs.get('friendly_name', ''), 'friendly_name': kwargs.get('friendly_name', ''),
'newsletter_config': json.dumps(agent_class.config), 'newsletter_config': json.dumps(agent_class.config),
'email_config': json.dumps(agent_class.email_config), 'email_config': json.dumps(agent_class.email_config),
@@ -318,13 +322,14 @@ class Newsletter(object):
_TEMPLATE_MASTER = '' _TEMPLATE_MASTER = ''
_TEMPLATE = '' _TEMPLATE = ''
def __init__(self, newsletter_id=None, config=None, email_config=None, start_date=None, end_date=None, def __init__(self, newsletter_id=None, newsletter_id_name=None, config=None, email_config=None,
subject=None, body=None, message=None): start_date=None, end_date=None, subject=None, body=None, message=None):
self.config = self.set_config(config=config, default=self._DEFAULT_CONFIG) self.config = self.set_config(config=config, default=self._DEFAULT_CONFIG)
self.email_config = self.set_config(config=email_config, default=self._DEFAULT_EMAIL_CONFIG) self.email_config = self.set_config(config=email_config, default=self._DEFAULT_EMAIL_CONFIG)
self.uuid = generate_newsletter_uuid() self.uuid = generate_newsletter_uuid()
self.newsletter_id = newsletter_id self.newsletter_id = newsletter_id
self.newsletter_id_name = newsletter_id_name or ''
self.start_date = None self.start_date = None
self.end_date = None self.end_date = None
@@ -506,9 +511,10 @@ class Newsletter(object):
'newsletter_time_frame': self.config['time_frame'], 'newsletter_time_frame': self.config['time_frame'],
'newsletter_time_frame_units': self.config['time_frame_units'], 'newsletter_time_frame_units': self.config['time_frame_units'],
'newsletter_url': base_url + self.uuid, 'newsletter_url': base_url + self.uuid,
'newsletter_static_url': base_url + 'id/' + str(self.newsletter_id), 'newsletter_static_url': base_url + 'id/' + self.newsletter_id_name,
'newsletter_uuid': self.uuid, 'newsletter_uuid': self.uuid,
'newsletter_id': self.newsletter_id 'newsletter_id': self.newsletter_id,
'newsletter_id_name': self.newsletter_id_name
} }
return parameters return parameters

View File

@@ -1,2 +1,2 @@
PLEXPY_BRANCH = "beta" PLEXPY_BRANCH = "beta"
PLEXPY_RELEASE_VERSION = "v2.1.5-beta" PLEXPY_RELEASE_VERSION = "v2.1.6-beta"

View File

@@ -2756,7 +2756,6 @@ class WebInterface(object):
"show_advanced_settings": plexpy.CONFIG.SHOW_ADVANCED_SETTINGS, "show_advanced_settings": plexpy.CONFIG.SHOW_ADVANCED_SETTINGS,
"newsletter_dir": plexpy.CONFIG.NEWSLETTER_DIR, "newsletter_dir": plexpy.CONFIG.NEWSLETTER_DIR,
"newsletter_self_hosted": checked(plexpy.CONFIG.NEWSLETTER_SELF_HOSTED), "newsletter_self_hosted": checked(plexpy.CONFIG.NEWSLETTER_SELF_HOSTED),
"newsletter_static_url": checked(plexpy.CONFIG.NEWSLETTER_STATIC_URL),
"newsletter_custom_dir": plexpy.CONFIG.NEWSLETTER_CUSTOM_DIR "newsletter_custom_dir": plexpy.CONFIG.NEWSLETTER_CUSTOM_DIR
} }
@@ -2779,7 +2778,7 @@ class WebInterface(object):
"allow_guest_access", "cache_images", "http_proxy", "http_basic_auth", "notify_concurrent_by_ip", "allow_guest_access", "cache_images", "http_proxy", "http_basic_auth", "notify_concurrent_by_ip",
"history_table_activity", "plexpy_auto_update", "history_table_activity", "plexpy_auto_update",
"themoviedb_lookup", "tvmaze_lookup", "http_plex_admin", "themoviedb_lookup", "tvmaze_lookup", "http_plex_admin",
"newsletter_self_hosted", "newsletter_static_url" "newsletter_self_hosted"
] ]
for checked_config in checked_configs: for checked_config in checked_configs:
if checked_config not in kwargs: if checked_config not in kwargs:
@@ -5666,15 +5665,15 @@ class WebInterface(object):
cherrypy.response.headers['Cache-Control'] = 'max-age=2592000' # 30 days cherrypy.response.headers['Cache-Control'] = 'max-age=2592000' # 30 days
return self.image(args[1], refresh=True) return self.image(args[1], refresh=True)
if plexpy.CONFIG.NEWSLETTER_STATIC_URL and len(args) >= 2 and args[0] == 'id': if len(args) >= 2 and args[0] == 'id':
newsletter_id = args[1] newsletter_id_name = args[1]
newsletter_uuid = None newsletter_uuid = None
else: else:
newsletter_id = None newsletter_id_name = None
newsletter_uuid = args[0] newsletter_uuid = args[0]
newsletter = newsletter_handler.get_newsletter(newsletter_uuid=newsletter_uuid, newsletter = newsletter_handler.get_newsletter(newsletter_uuid=newsletter_uuid,
newsletter_id=newsletter_id) newsletter_id_name=newsletter_id_name)
return newsletter return newsletter
@cherrypy.expose @cherrypy.expose
@@ -5694,6 +5693,7 @@ class WebInterface(object):
if newsletter: if newsletter:
newsletter_agent = newsletters.get_agent_class(newsletter_id=newsletter_id, newsletter_agent = newsletters.get_agent_class(newsletter_id=newsletter_id,
newsletter_id_name=newsletter['id_name'],
agent_id=newsletter['agent_id'], agent_id=newsletter['agent_id'],
config=newsletter['config'], config=newsletter['config'],
start_date=start_date, start_date=start_date,