dr.botzo/dr_botzo/dispatch/models.py

50 lines
1.1 KiB
Python
Raw Normal View History

"""Track dispatcher configurations."""
2015-06-19 21:07:45 -05:00
from __future__ import unicode_literals
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."""
2015-06-19 21:07:45 -05:00
return "{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."""
2015-06-19 21:07:45 -05:00
return "{0:s} -> {1:s} {2:s}".format(self.dispatcher.key, self.type, self.destination)