aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/apps/api/models/bot/nomination.py
blob: 2f8e305cf9144d0209a293dfe4ebfdab7f58f903 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from django.db import models

from pydis_site.apps.api.models.bot.user import User
from pydis_site.apps.api.models.mixins import ModelReprMixin


class Nomination(ModelReprMixin, models.Model):
    """A general helper nomination information created by staff."""

    active = models.BooleanField(
        default=True,
        help_text="Whether this nomination is still relevant."
    )
    user = models.ForeignKey(
        User,
        on_delete=models.CASCADE,
        help_text="The nominated user.",
        related_name='nomination'
    )
    inserted_at = models.DateTimeField(
        auto_now_add=True,
        help_text="The creation date of this nomination."
    )
    end_reason = models.TextField(
        help_text="Why the nomination was ended.",
        default="",
        blank=True
    )
    ended_at = models.DateTimeField(
        auto_now_add=False,
        help_text="When the nomination was ended.",
        null=True
    )
    reviewed = models.BooleanField(
        default=False,
        help_text="Whether a review was made."
    )
    thread_id = models.BigIntegerField(
        help_text="The nomination vote's thread id.",
        null=True,
    )

    class Meta:
        """Set the ordering of nominations to most recent first."""

        ordering = ("-inserted_at",)

    def __str__(self):
        """Representation that makes the target and state of the nomination immediately evident."""
        status = "active" if self.active else "ended"
        return f"Nomination of {self.user} ({status})"


class NominationEntry(ModelReprMixin, models.Model):
    """A nomination entry created by a single staff member."""

    nomination = models.ForeignKey(
        Nomination,
        on_delete=models.CASCADE,
        help_text="The nomination this entry belongs to.",
        related_name="entries"
    )
    actor = models.ForeignKey(
        User,
        on_delete=models.CASCADE,
        help_text="The staff member that nominated this user.",
        related_name='nomination_set'
    )
    reason = models.TextField(
        help_text="Why the actor nominated this user.",
        default="",
        blank=True
    )
    inserted_at = models.DateTimeField(
        auto_now_add=True,
        help_text="The creation date of this nomination entry."
    )

    class Meta:
        """Meta options for NominationEntry model."""

        verbose_name_plural = "nomination entries"

        # Set default ordering here to latest first
        # so we don't need to define it everywhere
        ordering = ("-inserted_at",)