Landing page

* started to implement a landing page
* started news implementation
This commit is contained in:
mipel
2021-07-05 14:49:32 +02:00
parent b59b9839ff
commit f069baa260
12 changed files with 213 additions and 75 deletions

21
konova/admin.py Normal file
View File

@@ -0,0 +1,21 @@
"""
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
class ServerMessageAdmin(admin.ModelAdmin):
list_display = [
"id",
"subject",
"publish_on",
"is_active",
]
admin.site.register(ServerMessage, ServerMessageAdmin)

View File

@@ -37,4 +37,13 @@ class UnitEnum(BaseEnum):
qkm = "qkm"
ha = "ha"
st = "St." # pieces
st = "St." # pieces
class ServerMessageImportance(BaseEnum):
"""
Defines importance levels for server messages
"""
DEFAULT = "DEFAULT"
INFO = "INFO"
WARNING = "WARNING"

View File

@@ -11,6 +11,8 @@ from django.contrib.auth.models import User
from django.contrib.gis.db.models import MultiPolygonField
from django.db import models
from konova.enums import ServerMessageImportance
class BaseResource(models.Model):
"""
@@ -69,3 +71,14 @@ class Geometry(BaseResource):
"""
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

@@ -12,6 +12,7 @@ https://docs.djangoproject.com/en/3.1/ref/settings/
from django.utils.translation import gettext_lazy as _
# Load other settings
from konova.enums import ServerMessageImportance
from konova.sub_settings.django_settings import *
# Num of days if user enables Remember-me on login
@@ -54,3 +55,10 @@ DEFAULT_ZOOM = 8.0
DEFAULT_GROUP = _("Default")
ZB_GROUP = _("Registration office")
ETS_GROUP = _("Conservation office")
# ServerMessageImportance bootstrap resolver
SVI_BOOTSTRAP_CLS_MAP = {
ServerMessageImportance.DEFAULT.value: None,
ServerMessageImportance.WARNING.value: "alert-danger",
ServerMessageImportance.INFO.value: "alert-info",
}

View File

@@ -18,6 +18,10 @@ body{
margin-bottom: 40px; /* Margin bottom by footer height */
}
.body-content{
margin: 1rem 0rem 0 0rem;
}
.footer {
position: absolute;
bottom: 0;
@@ -63,4 +67,18 @@ nav{
Overwrites bootstrap default nav-link colouring
*/
color: white;
}
.card{
margin: 0 0.5rem 0.5rem 0;
font-size: 12px;
}
.card:hover{
box-shadow: 1px 1px 3px var(--rlp-gray-light);
}
.card .card-text{
font-size: 12px;
max-height: 150px;
overflow: auto;
}

View File

@@ -1,44 +1,38 @@
{% extends 'base.html' %}
{% load i18n %}
{% load i18n ksp_filters %}
{% block body_middle %}
<h1>Kompensationsverzeichnis</h1>
<h2>Service Portal</h2>
<hr>
{% if user.is_anonymous %}
<a href="{% url 'simple-sso-login' %}">
<button class="button middle">
{% trans 'Proceed with login' %}
</button>
</a>
{% else %}
<article>
{% trans 'Logged in as' %} <strong>{{ user.username }}</strong>
<br>
{% trans 'Last login on' %} {{ user.last_login }}
</article>
<form action="{{form.action_url}}" method="post">
{% csrf_token %}
<table>
{% comment %}
This is an alternative to using the <article></article>
<tr>
<td>{% trans 'Logged in as' %}</td>
<td><strong>{{ user.username }}</strong></td>
</tr>
<tr>
<td>{% trans 'Last login on' %}</td>
<td><strong>{{ user.last_login }}</strong></td>
</tr>
{% endcomment %}
{% for field in form %}
<tr>
<td>{{ field.label }}</td>
<td>{{ field }}</td>
</tr>
{% 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 %}
</table>
</form>
{% endif %}
<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>
<div id="quickstart" class="col-md px-3">
<h4 class="row">{% trans 'Quickstart' %}</h4>
<div class="row px-3">
<div class="col-md">{% trans 'Intervention' %}</div>
<div class="col-md">{% trans 'Compensation' %}</div>
<div class="col-md">{% trans 'Eco-account' %}</div>
</div>
</div>
{% endblock %}

View File

@@ -0,0 +1,7 @@
"""
Author: Michel Peltriaux
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
Contact: michel.peltriaux@sgdnord.rlp.de
Created on: 05.07.21
"""

View File

@@ -0,0 +1,28 @@
"""
Author: Michel Peltriaux
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
Contact: michel.peltriaux@sgdnord.rlp.de
Created on: 05.07.21
"""
from django import template
from konova.settings import SVI_BOOTSTRAP_CLS_MAP
# Create custom library
register = template.Library()
@register.filter("bootstrap_cls")
def bootstrap_cls(value):
""" Returns a bootstrap html class name
Resolves ServerMessageImportance enum into a html class name
Args:
value ():
arg ():
Returns:
"""
return SVI_BOOTSTRAP_CLS_MAP.get(value, "")

View File

@@ -9,8 +9,10 @@ from django.contrib.auth import logout
from django.contrib.auth.decorators import login_required
from django.http import HttpRequest
from django.shortcuts import redirect, render
from django.utils import timezone
from konova.contexts import BaseContext
from konova.models import ServerMessage
from konova.settings import SSO_SERVER_BASE
@@ -40,7 +42,18 @@ def home_view(request: HttpRequest):
A redirect
"""
template = "konova/home.html"
now = timezone.now()
# Fetch the four newest active and published ServerMessages
msgs = ServerMessage.objects.filter(
is_active=True,
publish_on__lte=now,
unpublish_on__gte=now,
).order_by(
"-publish_on"
)[:4]
additional_context = {}
additional_context = {
"msgs": msgs,
}
context = BaseContext(request, additional_context).context
return render(request, template, context)