Merge pull request 'Server Messages unpublish' (#319) from improve_unpublish_dependency_news into master
Reviewed-on: SGD-Nord/konova#319
This commit is contained in:
commit
0a3a9b2480
@ -38,13 +38,7 @@ def home_view(request: HttpRequest):
|
|||||||
user_teams = user.shared_teams
|
user_teams = user.shared_teams
|
||||||
|
|
||||||
# Fetch the four newest active and published ServerMessages
|
# Fetch the four newest active and published ServerMessages
|
||||||
msgs = ServerMessage.objects.filter(
|
msgs = ServerMessage.get_current_news()[:3]
|
||||||
is_active=True,
|
|
||||||
publish_on__lte=now,
|
|
||||||
unpublish_on__gte=now,
|
|
||||||
).order_by(
|
|
||||||
"-publish_on"
|
|
||||||
)[:3]
|
|
||||||
|
|
||||||
# First fetch all valid objects (undeleted, only newest versions)
|
# First fetch all valid objects (undeleted, only newest versions)
|
||||||
interventions = Intervention.objects.filter(
|
interventions = Intervention.objects.filter(
|
||||||
|
18
news/migrations/0003_auto_20230324_0720.py
Normal file
18
news/migrations/0003_auto_20230324_0720.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 3.1.3 on 2023-03-24 06:20
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('news', '0002_auto_20220114_0936'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='servermessage',
|
||||||
|
name='unpublish_on',
|
||||||
|
field=models.DateTimeField(blank=True, null=True),
|
||||||
|
),
|
||||||
|
]
|
@ -1,4 +1,5 @@
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.utils import timezone
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from konova.models import BaseResource
|
from konova.models import BaseResource
|
||||||
@ -22,7 +23,7 @@ class ServerMessage(BaseResource):
|
|||||||
body = models.TextField()
|
body = models.TextField()
|
||||||
is_active = models.BooleanField(default=True)
|
is_active = models.BooleanField(default=True)
|
||||||
publish_on = models.DateTimeField()
|
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)
|
importance = models.CharField(max_length=100, choices=ServerMessageImportance.choices)
|
||||||
|
|
||||||
def save(self, user=None, *args, **kwargs):
|
def save(self, user=None, *args, **kwargs):
|
||||||
@ -34,3 +35,24 @@ class ServerMessage(BaseResource):
|
|||||||
self.modified = UserActionLogEntry.get_edited_action(user)
|
self.modified = UserActionLogEntry.get_edited_action(user)
|
||||||
|
|
||||||
super().save(*args, **kwargs)
|
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
|
@ -20,14 +20,7 @@ def index_view(request: HttpRequest):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
template = "news/index.html"
|
template = "news/index.html"
|
||||||
now = timezone.now()
|
news = ServerMessage.get_current_news()
|
||||||
news = ServerMessage.objects.filter(
|
|
||||||
is_active=True,
|
|
||||||
publish_on__lte=now,
|
|
||||||
unpublish_on__gte=now
|
|
||||||
).order_by(
|
|
||||||
"-publish_on"
|
|
||||||
)
|
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
"news": news,
|
"news": news,
|
||||||
|
Loading…
Reference in New Issue
Block a user