Refactoring to konova

This commit is contained in:
mipel
2021-07-01 15:08:22 +02:00
parent 947f50b11c
commit 972cbf5433
19 changed files with 94 additions and 263 deletions

View File

@@ -1,32 +0,0 @@
"""
Author: Michel Peltriaux
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
Contact: michel.peltriaux@sgdnord.rlp.de
Created on: 07.12.20
"""
from django.contrib import admin
from konova.models import RoleType, RoleGroup
class RoleTypeAdmin(admin.ModelAdmin):
list_display = [
"type",
"created_on",
"created_by",
]
class RoleGroupAdmin(admin.ModelAdmin):
list_display = [
"name",
"organisation",
"role",
]
admin.site.register(RoleType, RoleTypeAdmin)
admin.site.register(RoleGroup, RoleGroupAdmin)

View File

@@ -7,7 +7,6 @@ Created on: 07.12.20
"""
from dal_select2.views import Select2QuerySetView
from organisation.enums import OrganisationTypeEnum
from organisation.models import Organisation
@@ -33,9 +32,6 @@ class NonOfficialOrganisationAutocomplete(Select2QuerySetView):
qs = qs.filter(
name__icontains=self.q,
)
qs = qs.exclude(
type=OrganisationTypeEnum.OFFICIAL.value
)
qs = qs.order_by(
"name"
)

View File

@@ -9,14 +9,8 @@ Created on: 16.11.20
from abc import abstractmethod
from django import forms
from django.http import HttpRequest
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
from konova.models import RoleGroup
from konova.utils.session import set_session_user_role
from organisation.settings import ROLE_TYPE_STRINGS
class BaseForm(forms.Form):
"""
@@ -97,45 +91,3 @@ class RemoveForm(BaseForm):
self.object_to_remove.save()
return self.object_to_remove
class ChangeUserRoleForm(BaseForm):
"""
Form for a user to change the current role
"""
role = forms.ChoiceField(
label=_("You are working as"),
label_suffix="",
choices=[],
widget=forms.Select(
attrs={
"onchange": "submit();",
}
)
)
def __init__(self, *args, **kwargs):
user = kwargs.pop("user", None)
super().__init__(*args, **kwargs)
self.action_url = reverse("home")
self.cancel_redirect = reverse("home")
role_groups = RoleGroup.get_users_role_groups(user)
choices = []
for group in role_groups:
choices.append(
(group.id, "{} ({})".format(ROLE_TYPE_STRINGS.get(group.role.type, None), group.organisation))
)
self.fields["role"].choices = choices
def save(self, request: HttpRequest) -> RoleGroup:
""" Custom save method for storing the newly selected role
Args:
request (HttpRequest):
Returns:
"""
role_group = RoleGroup.get_users_role_groups(request.user).get(id=self.cleaned_data.get("role", -1))
set_session_user_role(request, role_group)
return role_group

View File

@@ -11,8 +11,7 @@ from django.contrib.auth.models import User
from django.core.management import BaseCommand
from django.db import transaction
from konova.management.commands.setup_test_data import TEST_ORGANISATION_DATA, TEST_ROLE_GROUPS_DATA
from konova.models import RoleType, RoleGroup
from konova.management.commands.setup_test_data import TEST_ORGANISATION_DATA
from organisation.models import Organisation
CREATED_TEMPLATE = "{} created"
@@ -26,7 +25,6 @@ class Command(BaseCommand):
with transaction.atomic():
self.__init_superuser()
self.__init_test_organisation()
self.__init_role_groups()
except KeyboardInterrupt:
self.__break_line()
exit(-1)
@@ -96,30 +94,6 @@ class Command(BaseCommand):
)
self.__break_line()
def __init_role_groups(self):
""" Creates test role groups from predefined data
Returns:
"""
self.stdout.write(
self.style.WARNING(
"--- Role Groups ---"
)
)
for group_data in TEST_ROLE_GROUPS_DATA:
group_data["organisation"] = Organisation.objects.get(name=group_data["organisation"])
group_data["role"] = RoleType.objects.get(type=group_data["role"])
group = RoleGroup.objects.get_or_create(
**group_data
)[0]
self.stdout.write(
self.style.SUCCESS(
CREATED_TEMPLATE.format(group.name)
)
)
self.__break_line()
def __break_line(self):
""" Simply prints a line break

View File

@@ -21,7 +21,7 @@ class BaseResource(models.Model):
default=uuid.uuid4,
)
created_on = models.DateTimeField(auto_now_add=True, null=True)
created_by = models.ForeignKey(User, null=True, on_delete=models.SET_NULL)
created_by = models.ForeignKey(User, null=True, on_delete=models.SET_NULL, related_name="+")
class Meta:
abstract = True
@@ -36,7 +36,7 @@ class BaseObject(BaseResource):
identifier = models.CharField(max_length=1000, null=True, blank=True)
title = models.CharField(max_length=1000, null=True, blank=True)
deleted_on = models.DateTimeField(null=True)
deleted_by = models.ForeignKey(User, null=True, on_delete=models.SET_NULL)
deleted_by = models.ForeignKey(User, null=True, on_delete=models.SET_NULL, related_name="+")
comment = models.TextField()
class Meta:
@@ -56,7 +56,7 @@ class Deadline(BaseResource):
class Document(BaseResource):
"""
Documents can be attached to process, compensation or intervention for uploading legal documents or pictures.
Documents can be attached to compensation or intervention for uploading legal documents or pictures.
"""
date_of_creation = models.DateField()
document = models.FileField()

View File

@@ -60,7 +60,6 @@ INSTALLED_APPS = [
'konova',
'compensation',
'intervention',
'process',
'organisation',
]
if DEBUG:

View File

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

View File

@@ -1,17 +0,0 @@
"""
Author: Michel Peltriaux
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
Contact: michel.peltriaux@sgdnord.rlp.de
Created on: 04.12.20
"""
from django import template
from process.settings import PROCESS_STATE_STRINGS
register = template.Library()
@register.filter
def resolve_process_state(value):
return PROCESS_STATE_STRINGS.get(value, None)

View File

@@ -30,10 +30,10 @@ urlpatterns = [
path('', home_view, name="home"),
path('intervention/', include("intervention.urls")),
path('compensation/', include("compensation.urls")),
path('eco-account/', include("process.urls")),
path('ema/', include("process.urls")),
path('eco-account/', include("intervention.urls")), #ToDo
path('ema/', include("intervention.urls")), #ToDo
path('organisation/', include("organisation.urls")),
path('user/', include("process.urls")),
path('user/', include("intervention.urls")), #ToDo
# Autocomplete paths
path("atcmplt/orgs", OrganisationAutocomplete.as_view(), name="orgs-autocomplete"),

View File

@@ -1,45 +0,0 @@
"""
Author: Michel Peltriaux
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
Contact: michel.peltriaux@sgdnord.rlp.de
Created on: 09.12.20
"""
from django.http import HttpRequest
from idna import unicode
from konova.models import RoleGroup
from organisation.settings import ROLE_TYPE_STRINGS
CURRENT_ROLE_ID = "current_role"
def set_session_user_role(request: HttpRequest, role_group: RoleGroup) -> dict:
""" Set the user session to an active role
Args:
request (HttpRequest): The user request
role_group (RoleGroup): The selected role group
Returns:
"""
current_role = {}
if role_group is not None:
current_role["type"] = unicode(ROLE_TYPE_STRINGS.get(role_group.role.type))
current_role["org"] = role_group.organisation.__str__()
current_role["id"] = role_group.id
request.session[CURRENT_ROLE_ID] = current_role
return current_role
def get_session_user_role(request: HttpRequest) -> dict:
""" Returns the current role chosen by a user for this session
Args:
request (HttpRequest): The used request
Returns:
"""
return request.session.get(CURRENT_ROLE_ID, {})

View File

@@ -5,16 +5,12 @@ Contact: michel.peltriaux@sgdnord.rlp.de
Created on: 16.11.20
"""
from django.utils.translation import gettext_lazy as _
from django.contrib import messages
from django.contrib.auth import logout
from django.http import HttpRequest
from django.shortcuts import redirect, render
from konova.contexts import BaseContext
from konova.forms import ChangeUserRoleForm
from konova.settings import SSO_SERVER_BASE
from konova.utils.session import get_session_user_role
def logout_view(request: HttpRequest):