Server Messages unpublish
* changes unpublish_on to optional value * simplifies fetching of server message news
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from django.db import models
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from konova.models import BaseResource
|
||||
@@ -22,7 +23,7 @@ class ServerMessage(BaseResource):
|
||||
body = models.TextField()
|
||||
is_active = models.BooleanField(default=True)
|
||||
publish_on = models.DateTimeField()
|
||||
unpublish_on = models.DateTimeField()
|
||||
unpublish_on = models.DateTimeField(null=True, blank=True)
|
||||
importance = models.CharField(max_length=100, choices=ServerMessageImportance.choices)
|
||||
|
||||
def save(self, user=None, *args, **kwargs):
|
||||
@@ -34,3 +35,24 @@ class ServerMessage(BaseResource):
|
||||
self.modified = UserActionLogEntry.get_edited_action(user)
|
||||
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
@staticmethod
|
||||
def get_current_news():
|
||||
""" Getter for the most current news
|
||||
|
||||
Meaning the ones that are
|
||||
* activated
|
||||
* publish_on has passed
|
||||
* unpublish_on (if set) has not been passed, yet
|
||||
|
||||
"""
|
||||
now = timezone.now()
|
||||
news = ServerMessage.objects.filter(
|
||||
is_active=True,
|
||||
publish_on__lte=now,
|
||||
).exclude(
|
||||
unpublish_on__lte=now,
|
||||
).order_by(
|
||||
"-publish_on"
|
||||
)
|
||||
return news
|
||||
Reference in New Issue
Block a user