mpeltriaux
5b0b376405
* removes admin backend views which are not important for production * adds filtering functionalities on index views * simplifies detail views on intervention, compensation, ecoaccount and ema * adds autocomplete fields on detail views * adds handy horizontal filter fields on detail views
37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
from django.db import models
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
from konova.models import BaseResource
|
|
from user.models import UserActionLogEntry
|
|
|
|
|
|
class ServerMessageImportance(models.TextChoices):
|
|
"""
|
|
Defines importance levels for server messages
|
|
"""
|
|
DEFAULT = "default", _("Default")
|
|
INFO = "info", _("Info")
|
|
WARNING = "warning", _("Warning")
|
|
|
|
|
|
class ServerMessage(BaseResource):
|
|
"""
|
|
Holds messages, which can be displayed on the user's dashboard
|
|
"""
|
|
subject = models.CharField(max_length=500, null=False, blank=False)
|
|
body = models.TextField()
|
|
is_active = models.BooleanField(default=True)
|
|
publish_on = models.DateTimeField()
|
|
unpublish_on = models.DateTimeField()
|
|
importance = models.CharField(max_length=100, choices=ServerMessageImportance.choices)
|
|
|
|
def save(self, user=None, *args, **kwargs):
|
|
user = kwargs.pop("user", None)
|
|
if user is not None:
|
|
if self.created is None:
|
|
self.created = UserActionLogEntry.get_created_action(user)
|
|
else:
|
|
self.modified = UserActionLogEntry.get_edited_action(user)
|
|
|
|
super().save(*args, **kwargs)
|