diff --git a/data/interfaces/default/notifier_config.html b/data/interfaces/default/notifier_config.html index 16c406bc..a70fc5d4 100644 --- a/data/interfaces/default/notifier_config.html +++ b/data/interfaces/default/notifier_config.html @@ -171,7 +171,7 @@
- +

Optional: Enter custom logic to use when evaluating the conditions (e.g. {1} and ({2} or {3})). @@ -333,11 +333,11 @@ $('#notifier-config-modal').unbind('hidden.bs.modal'); // Need this for setting conditions since conditions contain the character " - $('#custom_conditions').val(${json.dumps(notifier["custom_conditions"]) | n}); + $('#custom_conditions').val(JSON.stringify(${json.dumps(notifier["custom_conditions"]) | n})); $('#condition-widget').filterer({ - parameters: ${parameters | n}, - conditions: ${notifier["custom_conditions"] | n}, + parameters: ${json.dumps(parameters) | n}, + conditions: ${json.dumps(notifier["custom_conditions"]) | n}, updateConditions: function(newConditions){ $('#custom_conditions').val(JSON.stringify(newConditions)); } diff --git a/plexpy/notification_handler.py b/plexpy/notification_handler.py index e3ead880..1bad1cd2 100644 --- a/plexpy/notification_handler.py +++ b/plexpy/notification_handler.py @@ -208,13 +208,7 @@ def notify_custom_conditions(notifier_id=None, parameters=None): notifier_config = notifiers.get_notifier_config(notifier_id=notifier_id) custom_conditions_logic = notifier_config['custom_conditions_logic'] - try: - custom_conditions = json.loads(notifier_config['custom_conditions']) or [] - except ValueError as e: - logger.error(u"Tautulli NotificationHandler :: Unable to parse custom condition: %s." % e) - logger.debug(u"Tautulli NotificationHandler :: Custom conditions json: %s " - % notifier_config['custom_conditions']) - custom_conditions = [] + custom_conditions = notifier_config['custom_conditions'] if custom_conditions_logic or any(c for c in custom_conditions if c['value']): logger.debug(u"Tautulli NotificationHandler :: Checking custom notification conditions for notifier_id %s." diff --git a/plexpy/notifiers.py b/plexpy/notifiers.py index 49141554..56aba5f4 100644 --- a/plexpy/notifiers.py +++ b/plexpy/notifiers.py @@ -94,6 +94,8 @@ AGENT_IDS = {'growl': 0, 'zapier': 24 } +DEFAULT_CUSTOM_CONDITIONS = [{'parameter': '', 'operator': '', 'value': ''}] + def available_notification_agents(): agents = [{'label': 'Tautulli Remote Android App', @@ -446,7 +448,6 @@ def get_notifier_config(notifier_id=None): db = database.MonitorDatabase() result = db.select_single('SELECT * FROM notifiers WHERE id = ?', args=[notifier_id]) - if not result: return None @@ -468,6 +469,14 @@ def get_notifier_config(notifier_id=None): notifier_text[k] = {'subject': result.pop(k + '_subject'), 'body': result.pop(k + '_body')} + try: + result['custom_conditions'] = json.loads(result['custom_conditions']) + except (ValueError, TypeError): + result['custom_conditions'] = DEFAULT_CUSTOM_CONDITIONS + + if not result['custom_conditions_logic']: + result['custom_conditions_logic'] = '' + result['config'] = config result['config_options'] = notifier_config result['actions'] = notifier_actions @@ -494,7 +503,9 @@ def add_notifier_config(agent_id=None, **kwargs): 'agent_name': agent['name'], 'agent_label': agent['label'], 'friendly_name': '', - 'notifier_config': json.dumps(get_agent_class(agent_id=agent['id']).config) + 'notifier_config': json.dumps(get_agent_class(agent_id=agent['id']).config), + 'custom_conditions': json.dumps(DEFAULT_CUSTOM_CONDITIONS), + 'custom_conditions_logic': '' } if agent['name'] == 'scripts': for a in available_notification_actions(): @@ -549,7 +560,7 @@ def set_notifier_config(notifier_id=None, agent_id=None, **kwargs): 'agent_label': agent['label'], 'friendly_name': kwargs.get('friendly_name', ''), 'notifier_config': json.dumps(notifier_config), - 'custom_conditions': kwargs.get('custom_conditions', ''), + 'custom_conditions': kwargs.get('custom_conditions', json.dumps(DEFAULT_CUSTOM_CONDITIONS)), 'custom_conditions_logic': kwargs.get('custom_conditions_logic', ''), } values.update(actions) diff --git a/plexpy/webserve.py b/plexpy/webserve.py index b45c2ce4..3229ddb7 100644 --- a/plexpy/webserve.py +++ b/plexpy/webserve.py @@ -3004,18 +3004,12 @@ class WebInterface(object): def get_notifier_config_modal(self, notifier_id=None, **kwargs): result = notifiers.get_notifier_config(notifier_id=notifier_id) - if not result['custom_conditions']: - result['custom_conditions'] = json.dumps([{'parameter': '', 'operator': '', 'value': ''}]) - - if not result['custom_conditions_logic']: - result['custom_conditions_logic'] = '' - parameters = [ {'name': param['name'], 'type': param['type'], 'value': param['value']} for category in common.NOTIFICATION_PARAMETERS for param in category['parameters'] ] - return serve_template(templatename="notifier_config.html", notifier=result, parameters=json.dumps(parameters)) + return serve_template(templatename="notifier_config.html", notifier=result, parameters=parameters) @cherrypy.expose @cherrypy.tools.json_out()