Rename config_id to agent_id

This commit is contained in:
JonnyWong16 2016-02-14 11:39:03 -08:00
parent 322f106e75
commit c90dd147bb
5 changed files with 75 additions and 75 deletions

View file

@ -132,7 +132,7 @@ from plexpy import helpers
function reloadModal() { function reloadModal() {
$.ajax({ $.ajax({
url: 'get_notification_agent_config', url: 'get_notification_agent_config',
data: { config_id: '${agent["id"]}' }, data: { agent_id: '${agent["id"]}' },
cache: false, cache: false,
async: true, async: true,
complete: function (xhr, status) { complete: function (xhr, status) {
@ -195,7 +195,7 @@ from plexpy import helpers
$.ajax({ $.ajax({
url: 'test_notifier', url: 'test_notifier',
data: { data: {
config_id: '${agent["id"]}', agent_id: '${agent["id"]}',
subject: $('#test_subject').val(), subject: $('#test_subject').val(),
body: $('#test_body').val(), body: $('#test_body').val(),
script: $('#test_script').val(), script: $('#test_script').val(),

View file

@ -1721,10 +1721,10 @@ $(document).ready(function() {
// Load notification agent config modal // Load notification agent config modal
$(".toggle-notification-config-modal").click(function() { $(".toggle-notification-config-modal").click(function() {
var configId = $(this).data('id'); var agent_id = $(this).data('id');
$.ajax({ $.ajax({
url: 'get_notification_agent_config', url: 'get_notification_agent_config',
data: { config_id: configId }, data: { agent_id: agent_id },
cache: false, cache: false,
async: true, async: true,
complete: function(xhr, status) { complete: function(xhr, status) {
@ -1735,10 +1735,10 @@ $(document).ready(function() {
// Load notification triggers config modal // Load notification triggers config modal
$(".toggle-notification-triggers-modal").click(function() { $(".toggle-notification-triggers-modal").click(function() {
var configId = $(this).data('id'); var agent_id = $(this).data('id');
$.ajax({ $.ajax({
url: 'get_notification_agent_triggers', url: 'get_notification_agent_triggers',
data: { config_id: configId }, data: { agent_id: agent_id },
cache: false, cache: false,
async: true, async: true,
complete: function(xhr, status) { complete: function(xhr, status) {

View file

@ -49,7 +49,7 @@ def notify(stream_data=None, notify_action=None):
if agent['on_play'] and notify_action == 'play': if agent['on_play'] and notify_action == 'play':
# Build and send notification # Build and send notification
notify_strings = build_notify_text(session=stream_data, state=notify_action) notify_strings = build_notify_text(session=stream_data, state=notify_action)
notifiers.send_notification(config_id=agent['id'], notifiers.send_notification(agent_id=agent['id'],
subject=notify_strings[0], subject=notify_strings[0],
body=notify_strings[1], body=notify_strings[1],
notify_action=notify_action, notify_action=notify_action,
@ -62,7 +62,7 @@ def notify(stream_data=None, notify_action=None):
and (plexpy.CONFIG.NOTIFY_CONSECUTIVE or progress_percent < plexpy.CONFIG.NOTIFY_WATCHED_PERCENT): and (plexpy.CONFIG.NOTIFY_CONSECUTIVE or progress_percent < plexpy.CONFIG.NOTIFY_WATCHED_PERCENT):
# Build and send notification # Build and send notification
notify_strings = build_notify_text(session=stream_data, state=notify_action) notify_strings = build_notify_text(session=stream_data, state=notify_action)
notifiers.send_notification(config_id=agent['id'], notifiers.send_notification(agent_id=agent['id'],
subject=notify_strings[0], subject=notify_strings[0],
body=notify_strings[1], body=notify_strings[1],
notify_action=notify_action, notify_action=notify_action,
@ -74,7 +74,7 @@ def notify(stream_data=None, notify_action=None):
and (plexpy.CONFIG.NOTIFY_CONSECUTIVE or progress_percent < 99): and (plexpy.CONFIG.NOTIFY_CONSECUTIVE or progress_percent < 99):
# Build and send notification # Build and send notification
notify_strings = build_notify_text(session=stream_data, state=notify_action) notify_strings = build_notify_text(session=stream_data, state=notify_action)
notifiers.send_notification(config_id=agent['id'], notifiers.send_notification(agent_id=agent['id'],
subject=notify_strings[0], subject=notify_strings[0],
body=notify_strings[1], body=notify_strings[1],
notify_action=notify_action, notify_action=notify_action,
@ -86,7 +86,7 @@ def notify(stream_data=None, notify_action=None):
and (plexpy.CONFIG.NOTIFY_CONSECUTIVE or progress_percent < 99): and (plexpy.CONFIG.NOTIFY_CONSECUTIVE or progress_percent < 99):
# Build and send notification # Build and send notification
notify_strings = build_notify_text(session=stream_data, state=notify_action) notify_strings = build_notify_text(session=stream_data, state=notify_action)
notifiers.send_notification(config_id=agent['id'], notifiers.send_notification(agent_id=agent['id'],
subject=notify_strings[0], subject=notify_strings[0],
body=notify_strings[1], body=notify_strings[1],
notify_action=notify_action, notify_action=notify_action,
@ -97,7 +97,7 @@ def notify(stream_data=None, notify_action=None):
elif agent['on_buffer'] and notify_action == 'buffer': elif agent['on_buffer'] and notify_action == 'buffer':
# Build and send notification # Build and send notification
notify_strings = build_notify_text(session=stream_data, state=notify_action) notify_strings = build_notify_text(session=stream_data, state=notify_action)
notifiers.send_notification(config_id=agent['id'], notifiers.send_notification(agent_id=agent['id'],
subject=notify_strings[0], subject=notify_strings[0],
body=notify_strings[1], body=notify_strings[1],
notify_action=notify_action, notify_action=notify_action,
@ -113,7 +113,7 @@ def notify(stream_data=None, notify_action=None):
if not any(d['agent_id'] == agent['id'] for d in notify_states): if not any(d['agent_id'] == agent['id'] for d in notify_states):
# Build and send notification # Build and send notification
notify_strings = build_notify_text(session=stream_data, state=notify_action) notify_strings = build_notify_text(session=stream_data, state=notify_action)
notifiers.send_notification(config_id=agent['id'], notifiers.send_notification(agent_id=agent['id'],
subject=notify_strings[0], subject=notify_strings[0],
body=notify_strings[1], body=notify_strings[1],
notify_action=notify_action, notify_action=notify_action,
@ -128,7 +128,7 @@ def notify(stream_data=None, notify_action=None):
if not notify_state['on_watched'] and (notify_state['agent_id'] == agent['id']): if not notify_state['on_watched'] and (notify_state['agent_id'] == agent['id']):
# Build and send notification # Build and send notification
notify_strings = build_notify_text(session=stream_data, state=notify_action) notify_strings = build_notify_text(session=stream_data, state=notify_action)
notifiers.send_notification(config_id=agent['id'], notifiers.send_notification(agent_id=agent['id'],
subject=notify_strings[0], subject=notify_strings[0],
body=notify_strings[1], body=notify_strings[1],
notify_action=notify_action, notify_action=notify_action,
@ -143,7 +143,7 @@ def notify(stream_data=None, notify_action=None):
if agent['on_play'] and notify_action == 'play': if agent['on_play'] and notify_action == 'play':
# Build and send notification # Build and send notification
notify_strings = build_notify_text(session=stream_data, state=notify_action) notify_strings = build_notify_text(session=stream_data, state=notify_action)
notifiers.send_notification(config_id=agent['id'], notifiers.send_notification(agent_id=agent['id'],
subject=notify_strings[0], subject=notify_strings[0],
body=notify_strings[1], body=notify_strings[1],
notify_action=notify_action, notify_action=notify_action,
@ -155,7 +155,7 @@ def notify(stream_data=None, notify_action=None):
elif agent['on_stop'] and notify_action == 'stop': elif agent['on_stop'] and notify_action == 'stop':
# Build and send notification # Build and send notification
notify_strings = build_notify_text(session=stream_data, state=notify_action) notify_strings = build_notify_text(session=stream_data, state=notify_action)
notifiers.send_notification(config_id=agent['id'], notifiers.send_notification(agent_id=agent['id'],
subject=notify_strings[0], subject=notify_strings[0],
body=notify_strings[1], body=notify_strings[1],
notify_action=notify_action, notify_action=notify_action,
@ -167,7 +167,7 @@ def notify(stream_data=None, notify_action=None):
elif agent['on_pause'] and notify_action == 'pause': elif agent['on_pause'] and notify_action == 'pause':
# Build and send notification # Build and send notification
notify_strings = build_notify_text(session=stream_data, state=notify_action) notify_strings = build_notify_text(session=stream_data, state=notify_action)
notifiers.send_notification(config_id=agent['id'], notifiers.send_notification(agent_id=agent['id'],
subject=notify_strings[0], subject=notify_strings[0],
body=notify_strings[1], body=notify_strings[1],
notify_action=notify_action, notify_action=notify_action,
@ -179,7 +179,7 @@ def notify(stream_data=None, notify_action=None):
elif agent['on_resume'] and notify_action == 'resume': elif agent['on_resume'] and notify_action == 'resume':
# Build and send notification # Build and send notification
notify_strings = build_notify_text(session=stream_data, state=notify_action) notify_strings = build_notify_text(session=stream_data, state=notify_action)
notifiers.send_notification(config_id=agent['id'], notifiers.send_notification(agent_id=agent['id'],
subject=notify_strings[0], subject=notify_strings[0],
body=notify_strings[1], body=notify_strings[1],
notify_action=notify_action, notify_action=notify_action,
@ -191,7 +191,7 @@ def notify(stream_data=None, notify_action=None):
elif agent['on_buffer'] and notify_action == 'buffer': elif agent['on_buffer'] and notify_action == 'buffer':
# Build and send notification # Build and send notification
notify_strings = build_notify_text(session=stream_data, state=notify_action) notify_strings = build_notify_text(session=stream_data, state=notify_action)
notifiers.send_notification(config_id=agent['id'], notifiers.send_notification(agent_id=agent['id'],
subject=notify_strings[0], subject=notify_strings[0],
body=notify_strings[1], body=notify_strings[1],
notify_action=notify_action, notify_action=notify_action,
@ -215,7 +215,7 @@ def notify_timeline(timeline_data=None, notify_action=None):
if agent['on_created'] and notify_action == 'created': if agent['on_created'] and notify_action == 'created':
# Build and send notification # Build and send notification
notify_strings = build_notify_text(timeline=timeline_data, state=notify_action) notify_strings = build_notify_text(timeline=timeline_data, state=notify_action)
notifiers.send_notification(config_id=agent['id'], notifiers.send_notification(agent_id=agent['id'],
subject=notify_strings[0], subject=notify_strings[0],
body=notify_strings[1], body=notify_strings[1],
notify_action=notify_action, notify_action=notify_action,
@ -228,7 +228,7 @@ def notify_timeline(timeline_data=None, notify_action=None):
if agent['on_extdown'] and notify_action == 'extdown': if agent['on_extdown'] and notify_action == 'extdown':
# Build and send notification # Build and send notification
notify_strings = build_server_notify_text(state=notify_action) notify_strings = build_server_notify_text(state=notify_action)
notifiers.send_notification(config_id=agent['id'], notifiers.send_notification(agent_id=agent['id'],
subject=notify_strings[0], subject=notify_strings[0],
body=notify_strings[1], body=notify_strings[1],
notify_action=notify_action, notify_action=notify_action,
@ -236,7 +236,7 @@ def notify_timeline(timeline_data=None, notify_action=None):
if agent['on_intdown'] and notify_action == 'intdown': if agent['on_intdown'] and notify_action == 'intdown':
# Build and send notification # Build and send notification
notify_strings = build_server_notify_text(state=notify_action) notify_strings = build_server_notify_text(state=notify_action)
notifiers.send_notification(config_id=agent['id'], notifiers.send_notification(agent_id=agent['id'],
subject=notify_strings[0], subject=notify_strings[0],
body=notify_strings[1], body=notify_strings[1],
notify_action=notify_action, notify_action=notify_action,
@ -244,7 +244,7 @@ def notify_timeline(timeline_data=None, notify_action=None):
if agent['on_extup'] and notify_action == 'extup': if agent['on_extup'] and notify_action == 'extup':
# Build and send notification # Build and send notification
notify_strings = build_server_notify_text(state=notify_action) notify_strings = build_server_notify_text(state=notify_action)
notifiers.send_notification(config_id=agent['id'], notifiers.send_notification(agent_id=agent['id'],
subject=notify_strings[0], subject=notify_strings[0],
body=notify_strings[1], body=notify_strings[1],
notify_action=notify_action, notify_action=notify_action,
@ -252,7 +252,7 @@ def notify_timeline(timeline_data=None, notify_action=None):
if agent['on_intup'] and notify_action == 'intup': if agent['on_intup'] and notify_action == 'intup':
# Build and send notification # Build and send notification
notify_strings = build_server_notify_text(state=notify_action) notify_strings = build_server_notify_text(state=notify_action)
notifiers.send_notification(config_id=agent['id'], notifiers.send_notification(agent_id=agent['id'],
subject=notify_strings[0], subject=notify_strings[0],
body=notify_strings[1], body=notify_strings[1],
notify_action=notify_action, notify_action=notify_action,

View file

@ -358,59 +358,59 @@ def available_notification_agents():
return agents return agents
def get_notification_agent_config(config_id): def get_notification_agent_config(agent_id):
if str(config_id).isdigit(): if str(agent_id).isdigit():
config_id = int(config_id) agent_id = int(agent_id)
if config_id == 0: if agent_id == 0:
growl = GROWL() growl = GROWL()
return growl.return_config_options() return growl.return_config_options()
elif config_id == 1: elif agent_id == 1:
prowl = PROWL() prowl = PROWL()
return prowl.return_config_options() return prowl.return_config_options()
elif config_id == 2: elif agent_id == 2:
xbmc = XBMC() xbmc = XBMC()
return xbmc.return_config_options() return xbmc.return_config_options()
elif config_id == 3: elif agent_id == 3:
plex = Plex() plex = Plex()
return plex.return_config_options() return plex.return_config_options()
elif config_id == 4: elif agent_id == 4:
nma = NMA() nma = NMA()
return nma.return_config_options() return nma.return_config_options()
elif config_id == 5: elif agent_id == 5:
pushalot = PUSHALOT() pushalot = PUSHALOT()
return pushalot.return_config_options() return pushalot.return_config_options()
elif config_id == 6: elif agent_id == 6:
pushbullet = PUSHBULLET() pushbullet = PUSHBULLET()
return pushbullet.return_config_options() return pushbullet.return_config_options()
elif config_id == 7: elif agent_id == 7:
pushover = PUSHOVER() pushover = PUSHOVER()
return pushover.return_config_options() return pushover.return_config_options()
elif config_id == 8: elif agent_id == 8:
osx_notify = OSX_NOTIFY() osx_notify = OSX_NOTIFY()
return osx_notify.return_config_options() return osx_notify.return_config_options()
elif config_id == 9: elif agent_id == 9:
boxcar = BOXCAR() boxcar = BOXCAR()
return boxcar.return_config_options() return boxcar.return_config_options()
elif config_id == 10: elif agent_id == 10:
email = Email() email = Email()
return email.return_config_options() return email.return_config_options()
elif config_id == 11: elif agent_id == 11:
tweet = TwitterNotifier() tweet = TwitterNotifier()
return tweet.return_config_options() return tweet.return_config_options()
elif config_id == 12: elif agent_id == 12:
iftttClient = IFTTT() iftttClient = IFTTT()
return iftttClient.return_config_options() return iftttClient.return_config_options()
elif config_id == 13: elif agent_id == 13:
telegramClient = TELEGRAM() telegramClient = TELEGRAM()
return telegramClient.return_config_options() return telegramClient.return_config_options()
elif config_id == 14: elif agent_id == 14:
slackClient = SLACK() slackClient = SLACK()
return slackClient.return_config_options() return slackClient.return_config_options()
elif config_id == 15: elif agent_id == 15:
script = Scripts() script = Scripts()
return script.return_config_options() return script.return_config_options()
elif config_id == 16: elif agent_id == 16:
facebook = FacebookNotifier() facebook = FacebookNotifier()
return facebook.return_config_options() return facebook.return_config_options()
else: else:
@ -419,59 +419,59 @@ def get_notification_agent_config(config_id):
return [] return []
def send_notification(config_id, subject, body, **kwargs): def send_notification(agent_id, subject, body, **kwargs):
if str(config_id).isdigit(): if str(agent_id).isdigit():
config_id = int(config_id) agent_id = int(agent_id)
if config_id == 0: if agent_id == 0:
growl = GROWL() growl = GROWL()
growl.notify(message=body, event=subject) growl.notify(message=body, event=subject)
elif config_id == 1: elif agent_id == 1:
prowl = PROWL() prowl = PROWL()
prowl.notify(message=body, event=subject) prowl.notify(message=body, event=subject)
elif config_id == 2: elif agent_id == 2:
xbmc = XBMC() xbmc = XBMC()
xbmc.notify(subject=subject, message=body) xbmc.notify(subject=subject, message=body)
elif config_id == 3: elif agent_id == 3:
plex = Plex() plex = Plex()
plex.notify(subject=subject, message=body) plex.notify(subject=subject, message=body)
elif config_id == 4: elif agent_id == 4:
nma = NMA() nma = NMA()
nma.notify(subject=subject, message=body) nma.notify(subject=subject, message=body)
elif config_id == 5: elif agent_id == 5:
pushalot = PUSHALOT() pushalot = PUSHALOT()
pushalot.notify(message=body, event=subject) pushalot.notify(message=body, event=subject)
elif config_id == 6: elif agent_id == 6:
pushbullet = PUSHBULLET() pushbullet = PUSHBULLET()
pushbullet.notify(message=body, subject=subject) pushbullet.notify(message=body, subject=subject)
elif config_id == 7: elif agent_id == 7:
pushover = PUSHOVER() pushover = PUSHOVER()
pushover.notify(message=body, event=subject) pushover.notify(message=body, event=subject)
elif config_id == 8: elif agent_id == 8:
osx_notify = OSX_NOTIFY() osx_notify = OSX_NOTIFY()
osx_notify.notify(title=subject, text=body) osx_notify.notify(title=subject, text=body)
elif config_id == 9: elif agent_id == 9:
boxcar = BOXCAR() boxcar = BOXCAR()
boxcar.notify(title=subject, message=body) boxcar.notify(title=subject, message=body)
elif config_id == 10: elif agent_id == 10:
email = Email() email = Email()
email.notify(subject=subject, message=body) email.notify(subject=subject, message=body)
elif config_id == 11: elif agent_id == 11:
tweet = TwitterNotifier() tweet = TwitterNotifier()
tweet.notify(subject=subject, message=body) tweet.notify(subject=subject, message=body)
elif config_id == 12: elif agent_id == 12:
iftttClient = IFTTT() iftttClient = IFTTT()
iftttClient.notify(subject=subject, message=body) iftttClient.notify(subject=subject, message=body)
elif config_id == 13: elif agent_id == 13:
telegramClient = TELEGRAM() telegramClient = TELEGRAM()
telegramClient.notify(message=body, event=subject) telegramClient.notify(message=body, event=subject)
elif config_id == 14: elif agent_id == 14:
slackClient = SLACK() slackClient = SLACK()
slackClient.notify(message=body, event=subject) slackClient.notify(message=body, event=subject)
elif config_id == 15: elif agent_id == 15:
scripts = Scripts() scripts = Scripts()
scripts.notify(message=body, subject=subject, **kwargs) scripts.notify(message=body, subject=subject, **kwargs)
elif config_id == 16: elif agent_id == 16:
facebook = FacebookNotifier() facebook = FacebookNotifier()
facebook.notify(subject=subject, message=body) facebook.notify(subject=subject, message=body)
else: else:

View file

@ -1321,12 +1321,12 @@ class WebInterface(object):
raise cherrypy.HTTPRedirect("settings") raise cherrypy.HTTPRedirect("settings")
@cherrypy.expose @cherrypy.expose
def get_notification_agent_config(self, config_id, **kwargs): def get_notification_agent_config(self, agent_id, **kwargs):
if config_id.isdigit(): if agent_id.isdigit():
config = notifiers.get_notification_agent_config(config_id=config_id) config = notifiers.get_notification_agent_config(agent_id=agent_id)
agents = notifiers.available_notification_agents() agents = notifiers.available_notification_agents()
for agent in agents: for agent in agents:
if int(config_id) == agent['id']: if int(agent_id) == agent['id']:
this_agent = agent this_agent = agent
break break
else: else:
@ -1340,11 +1340,11 @@ class WebInterface(object):
agent=this_agent, data=config, checkboxes=checkboxes) agent=this_agent, data=config, checkboxes=checkboxes)
@cherrypy.expose @cherrypy.expose
def get_notification_agent_triggers(self, config_id, **kwargs): def get_notification_agent_triggers(self, agent_id, **kwargs):
if config_id.isdigit(): if agent_id.isdigit():
agents = notifiers.available_notification_agents() agents = notifiers.available_notification_agents()
for agent in agents: for agent in agents:
if int(config_id) == agent['id']: if int(agent_id) == agent['id']:
this_agent = agent this_agent = agent
break break
else: else:
@ -1357,13 +1357,13 @@ class WebInterface(object):
@cherrypy.expose @cherrypy.expose
@addtoapi('notify') @addtoapi('notify')
def test_notifier(self, config_id=None, subject='PlexPy', body='Test notification', **kwargs): def test_notifier(self, agent_id=None, subject='PlexPy', body='Test notification', **kwargs):
cherrypy.response.headers['Cache-Control'] = "max-age=0,no-cache,no-store" cherrypy.response.headers['Cache-Control'] = "max-age=0,no-cache,no-store"
if config_id.isdigit(): if agent_id.isdigit():
agents = notifiers.available_notification_agents() agents = notifiers.available_notification_agents()
for agent in agents: for agent in agents:
if int(config_id) == agent['id']: if int(agent_id) == agent['id']:
this_agent = agent this_agent = agent
break break
else: else:
@ -1374,8 +1374,8 @@ class WebInterface(object):
notifiers.send_notification(this_agent['id'], subject, body, **kwargs) notifiers.send_notification(this_agent['id'], subject, body, **kwargs)
return "Notification sent." return "Notification sent."
else: else:
logger.debug(u"Unable to send test notification, invalid notification agent ID %s." % config_id) logger.debug(u"Unable to send test notification, invalid notification agent ID %s." % agent_id)
return "Invalid notification agent ID %s." % config_id return "Invalid notification agent ID %s." % agent_id
else: else:
logger.debug(u"Unable to send test notification, no notification agent ID received.") logger.debug(u"Unable to send test notification, no notification agent ID received.")
return "No notification agent ID received." return "No notification agent ID received."