"""Track dispatcher configurations.""" import logging from django.db import models log = logging.getLogger('dispatch.models') class Dispatcher(models.Model): """Organize dispatchers by key.""" key = models.CharField(max_length=16, unique=True) class Meta: permissions = ( ('send_message', "Can send messages to dispatchers"), ) def __unicode__(self): """String representation.""" return u"{0:s}".format(self.key) class DispatcherAction(models.Model): """Handle requests to dispatchers and do something with them.""" PRIVMSG_TYPE = 'privmsg' FILE_TYPE = 'file' TYPE_CHOICES = ( (PRIVMSG_TYPE, "IRC privmsg"), (FILE_TYPE, "Write to file"), ) dispatcher = models.ForeignKey('Dispatcher', related_name='actions') type = models.CharField(max_length=16, choices=TYPE_CHOICES) destination = models.CharField(max_length=200) def __unicode__(self): """String representation.""" return u"{0:s} -> {1:s} {2:s}".format(self.dispatcher.key, self.type, self.destination)