Compare commits
No commits in common. "0a3a9b24800f32f352416389337a8699702c8edb" and "e4a2a0f64e0d3fb7ef85b0f1ed5e691c23c38a6b" have entirely different histories.
0a3a9b2480
...
e4a2a0f64e
@ -38,7 +38,13 @@ 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.get_current_news()[:3]
|
msgs = ServerMessage.objects.filter(
|
||||||
|
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(
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
# 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,5 +1,4 @@
|
|||||||
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
|
||||||
@ -23,7 +22,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(null=True, blank=True)
|
unpublish_on = models.DateTimeField()
|
||||||
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):
|
||||||
@ -35,24 +34,3 @@ 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,7 +20,14 @@ def index_view(request: HttpRequest):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
template = "news/index.html"
|
template = "news/index.html"
|
||||||
news = ServerMessage.get_current_news()
|
now = timezone.now()
|
||||||
|
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