35 lines
794 B
Python
35 lines
794 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 konova.contexts import BaseContext
|
||
|
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,
|
||
|
}
|
||
|
context = BaseContext(request, context).context
|
||
|
return render(request, template, context)
|