From b01442ef171610a34a609d814e6f311cc242a496 Mon Sep 17 00:00:00 2001 From: mipel Date: Tue, 6 Jul 2021 08:53:08 +0200 Subject: [PATCH] News app * adds news app for future implementations --- konova/models.py | 12 --------- konova/sub_settings/django_settings.py | 2 ++ konova/templates/konova/home.html | 26 ++----------------- konova/urls.py | 1 + konova/views.py | 2 +- news/__init__.py | 0 {konova => news}/admin.py | 9 +------ news/apps.py | 5 ++++ news/models.py | 16 ++++++++++++ news/templates/news/dashboard-news.html | 23 +++++++++++++++++ news/templates/news/index.html | 29 +++++++++++++++++++++ news/tests.py | 3 +++ news/urls.py | 15 +++++++++++ news/views.py | 34 +++++++++++++++++++++++++ 14 files changed, 132 insertions(+), 45 deletions(-) create mode 100644 news/__init__.py rename {konova => news}/admin.py (51%) create mode 100644 news/apps.py create mode 100644 news/models.py create mode 100644 news/templates/news/dashboard-news.html create mode 100644 news/templates/news/index.html create mode 100644 news/tests.py create mode 100644 news/urls.py create mode 100644 news/views.py diff --git a/konova/models.py b/konova/models.py index bb7eebb2..86587627 100644 --- a/konova/models.py +++ b/konova/models.py @@ -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)) diff --git a/konova/sub_settings/django_settings.py b/konova/sub_settings/django_settings.py index 3a3d7afd..7f54d48f 100644 --- a/konova/sub_settings/django_settings.py +++ b/konova/sub_settings/django_settings.py @@ -61,6 +61,7 @@ INSTALLED_APPS = [ 'compensation', 'intervention', 'organisation', + 'news', ] if DEBUG: INSTALLED_APPS += [ @@ -101,6 +102,7 @@ TEMPLATES = [ }, }, ] + WSGI_APPLICATION = 'konova.wsgi.application' diff --git a/konova/templates/konova/home.html b/konova/templates/konova/home.html index 87b2554a..26dffba1 100644 --- a/konova/templates/konova/home.html +++ b/konova/templates/konova/home.html @@ -1,31 +1,9 @@ {% extends 'base.html' %} -{% load i18n ksp_filters %} +{% load i18n %} {% block body %} -
-

{% trans 'News' %}

-
- {% for msg in msgs %} -
-
-
{{msg.subject}}
- {% trans 'Published on' %} {{msg.publish_on}} -
{{msg.body|safe}}
-
-
- {% endfor %} - -
-
- + {% include 'news/dashboard-news.html' %}
-

{% trans 'Quickstart' %}

diff --git a/konova/urls.py b/konova/urls.py index 42c39082..96a0de04 100644 --- a/konova/urls.py +++ b/konova/urls.py @@ -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"), diff --git a/konova/views.py b/konova/views.py index daaa447a..5d47a1c3 100644 --- a/konova/views.py +++ b/konova/views.py @@ -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 diff --git a/news/__init__.py b/news/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/konova/admin.py b/news/admin.py similarity index 51% rename from konova/admin.py rename to news/admin.py index a5c81175..b4508cc1 100644 --- a/konova/admin.py +++ b/news/admin.py @@ -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): diff --git a/news/apps.py b/news/apps.py new file mode 100644 index 00000000..5a7b92d0 --- /dev/null +++ b/news/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class NewsConfig(AppConfig): + name = 'news' diff --git a/news/models.py b/news/models.py new file mode 100644 index 00000000..2030c074 --- /dev/null +++ b/news/models.py @@ -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)) \ No newline at end of file diff --git a/news/templates/news/dashboard-news.html b/news/templates/news/dashboard-news.html new file mode 100644 index 00000000..eb6df5ab --- /dev/null +++ b/news/templates/news/dashboard-news.html @@ -0,0 +1,23 @@ +{% load i18n ksp_filters %} + +
+

{% trans 'News' %}

+
+ {% for msg in msgs %} +
+
+
{{msg.subject}}
+ {% trans 'Published on' %} {{msg.publish_on}} +
{{msg.body|safe}}
+
+
+ {% endfor %} + +
+
\ No newline at end of file diff --git a/news/templates/news/index.html b/news/templates/news/index.html new file mode 100644 index 00000000..d4b16478 --- /dev/null +++ b/news/templates/news/index.html @@ -0,0 +1,29 @@ +{% extends 'base.html' %} +{% load i18n ksp_filters %} + +{% block body %} +
+
+

+ {% trans 'All' %} + {% trans 'News' %} +

+
+
+ {% for msg in news %} +
+
+
+ {{msg.subject}} +
+ {% trans 'Published on' %} {{msg.publish_on}} +
+ +
{{msg.body|safe}}
+
+
+ {% endfor %} +
+
+
+{% endblock %} \ No newline at end of file diff --git a/news/tests.py b/news/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/news/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/news/urls.py b/news/urls.py new file mode 100644 index 00000000..c7a827f3 --- /dev/null +++ b/news/urls.py @@ -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"), +] \ No newline at end of file diff --git a/news/views.py b/news/views.py new file mode 100644 index 00000000..d386de01 --- /dev/null +++ b/news/views.py @@ -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)