diff --git a/src/dashboard/apps/consent/models.py b/src/dashboard/apps/consent/models.py new file mode 100644 index 00000000..c215d2ee --- /dev/null +++ b/src/dashboard/apps/consent/models.py @@ -0,0 +1,59 @@ +"""Dashboard consent app models.""" + +from django.db import models +from django.utils.translation import gettext_lazy as _ + +from apps.auth.models import DashboardUser as User +from apps.core.models import DeliveryPoint +from apps.core.models.abstract import DateBase + + +class Consent(DateBase): + """Represents the consent given by a user for a specific charge point. + + Attributes: + AWAITING: Status indicating that the consent is awaiting validation. + VALIDATED: Status indicating that the consent has been validated. + REVOKED: Status indicating that the consent has been revoked. + + delivery_point: Foreign key relation to the charge point associated with the + consent. + user: Foreign key relation to the user giving the consent. + status: CharField storing the status of the consent, with a maximum length of 20 + characters and restricted to choices defined in CONSENT_STATUS_CHOICE. + date_added: DateTimeField recording the date and time when the consent was + created. + date_updated: DateTimeField recording the date and time when the consent was + last updated. + """ + + AWAITING = "AWAITING" + VALIDATED = "VALIDATED" + REVOKED = "REVOKED" + CONSENT_STATUS_CHOICE = [ + (AWAITING, _("Awaiting")), + (VALIDATED, _("Validated")), + (REVOKED, _("Revoked")), + ] + + delivery_point = models.ForeignKey(DeliveryPoint, on_delete=models.CASCADE) + user = models.ForeignKey( + User, on_delete=models.SET_NULL, null=True, verbose_name=_("user") + ) + status = models.CharField( + _("status"), max_length=20, choices=CONSENT_STATUS_CHOICE, default=AWAITING + ) + + # Validity period + validity_date_begin = models.DateTimeField(_("begin date")) + validity_date_expiration = models.DateTimeField(_("expiration date")) + revoked_at = models.DateTimeField(_("revoked at"), null=True, blank=True) + + class Meta: + """.""" + + ordering = ["delivery_point"] + + def __str__(self): + """.""" + return f"{self.delivery_point} - {self.date_updated} - {self.status}" diff --git a/src/dashboard/apps/core/models/entity.py b/src/dashboard/apps/core/models/entity.py new file mode 100644 index 00000000..353cf750 --- /dev/null +++ b/src/dashboard/apps/core/models/entity.py @@ -0,0 +1,25 @@ +"""Dashboard core app models.""" + +from django.db import models + +from apps.auth.models import DashboardUser as User +from apps.core.models.abstract import DateBase + + +class Entity(DateBase): + """Represents an operator in the system.""" + + name = models.CharField(max_length=64, unique=True) + user = models.ManyToManyField(User) + is_enabled = models.BooleanField(default=True) + + class Meta: + """.""" + + verbose_name = "Entity" + verbose_name_plural = "Entities" + ordering = ["name"] + + def __str__(self): + """.""" + return self.name diff --git a/src/dashboard/dashboard/settings.py b/src/dashboard/dashboard/settings.py index 4d97216e..710a5794 100644 --- a/src/dashboard/dashboard/settings.py +++ b/src/dashboard/dashboard/settings.py @@ -50,6 +50,7 @@ "dashboard", "apps", "apps.auth", + "apps.core", "apps.home", "apps.consent", ]