rename dispatcher action type to action_type
This commit is contained in:
parent
cff1a183cf
commit
ffcdc3f8d8
@ -0,0 +1,18 @@
|
||||
# Generated by Django 3.2.18 on 2023-03-01 00:26
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('dispatch', '0006_xmlrpc_settings'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name='dispatcheraction',
|
||||
old_name='type',
|
||||
new_name='action_type',
|
||||
),
|
||||
]
|
@ -38,10 +38,10 @@ class DispatcherAction(models.Model):
|
||||
)
|
||||
|
||||
dispatcher = models.ForeignKey('Dispatcher', related_name='actions', on_delete=models.CASCADE)
|
||||
type = models.CharField(max_length=16, choices=TYPE_CHOICES)
|
||||
action_type = models.CharField(max_length=16, choices=TYPE_CHOICES)
|
||||
destination = models.CharField(max_length=200)
|
||||
include_key = models.BooleanField(default=False)
|
||||
|
||||
def __str__(self):
|
||||
"""Provide string representation."""
|
||||
return "{0:s} -> {1:s} {2:s}".format(self.dispatcher.key, self.type, self.destination)
|
||||
return "{0:s} -> {1:s} {2:s}".format(self.dispatcher.key, self.action_type, self.destination)
|
||||
|
@ -12,7 +12,7 @@ class DispatcherActionSerializer(serializers.ModelSerializer):
|
||||
"""Meta options."""
|
||||
|
||||
model = DispatcherAction
|
||||
fields = ('id', 'dispatcher', 'type', 'destination')
|
||||
fields = ('id', 'dispatcher', 'action_type', 'destination')
|
||||
|
||||
|
||||
class DispatcherSerializer(serializers.ModelSerializer):
|
||||
|
@ -71,19 +71,19 @@ class DispatchMessage(generics.GenericAPIView):
|
||||
else:
|
||||
text = message.data['message']
|
||||
|
||||
if action.type == DispatcherAction.PRIVMSG_TYPE:
|
||||
if action.action_type == DispatcherAction.PRIVMSG_TYPE:
|
||||
# connect over XML-RPC and send
|
||||
try:
|
||||
bot_url = 'http://{0:s}:{1:d}/'.format(dispatcher.bot_xmlrpc_host, dispatcher.bot_xmlrpc_port)
|
||||
bot = xmlrpc.client.ServerProxy(bot_url, allow_none=True)
|
||||
log.debug("sending '%s' to channel %s", text, action.destination)
|
||||
bot.reply(None, text, False, action.destination)
|
||||
except Exception as e:
|
||||
except xmlrpc.client.Fault as xmlex:
|
||||
new_data = copy.deepcopy(message.data)
|
||||
new_data['status'] = "FAILED - {0:s}".format(str(e))
|
||||
new_data['status'] = "FAILED - {0:s}".format(str(xmlex))
|
||||
new_message = self.serializer_class(data=new_data)
|
||||
return Response(new_message.initial_data)
|
||||
elif action.type == DispatcherAction.FILE_TYPE:
|
||||
elif action.action_type == DispatcherAction.FILE_TYPE:
|
||||
# write to file
|
||||
filename = os.path.abspath(action.destination)
|
||||
log.debug("sending '%s' to file %s", text, filename)
|
||||
|
Loading…
Reference in New Issue
Block a user