bornhack-website/src/ircbot/models.py
Thomas Steen Rasmussen 00af109e2f
add flake8 and isort to pre-commit config, make flake8 and isort happy (#441)
* add flake8 to pre-commit config, and fixup many things to make flake8 happy

* add isort and sort all imports, add to pre-commit and requirements
2020-02-12 13:10:41 +01:00

27 lines
864 B
Python

from django.core.exceptions import ValidationError
from django.db import models
from django.utils import timezone
from utils.models import CreatedUpdatedModel
class OutgoingIrcMessage(CreatedUpdatedModel):
target = models.CharField(max_length=100)
message = models.CharField(max_length=200)
processed = models.BooleanField(default=False)
timeout = models.DateTimeField()
expired = models.BooleanField(default=False)
def __str__(self):
return "PRIVMSG %s %s (%s)" % (
self.target,
self.message,
"processed" if self.processed else "unprocessed",
)
def clean(self):
if not self.pk:
# this is a new outgoing message being saved
if self.timeout < timezone.now():
raise ValidationError({"timeout": "The timeout can not be in the past"})