aboutsummaryrefslogtreecommitdiffstats
path: root/api/models.py
diff options
context:
space:
mode:
authorGravatar ImportErr <[email protected]>2018-12-08 11:55:40 +0000
committerGravatar ImportErr <[email protected]>2018-12-08 11:55:40 +0000
commit65b3381cfd35949ef457d5f794f83dbd3a4bd45c (patch)
tree1867912cf613498a4ca56fe3a0ef8660876157e3 /api/models.py
parentRenamed class in test_users (diff)
parentBump minimum DRF version to `3.9.0`. (diff)
Fixed merge conflicts
Diffstat (limited to 'api/models.py')
-rw-r--r--api/models.py63
1 files changed, 62 insertions, 1 deletions
diff --git a/api/models.py b/api/models.py
index fc031b6e..21b5975a 100644
--- a/api/models.py
+++ b/api/models.py
@@ -155,7 +155,8 @@ class SpecialSnake(ModelReprMixin, models.Model):
name = models.CharField(
max_length=140,
primary_key=True,
- help_text='A special snake name.'
+ help_text='A special snake name.',
+ validators=[RegexValidator(regex=r'^([^0-9])+$')]
)
info = models.TextField(
help_text='Info about a special snake.'
@@ -234,3 +235,63 @@ class User(ModelReprMixin, models.Model):
def __str__(self):
return f"{self.name}#{self.discriminator}"
+
+
+class Infraction(ModelReprMixin, models.Model):
+ """An infraction for a Discord user."""
+
+ TYPE_CHOICES = (
+ ("warning", "Warning"),
+ ("mute", "Mute"),
+ ("ban", "Ban"),
+ ("kick", "Kick"),
+ ("superstar", "Superstar")
+ )
+ inserted_at = models.DateTimeField(
+ auto_now_add=True,
+ help_text="The date and time of the creation of this infraction."
+ )
+ expires_at = models.DateTimeField(
+ null=True,
+ help_text=(
+ "The date and time of the expiration of this infraction. "
+ "Null if the infraction is permanent or it can't expire."
+ )
+ )
+ active = models.BooleanField(
+ default=True,
+ help_text="Whether the infraction is still active."
+ )
+ user = models.ForeignKey(
+ User,
+ on_delete=models.CASCADE,
+ related_name='infractions_received',
+ help_text="The user to which the infraction was applied."
+ )
+ actor = models.ForeignKey(
+ User,
+ on_delete=models.CASCADE,
+ related_name='infractions_given',
+ help_text="The user which applied the infraction."
+ )
+ type = models.CharField(
+ max_length=9,
+ choices=TYPE_CHOICES,
+ help_text="The type of the infraction."
+ )
+ reason = models.TextField(
+ null=True,
+ help_text="The reason for the infraction."
+ )
+ hidden = models.BooleanField(
+ default=False,
+ help_text="Whether the infraction is a shadow infraction."
+ )
+
+ def __str__(self):
+ s = f"#{self.id}: {self.type} on {self.user_id}"
+ if self.expires_at:
+ s += f" until {self.expires_at}"
+ if self.hidden:
+ s += " (hidden)"
+ return s