diff --git a/dispatch/migrations/0007_rename_type_dispatcheraction_action_type.py b/dispatch/migrations/0007_rename_type_dispatcheraction_action_type.py new file mode 100644 index 0000000..86ed888 --- /dev/null +++ b/dispatch/migrations/0007_rename_type_dispatcheraction_action_type.py @@ -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', + ), + ] diff --git a/dispatch/models.py b/dispatch/models.py index a8f97b1..0572fa2 100644 --- a/dispatch/models.py +++ b/dispatch/models.py @@ -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) diff --git a/dispatch/serializers.py b/dispatch/serializers.py index ca38c16..4fbefcf 100644 --- a/dispatch/serializers.py +++ b/dispatch/serializers.py @@ -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): diff --git a/dispatch/views.py b/dispatch/views.py index 4c07476..5dc8ce6 100644 --- a/dispatch/views.py +++ b/dispatch/views.py @@ -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)