* adds news app for future implementations
This commit is contained in:
mipel 2021-07-06 08:53:08 +02:00
parent 7968d7d355
commit 3277896ff1
14 changed files with 132 additions and 45 deletions

View File

@ -70,15 +70,3 @@ class Geometry(BaseResource):
Outsourced geometry model so multiple versions of the same object can refer to the same geometry if it is not changed
"""
geom = MultiPolygonField(null=True, blank=True)
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))

View File

@ -61,6 +61,7 @@ INSTALLED_APPS = [
'compensation',
'intervention',
'organisation',
'news',
]
if DEBUG:
INSTALLED_APPS += [
@ -101,6 +102,7 @@ TEMPLATES = [
},
},
]
WSGI_APPLICATION = 'konova.wsgi.application'

View File

@ -1,31 +1,9 @@
{% extends 'base.html' %}
{% load i18n ksp_filters %}
{% load i18n %}
{% block body %}
<div id="server-messages" class="row 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 'home' %}">
<div class="card-body">
<h5 class="card-title">{% trans 'Older ...' %}</h5>
</div>
</a>
</div>
</div>
</div>
{% include 'news/dashboard-news.html' %}
<hr>
<div id="quickstart" class="col-md px-3">
<h4 class="row">{% trans 'Quickstart' %}</h4>
<div class="row px-3">

View File

@ -34,6 +34,7 @@ urlpatterns = [
path('ema/', include("intervention.urls")), #ToDo
path('organisation/', include("organisation.urls")),
path('user/', include("intervention.urls")), #ToDo
path('news/', include("news.urls")),
# Autocomplete paths
path("atcmplt/orgs", OrganisationAutocomplete.as_view(), name="orgs-autocomplete"),

View File

@ -12,7 +12,7 @@ from django.shortcuts import redirect, render
from django.utils import timezone
from konova.contexts import BaseContext
from konova.models import ServerMessage
from news.models import ServerMessage
from konova.settings import SSO_SERVER_BASE

0
news/__init__.py Normal file
View File

View File

@ -1,13 +1,6 @@
"""
Author: Michel Peltriaux
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
Contact: michel.peltriaux@sgdnord.rlp.de
Created on: 05.07.21
"""
from django.contrib import admin
from konova.models import ServerMessage
from news.models import ServerMessage
class ServerMessageAdmin(admin.ModelAdmin):

5
news/apps.py Normal file
View File

@ -0,0 +1,5 @@
from django.apps import AppConfig
class NewsConfig(AppConfig):
name = 'news'

16
news/models.py Normal file
View 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))

View 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>

View 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
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

15
news/urls.py Normal file
View 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
View 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)