You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
konova/news/views.py

38 lines
960 B
Python

from django.contrib.auth.decorators import login_required
from django.http import HttpRequest
from django.shortcuts import render
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
from konova.contexts import BaseContext
from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
from news.models import ServerMessage
@login_required
def index_view(request: HttpRequest):
""" Renders an overview of all news
Args:
request (HttpRequest): The incoming request
Returns:
"""
template = "news/index.html"
now = timezone.now()
news = ServerMessage.objects.filter(
is_active=True,
publish_on__lte=now,
unpublish_on__gte=now
).order_by(
"-publish_on"
)
context = {
"news": news,
TAB_TITLE_IDENTIFIER: _("News"),
}
context = BaseContext(request, context).context
return render(request, template, context)