2015-06-18 23:57:43 -05:00
|
|
|
"""Track dispatcher configurations."""
|
|
|
|
|
2015-06-19 21:07:45 -05:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2015-06-18 23:57:43 -05:00
|
|
|
import logging
|
|
|
|
|
|
|
|
from django.db import models
|
|
|
|
|
|
|
|
|
|
|
|
log = logging.getLogger('dispatch.models')
|
|
|
|
|
|
|
|
|
|
|
|
class Dispatcher(models.Model):
|
|
|
|
|
2015-06-19 11:29:00 -05:00
|
|
|
"""Organize dispatchers by key."""
|
|
|
|
|
|
|
|
key = models.CharField(max_length=16, unique=True)
|
|
|
|
|
2015-06-19 16:45:10 -05:00
|
|
|
class Meta:
|
|
|
|
permissions = (
|
|
|
|
('send_message', "Can send messages to dispatchers"),
|
|
|
|
)
|
|
|
|
|
2015-06-19 11:29:00 -05:00
|
|
|
def __unicode__(self):
|
|
|
|
"""String representation."""
|
|
|
|
|
2015-06-19 21:07:45 -05:00
|
|
|
return "{0:s}".format(self.key)
|
2015-06-19 11:29:00 -05:00
|
|
|
|
|
|
|
|
|
|
|
class DispatcherAction(models.Model):
|
|
|
|
|
|
|
|
"""Handle requests to dispatchers and do something with them."""
|
2015-06-18 23:57:43 -05:00
|
|
|
|
|
|
|
PRIVMSG_TYPE = 'privmsg'
|
|
|
|
FILE_TYPE = 'file'
|
|
|
|
|
|
|
|
TYPE_CHOICES = (
|
|
|
|
(PRIVMSG_TYPE, "IRC privmsg"),
|
|
|
|
(FILE_TYPE, "Write to file"),
|
|
|
|
)
|
|
|
|
|
2015-06-19 15:08:57 -05:00
|
|
|
dispatcher = models.ForeignKey('Dispatcher', related_name='actions')
|
2015-06-18 23:57:43 -05:00
|
|
|
type = models.CharField(max_length=16, choices=TYPE_CHOICES)
|
|
|
|
destination = models.CharField(max_length=200)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
"""String representation."""
|
|
|
|
|
2015-06-19 21:07:45 -05:00
|
|
|
return "{0:s} -> {1:s} {2:s}".format(self.dispatcher.key, self.type, self.destination)
|