News app
* adds news app for future implementations
This commit is contained in:
0
news/__init__.py
Normal file
0
news/__init__.py
Normal file
14
news/admin.py
Normal file
14
news/admin.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from news.models import ServerMessage
|
||||
|
||||
|
||||
class ServerMessageAdmin(admin.ModelAdmin):
|
||||
list_display = [
|
||||
"id",
|
||||
"subject",
|
||||
"publish_on",
|
||||
"is_active",
|
||||
]
|
||||
|
||||
admin.site.register(ServerMessage, ServerMessageAdmin)
|
||||
5
news/apps.py
Normal file
5
news/apps.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class NewsConfig(AppConfig):
|
||||
name = 'news'
|
||||
16
news/models.py
Normal file
16
news/models.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from django.db import models
|
||||
|
||||
from konova.enums import ServerMessageImportance
|
||||
from konova.models import BaseResource
|
||||
|
||||
|
||||
class ServerMessage(BaseResource):
|
||||
"""
|
||||
Holds messages, which can be displayed on the user's dashboard
|
||||
"""
|
||||
subject = models.CharField(max_length=500, null=False, blank=False)
|
||||
body = models.TextField()
|
||||
is_active = models.BooleanField(default=True)
|
||||
publish_on = models.DateTimeField()
|
||||
unpublish_on = models.DateTimeField()
|
||||
importance = models.CharField(max_length=100, choices=ServerMessageImportance.as_choices(drop_empty_choice=True))
|
||||
23
news/templates/news/dashboard-news.html
Normal file
23
news/templates/news/dashboard-news.html
Normal file
@@ -0,0 +1,23 @@
|
||||
{% load i18n ksp_filters %}
|
||||
|
||||
<div id="server-messages" class="col-md px-3">
|
||||
<h4 class="row">{% trans 'News' %}</h4>
|
||||
<div class="row px-3">
|
||||
{% for msg in msgs %}
|
||||
<div class="card col-md {{msg.importance|bootstrap_cls}}">
|
||||
<div class="card-body">
|
||||
<h6 class="card-title">{{msg.subject}}</h6>
|
||||
<small>{% trans 'Published on' %} {{msg.publish_on}}</small>
|
||||
<article class="card-text">{{msg.body|safe}}</article>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
<div class="card col-md {{msg.importance|bootstrap_cls}} align-items-center justify-content-center">
|
||||
<a class="w-100 h-100 align-middle text-center" href="{% url 'news:index' %}">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">{% trans 'Older ...' %}</h5>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
29
news/templates/news/index.html
Normal file
29
news/templates/news/index.html
Normal file
@@ -0,0 +1,29 @@
|
||||
{% extends 'base.html' %}
|
||||
{% load i18n ksp_filters %}
|
||||
|
||||
{% block body %}
|
||||
<div class="">
|
||||
<div class="row px-3">
|
||||
<h4>
|
||||
{% trans 'All' %}
|
||||
{% trans 'News' %}
|
||||
</h4>
|
||||
</div>
|
||||
<div class="col-md">
|
||||
{% for msg in news %}
|
||||
<div class="card col-md {{msg.importance|bootstrap_cls}}">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">
|
||||
<strong>{{msg.subject}}</strong>
|
||||
<br>
|
||||
<small> {% trans 'Published on' %} {{msg.publish_on}}</small>
|
||||
</h5>
|
||||
<small></small>
|
||||
<article class="card-text">{{msg.body|safe}}</article>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
<hr>
|
||||
{% endblock %}
|
||||
3
news/tests.py
Normal file
3
news/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
15
news/urls.py
Normal file
15
news/urls.py
Normal file
@@ -0,0 +1,15 @@
|
||||
"""
|
||||
Author: Michel Peltriaux
|
||||
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||
Contact: michel.peltriaux@sgdnord.rlp.de
|
||||
Created on: 06.07.21
|
||||
|
||||
"""
|
||||
from django.urls import path
|
||||
|
||||
from news.views import index_view
|
||||
|
||||
app_name="news"
|
||||
urlpatterns = [
|
||||
path("", index_view, name="index"),
|
||||
]
|
||||
34
news/views.py
Normal file
34
news/views.py
Normal file
@@ -0,0 +1,34 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user