dispatch: nest the dispatcher -> action serializer
This commit is contained in:
parent
4f717cb1c2
commit
3532b073c4
@ -32,7 +32,7 @@ class DispatcherAction(models.Model):
|
|||||||
(FILE_TYPE, "Write to file"),
|
(FILE_TYPE, "Write to file"),
|
||||||
)
|
)
|
||||||
|
|
||||||
dispatcher = models.ForeignKey('Dispatcher')
|
dispatcher = models.ForeignKey('Dispatcher', related_name='actions')
|
||||||
type = models.CharField(max_length=16, choices=TYPE_CHOICES)
|
type = models.CharField(max_length=16, choices=TYPE_CHOICES)
|
||||||
destination = models.CharField(max_length=200)
|
destination = models.CharField(max_length=200)
|
||||||
|
|
||||||
|
@ -5,13 +5,6 @@ from rest_framework import serializers
|
|||||||
from dispatch.models import Dispatcher, DispatcherAction
|
from dispatch.models import Dispatcher, DispatcherAction
|
||||||
|
|
||||||
|
|
||||||
class DispatcherSerializer(serializers.ModelSerializer):
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = Dispatcher
|
|
||||||
fields = ('id', 'key')
|
|
||||||
|
|
||||||
|
|
||||||
class DispatcherActionSerializer(serializers.ModelSerializer):
|
class DispatcherActionSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
@ -19,6 +12,15 @@ class DispatcherActionSerializer(serializers.ModelSerializer):
|
|||||||
fields = ('id', 'dispatcher', 'type', 'destination')
|
fields = ('id', 'dispatcher', 'type', 'destination')
|
||||||
|
|
||||||
|
|
||||||
|
class DispatcherSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
actions = DispatcherActionSerializer(many=True, read_only=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Dispatcher
|
||||||
|
fields = ('id', 'key', 'actions')
|
||||||
|
|
||||||
|
|
||||||
class DispatchMessageSerializer(serializers.Serializer):
|
class DispatchMessageSerializer(serializers.Serializer):
|
||||||
|
|
||||||
message = serializers.CharField()
|
message = serializers.CharField()
|
||||||
|
@ -57,7 +57,7 @@ class DispatchMessage(generics.GenericAPIView):
|
|||||||
dispatcher = self.get_object()
|
dispatcher = self.get_object()
|
||||||
message = self.serializer_class(data=request.data)
|
message = self.serializer_class(data=request.data)
|
||||||
if message.is_valid():
|
if message.is_valid():
|
||||||
for action in dispatcher.dispatcheraction_set.all():
|
for action in dispatcher.actions.all():
|
||||||
if action.type == DispatcherAction.PRIVMSG_TYPE:
|
if action.type == DispatcherAction.PRIVMSG_TYPE:
|
||||||
bot_url = 'http://{0:s}:{1:d}/'.format(settings.IRCBOT_XMLRPC_HOST, settings.IRCBOT_XMLRPC_PORT)
|
bot_url = 'http://{0:s}:{1:d}/'.format(settings.IRCBOT_XMLRPC_HOST, settings.IRCBOT_XMLRPC_PORT)
|
||||||
bot = xmlrpclib.ServerProxy(bot_url)
|
bot = xmlrpclib.ServerProxy(bot_url)
|
||||||
|
Loading…
Reference in New Issue
Block a user