News app
* adds news app for future implementations
This commit is contained in:
parent
f069baa260
commit
b01442ef17
@ -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
|
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)
|
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))
|
|
||||||
|
@ -61,6 +61,7 @@ INSTALLED_APPS = [
|
|||||||
'compensation',
|
'compensation',
|
||||||
'intervention',
|
'intervention',
|
||||||
'organisation',
|
'organisation',
|
||||||
|
'news',
|
||||||
]
|
]
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
INSTALLED_APPS += [
|
INSTALLED_APPS += [
|
||||||
@ -101,6 +102,7 @@ TEMPLATES = [
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
WSGI_APPLICATION = 'konova.wsgi.application'
|
WSGI_APPLICATION = 'konova.wsgi.application'
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,31 +1,9 @@
|
|||||||
{% extends 'base.html' %}
|
{% extends 'base.html' %}
|
||||||
{% load i18n ksp_filters %}
|
{% load i18n %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<div id="server-messages" class="row px-3">
|
{% include 'news/dashboard-news.html' %}
|
||||||
<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>
|
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
<div id="quickstart" class="col-md px-3">
|
<div id="quickstart" class="col-md px-3">
|
||||||
<h4 class="row">{% trans 'Quickstart' %}</h4>
|
<h4 class="row">{% trans 'Quickstart' %}</h4>
|
||||||
<div class="row px-3">
|
<div class="row px-3">
|
||||||
|
@ -34,6 +34,7 @@ urlpatterns = [
|
|||||||
path('ema/', include("intervention.urls")), #ToDo
|
path('ema/', include("intervention.urls")), #ToDo
|
||||||
path('organisation/', include("organisation.urls")),
|
path('organisation/', include("organisation.urls")),
|
||||||
path('user/', include("intervention.urls")), #ToDo
|
path('user/', include("intervention.urls")), #ToDo
|
||||||
|
path('news/', include("news.urls")),
|
||||||
|
|
||||||
# Autocomplete paths
|
# Autocomplete paths
|
||||||
path("atcmplt/orgs", OrganisationAutocomplete.as_view(), name="orgs-autocomplete"),
|
path("atcmplt/orgs", OrganisationAutocomplete.as_view(), name="orgs-autocomplete"),
|
||||||
|
@ -12,7 +12,7 @@ from django.shortcuts import redirect, render
|
|||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
from konova.contexts import BaseContext
|
from konova.contexts import BaseContext
|
||||||
from konova.models import ServerMessage
|
from news.models import ServerMessage
|
||||||
from konova.settings import SSO_SERVER_BASE
|
from konova.settings import SSO_SERVER_BASE
|
||||||
|
|
||||||
|
|
||||||
|
0
news/__init__.py
Normal file
0
news/__init__.py
Normal 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 django.contrib import admin
|
||||||
|
|
||||||
from konova.models import ServerMessage
|
from news.models import ServerMessage
|
||||||
|
|
||||||
|
|
||||||
class ServerMessageAdmin(admin.ModelAdmin):
|
class ServerMessageAdmin(admin.ModelAdmin):
|
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)
|
Loading…
Reference in New Issue
Block a user