# 63 Refactoring
* refactors django User model to custom User model to provide further attributes and methods directly on the user model
This commit is contained in:
parent
31b3428146
commit
ef65869c7c
@ -6,7 +6,7 @@ Created on: 04.12.20
|
||||
|
||||
"""
|
||||
from dal import autocomplete
|
||||
from django.contrib.auth.models import User
|
||||
from user.models import User
|
||||
from django.db import transaction
|
||||
from django.urls import reverse_lazy, reverse
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
@ -8,7 +8,7 @@ Created on: 16.11.21
|
||||
import shutil
|
||||
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.models import User
|
||||
from user.models import User
|
||||
from django.db import models, transaction
|
||||
from django.db.models import QuerySet, Sum
|
||||
from django.http import HttpRequest
|
||||
|
@ -7,7 +7,7 @@ Created on: 16.11.21
|
||||
"""
|
||||
import shutil
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from user.models import User
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core.validators import MinValueValidator
|
||||
from django.db import models, transaction
|
||||
|
@ -5,7 +5,7 @@ Contact: michel.peltriaux@sgdnord.rlp.de
|
||||
Created on: 01.12.20
|
||||
|
||||
"""
|
||||
from django.contrib.auth.models import User
|
||||
from user.models import User
|
||||
from django.http import HttpRequest
|
||||
from django.template.loader import render_to_string
|
||||
from django.urls import reverse
|
||||
|
@ -58,20 +58,8 @@ class EcoAccountQualityChecker(CompensationQualityChecker):
|
||||
self._check_deductable_surface()
|
||||
self._check_responsible_data()
|
||||
self._check_legal_data()
|
||||
self._check_record_state()
|
||||
super().run_check()
|
||||
|
||||
def _check_record_state(self):
|
||||
""" Checks the data quality for recorded state
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
if self.obj.recorded is None:
|
||||
self.messages.append(
|
||||
_("Not recorded")
|
||||
)
|
||||
|
||||
def _check_legal_data(self):
|
||||
""" Checks the data quality for Legal
|
||||
|
||||
|
@ -7,7 +7,7 @@ Created on: 06.10.21
|
||||
"""
|
||||
from dal import autocomplete
|
||||
from django import forms
|
||||
from django.contrib.auth.models import User
|
||||
from user.models import User
|
||||
from django.db import transaction
|
||||
from django.urls import reverse, reverse_lazy
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
@ -7,7 +7,7 @@ Created on: 02.12.20
|
||||
"""
|
||||
from dal import autocomplete
|
||||
from django import forms
|
||||
from django.contrib.auth.models import User
|
||||
from user.models import User
|
||||
from django.db import transaction
|
||||
from django.urls import reverse, reverse_lazy
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
@ -6,7 +6,7 @@ Created on: 27.09.21
|
||||
|
||||
"""
|
||||
from dal import autocomplete
|
||||
from django.contrib.auth.models import User
|
||||
from user.models import User
|
||||
from django.db import transaction
|
||||
from django import forms
|
||||
from django.urls import reverse
|
||||
|
@ -8,7 +8,7 @@ Created on: 15.11.21
|
||||
import shutil
|
||||
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.models import User
|
||||
from user.models import User
|
||||
from django.db import models, transaction
|
||||
from django.db.models import QuerySet
|
||||
from django.http import HttpRequest
|
||||
|
@ -6,7 +6,7 @@ Created on: 07.12.20
|
||||
|
||||
"""
|
||||
from dal_select2.views import Select2QuerySetView, Select2GroupQuerySetView
|
||||
from django.contrib.auth.models import User
|
||||
from user.models import User
|
||||
from django.db.models import Q
|
||||
|
||||
from codelist.models import KonovaCode
|
||||
|
@ -12,7 +12,7 @@ from bootstrap_modal_forms.forms import BSModalForm
|
||||
from bootstrap_modal_forms.utils import is_ajax
|
||||
from django import forms
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.models import User
|
||||
from user.models import User
|
||||
from django.contrib.gis.forms import OSMWidget, MultiPolygonField
|
||||
from django.contrib.gis.geos import MultiPolygon
|
||||
from django.db import transaction
|
||||
|
@ -7,7 +7,8 @@ Created on: 15.12.20
|
||||
"""
|
||||
from getpass import getpass
|
||||
|
||||
from django.contrib.auth.models import User, Group
|
||||
from user.models import User
|
||||
from django.contrib.auth.models import Group
|
||||
from django.core.management import BaseCommand, call_command
|
||||
from django.db import transaction
|
||||
|
||||
|
@ -23,8 +23,7 @@ GROUPS_DATA = [
|
||||
|
||||
# Must match with UserNotificationEnum
|
||||
USER_NOTIFICATIONS_NAMES = {
|
||||
"NOTIFY_ON_NEW_RELATED_DATA": _("On new related data"),
|
||||
"NOTIFY_ON_SHARE_LINK_DISABLED": _("On disabled share link"),
|
||||
"NOTIFY_ON_SHARED_ACCESS_GAINED": _("On shared access gained"),
|
||||
"NOTIFY_ON_SHARED_ACCESS_REMOVED": _("On shared access removed"),
|
||||
"NOTIFY_ON_SHARED_DATA_RECORDED": _("On shared data recorded"),
|
||||
"NOTIFY_ON_SHARED_DATA_DELETED": _("On shared data deleted"),
|
||||
|
@ -10,7 +10,7 @@ import uuid
|
||||
from abc import abstractmethod
|
||||
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.models import User
|
||||
from user.models import User
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.http import HttpRequest
|
||||
from django.utils.timezone import now
|
||||
@ -411,6 +411,11 @@ class ShareableObjectMixin(models.Model):
|
||||
users = User.objects.filter(
|
||||
id__in=accessing_users
|
||||
)
|
||||
removed_users = self.users.all().exclude(
|
||||
id__in=accessing_users
|
||||
)
|
||||
for user in removed_users:
|
||||
user.send_mail_shared_access_removed(self)
|
||||
self.share_with_list(users)
|
||||
|
||||
|
||||
|
@ -5,9 +5,10 @@ Contact: michel.peltriaux@sgdnord.rlp.de
|
||||
Created on: 17.08.21
|
||||
|
||||
"""
|
||||
from django.contrib.auth.models import User
|
||||
from simple_sso.sso_client.client import Client
|
||||
|
||||
from user.models import User
|
||||
|
||||
|
||||
class KonovaSSOClient(Client):
|
||||
""" Konova specialized derivate of general sso.Client.
|
||||
|
@ -129,7 +129,7 @@ DATABASES = {
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
|
||||
|
||||
AUTH_USER_MODEL = "user.User"
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||
|
@ -1,3 +1,5 @@
|
||||
from time import sleep
|
||||
|
||||
from celery import shared_task
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
|
||||
@ -5,10 +7,13 @@ from konova.models import Geometry
|
||||
|
||||
|
||||
@shared_task
|
||||
def celery_update_parcels(geometry_id: str):
|
||||
def celery_update_parcels(geometry_id: str, recheck: bool = True):
|
||||
try:
|
||||
geom = Geometry.objects.get(id=geometry_id)
|
||||
geom.parcels.clear()
|
||||
geom.update_parcels()
|
||||
except ObjectDoesNotExist:
|
||||
return
|
||||
if recheck:
|
||||
sleep(5)
|
||||
celery_update_parcels(geometry_id, False)
|
||||
|
||||
|
@ -7,7 +7,8 @@ Created on: 26.10.21
|
||||
"""
|
||||
import datetime
|
||||
|
||||
from django.contrib.auth.models import User, Group
|
||||
from user.models import User
|
||||
from django.contrib.auth.models import Group
|
||||
from django.contrib.gis.geos import MultiPolygon, Polygon
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.test import TestCase, Client
|
||||
|
@ -8,6 +8,8 @@ Created on: 09.11.20
|
||||
import logging
|
||||
|
||||
from django.core.mail import send_mail
|
||||
from django.template.loader import render_to_string
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from konova.sub_settings.django_settings import DEFAULT_FROM_EMAIL
|
||||
|
||||
@ -26,18 +28,13 @@ class Mailer:
|
||||
auth_user = None
|
||||
auth_password = None
|
||||
|
||||
def __init__(self, to_mail: list, from_mail: str = DEFAULT_FROM_EMAIL, auth_user: str = None, auth_password: str = None, fail_silently: bool = False):
|
||||
# Make sure given to_mail parameter is a list
|
||||
if isinstance(to_mail, str):
|
||||
to_mail = [to_mail]
|
||||
|
||||
def __init__(self, from_mail: str = DEFAULT_FROM_EMAIL, auth_user: str = None, auth_password: str = None, fail_silently: bool = False):
|
||||
self.from_mail = from_mail
|
||||
self.to_mail = to_mail
|
||||
self.fail_silently = fail_silently
|
||||
self.auth_user = auth_user
|
||||
self.auth_password = auth_password
|
||||
|
||||
def send(self, subject: str, msg: str):
|
||||
def send(self, recipient_list: list, subject: str, msg: str):
|
||||
"""
|
||||
Sends a mail with subject and message
|
||||
"""
|
||||
@ -45,8 +42,30 @@ class Mailer:
|
||||
subject=subject,
|
||||
message=msg,
|
||||
from_email=self.from_mail,
|
||||
recipient_list=self.to_mail,
|
||||
recipient_list=recipient_list,
|
||||
fail_silently=self.fail_silently,
|
||||
auth_user=self.auth_user,
|
||||
auth_password=self.auth_password
|
||||
)
|
||||
|
||||
def send_mail_shared_access_removed(self, obj, user):
|
||||
""" Send a mail if user has no access to the object anymore
|
||||
|
||||
Args:
|
||||
obj ():
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
context = {
|
||||
"user": user,
|
||||
"obj": obj,
|
||||
}
|
||||
msg = render_to_string("email/sharing/shared_access_removed.html", context)
|
||||
user_mail_address = [user.email]
|
||||
self.send(
|
||||
user_mail_address,
|
||||
_("{} - Shared access removed").format(obj.identifier),
|
||||
msg
|
||||
)
|
||||
|
||||
|
@ -8,7 +8,7 @@ Created on: 17.08.21
|
||||
from collections import Iterable
|
||||
|
||||
import requests
|
||||
from django.contrib.auth.models import User
|
||||
from user.models import User
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from konova.settings import SSO_SERVER_BASE, SSO_PUBLIC_KEY, PROXIES
|
||||
|
@ -5,7 +5,7 @@ Contact: michel.peltriaux@sgdnord.rlp.de
|
||||
Created on: 02.07.21
|
||||
|
||||
"""
|
||||
from django.contrib.auth.models import User
|
||||
from user.models import User
|
||||
|
||||
from konova.settings import ETS_GROUP, ZB_GROUP
|
||||
|
||||
|
Binary file not shown.
@ -3,26 +3,30 @@
|
||||
# This file is distributed under the same license as the PACKAGE package.
|
||||
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
||||
#
|
||||
#: compensation/filters.py:91 compensation/forms/modalForms.py:34
|
||||
#: compensation/filters.py:122 compensation/forms/modalForms.py:34
|
||||
#: compensation/forms/modalForms.py:45 compensation/forms/modalForms.py:61
|
||||
#: compensation/forms/modalForms.py:238 compensation/forms/modalForms.py:316
|
||||
#: intervention/forms/forms.py:52 intervention/forms/forms.py:154
|
||||
#: intervention/forms/forms.py:166 intervention/forms/modalForms.py:125
|
||||
#: intervention/forms/modalForms.py:138 intervention/forms/modalForms.py:151
|
||||
#: konova/filters.py:63 konova/filters.py:64 konova/filters.py:91
|
||||
#: konova/filters.py:92 konova/filters.py:104 konova/filters.py:105
|
||||
#: konova/filters.py:117 konova/filters.py:118 konova/filters.py:130
|
||||
#: konova/filters.py:131 konova/filters.py:144 konova/filters.py:145
|
||||
#: konova/filters.py:280 konova/filters.py:324 konova/forms.py:140
|
||||
#: konova/forms.py:241 konova/forms.py:312 konova/forms.py:339
|
||||
#: konova/forms.py:349 konova/forms.py:362 konova/forms.py:374
|
||||
#: konova/forms.py:392 user/forms.py:38
|
||||
#: konova/filters/mixins.py:53 konova/filters/mixins.py:54
|
||||
#: konova/filters/mixins.py:81 konova/filters/mixins.py:82
|
||||
#: konova/filters/mixins.py:94 konova/filters/mixins.py:95
|
||||
#: konova/filters/mixins.py:107 konova/filters/mixins.py:108
|
||||
#: konova/filters/mixins.py:120 konova/filters/mixins.py:121
|
||||
#: konova/filters/mixins.py:134 konova/filters/mixins.py:135
|
||||
#: konova/filters/mixins.py:270 konova/filters/mixins.py:315
|
||||
#: konova/filters/mixins.py:353 konova/filters/mixins.py:354
|
||||
#: konova/filters/mixins.py:385 konova/filters/mixins.py:386
|
||||
#: konova/forms.py:140 konova/forms.py:241 konova/forms.py:312
|
||||
#: konova/forms.py:339 konova/forms.py:349 konova/forms.py:362
|
||||
#: konova/forms.py:374 konova/forms.py:392 user/forms.py:38
|
||||
#, fuzzy
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2022-01-11 17:07+0100\n"
|
||||
"POT-Creation-Date: 2022-01-12 11:33+0100\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
@ -48,7 +52,7 @@ msgstr "Bis"
|
||||
#: intervention/forms/forms.py:100
|
||||
#: intervention/templates/intervention/detail/view.html:56
|
||||
#: intervention/templates/intervention/report/report.html:37
|
||||
#: intervention/utils/quality.py:49
|
||||
#: intervention/utils/quality.py:49 konova/filters/mixins.py:395
|
||||
msgid "Conservation office"
|
||||
msgstr "Eintragungsstelle"
|
||||
|
||||
@ -301,7 +305,7 @@ msgstr "Altfälle"
|
||||
msgid "Before"
|
||||
msgstr "Vor"
|
||||
|
||||
#: compensation/filters.py:90
|
||||
#: compensation/filters.py:121
|
||||
msgid "Show only unrecorded"
|
||||
msgstr "Nur unverzeichnete anzeigen"
|
||||
|
||||
@ -1218,7 +1222,7 @@ msgstr "Mehrfachauswahl möglich"
|
||||
#: intervention/forms/forms.py:84
|
||||
#: intervention/templates/intervention/detail/view.html:48
|
||||
#: intervention/templates/intervention/report/report.html:29
|
||||
#: intervention/utils/quality.py:46
|
||||
#: intervention/utils/quality.py:46 konova/filters/mixins.py:363
|
||||
msgid "Registration office"
|
||||
msgstr "Zulassungsbehörde"
|
||||
|
||||
@ -1508,62 +1512,73 @@ msgstr ""
|
||||
"somit nichts eingeben, bearbeiten oder sonstige Aktionen ausführen. "
|
||||
"Kontaktieren Sie bitte einen Administrator. +++"
|
||||
|
||||
#: konova/filters.py:67
|
||||
#: konova/filters/mixins.py:57
|
||||
msgid "File number"
|
||||
msgstr "Aktenzeichen"
|
||||
|
||||
#: konova/filters.py:68
|
||||
#: konova/filters/mixins.py:58
|
||||
msgid "Search for file number"
|
||||
msgstr "Nach Aktenzeichen suchen"
|
||||
|
||||
#: konova/filters.py:95
|
||||
#: konova/filters/mixins.py:85
|
||||
msgid "District"
|
||||
msgstr "Kreis"
|
||||
|
||||
#: konova/filters.py:96
|
||||
#: konova/filters/mixins.py:86
|
||||
msgid "Search for district"
|
||||
msgstr "Nach Kreis suchen"
|
||||
|
||||
#: konova/filters.py:108
|
||||
#: konova/filters/mixins.py:98
|
||||
msgid "Parcel gmrkng"
|
||||
msgstr "Gemarkung"
|
||||
|
||||
#: konova/filters.py:109
|
||||
#: konova/filters/mixins.py:99
|
||||
msgid "Search for parcel gmrkng"
|
||||
msgstr "Nach Gemarkung suchen"
|
||||
|
||||
#: konova/filters.py:121 konova/templates/konova/includes/parcels.html:18
|
||||
#: konova/filters/mixins.py:111
|
||||
#: konova/templates/konova/includes/parcels.html:18
|
||||
msgid "Parcel"
|
||||
msgstr "Flur"
|
||||
|
||||
#: konova/filters.py:122
|
||||
#: konova/filters/mixins.py:112
|
||||
msgid "Search for parcel"
|
||||
msgstr "Nach Flur suchen"
|
||||
|
||||
#: konova/filters.py:134 konova/templates/konova/includes/parcels.html:19
|
||||
#: konova/filters/mixins.py:124
|
||||
#: konova/templates/konova/includes/parcels.html:19
|
||||
msgid "Parcel counter"
|
||||
msgstr "Flurstückzähler"
|
||||
|
||||
#: konova/filters.py:135
|
||||
#: konova/filters/mixins.py:125
|
||||
msgid "Search for parcel counter"
|
||||
msgstr "Nach Flurstückzähler suchen"
|
||||
|
||||
#: konova/filters.py:148 konova/templates/konova/includes/parcels.html:20
|
||||
#: konova/filters/mixins.py:138
|
||||
#: konova/templates/konova/includes/parcels.html:20
|
||||
msgid "Parcel number"
|
||||
msgstr "Flurstücknenner"
|
||||
|
||||
#: konova/filters.py:149
|
||||
#: konova/filters/mixins.py:139
|
||||
msgid "Search for parcel number"
|
||||
msgstr "Nach Flurstücknenner suchen"
|
||||
|
||||
#: konova/filters.py:279
|
||||
#: konova/filters/mixins.py:269
|
||||
msgid "Show unshared"
|
||||
msgstr "Nicht freigegebene anzeigen"
|
||||
|
||||
#: konova/filters.py:323
|
||||
#: konova/filters/mixins.py:314
|
||||
msgid "Show recorded"
|
||||
msgstr "Verzeichnete anzeigen"
|
||||
|
||||
#: konova/filters/mixins.py:364
|
||||
msgid "Search for registration office"
|
||||
msgstr "Nach Zulassungsbehörde suchen"
|
||||
|
||||
#: konova/filters/mixins.py:396
|
||||
msgid "Search for conservation office"
|
||||
msgstr "Nch Eintragungsstelle suchen"
|
||||
|
||||
#: konova/forms.py:37 templates/form/collapsable/form.html:62
|
||||
msgid "Save"
|
||||
msgstr "Speichern"
|
||||
@ -1644,26 +1659,22 @@ msgstr ""
|
||||
"Ich, {} {}, bestätige, dass diese Daten wieder entzeichnet werden müssen."
|
||||
|
||||
#: konova/management/commands/setup_data.py:26
|
||||
msgid "On new related data"
|
||||
msgstr "Wenn neue Daten für mich angelegt werden"
|
||||
msgid "On shared access gained"
|
||||
msgstr "Wenn mir eine Freigabe zu Daten erteilt wird"
|
||||
|
||||
#: konova/management/commands/setup_data.py:27
|
||||
msgid "On disabled share link"
|
||||
msgstr "Wenn ein Freigabelink deaktiviert wird"
|
||||
|
||||
#: konova/management/commands/setup_data.py:28
|
||||
msgid "On shared access removed"
|
||||
msgstr "Wenn mir eine Freigabe zu Daten entzogen wird"
|
||||
|
||||
#: konova/management/commands/setup_data.py:29
|
||||
#: konova/management/commands/setup_data.py:28
|
||||
msgid "On shared data recorded"
|
||||
msgstr "Wenn meine freigegebenen Daten verzeichnet wurden"
|
||||
|
||||
#: konova/management/commands/setup_data.py:30
|
||||
#: konova/management/commands/setup_data.py:29
|
||||
msgid "On shared data deleted"
|
||||
msgstr "Wenn meine freigegebenen Daten gelöscht wurden"
|
||||
|
||||
#: konova/management/commands/setup_data.py:31
|
||||
#: konova/management/commands/setup_data.py:30
|
||||
msgid "On registered data edited"
|
||||
msgstr "Wenn meine freigegebenen Daten bearbeitet wurden"
|
||||
|
||||
@ -1906,35 +1917,35 @@ msgstr "Abbrechen"
|
||||
msgid "Fields with * are required."
|
||||
msgstr "* sind Pflichtfelder."
|
||||
|
||||
#: templates/generic_index.html:28
|
||||
#: templates/generic_index.html:39
|
||||
msgid "New entry"
|
||||
msgstr "Neuer Eintrag"
|
||||
|
||||
#: templates/generic_index.html:30
|
||||
#: templates/generic_index.html:41
|
||||
msgid "New"
|
||||
msgstr "Neu"
|
||||
|
||||
#: templates/generic_index.html:45
|
||||
#: templates/generic_index.html:56
|
||||
msgid "Search for keywords"
|
||||
msgstr "Nach Schlagwörtern suchen"
|
||||
|
||||
#: templates/generic_index.html:45
|
||||
#: templates/generic_index.html:56
|
||||
msgid "Search"
|
||||
msgstr "Suchen"
|
||||
|
||||
#: templates/generic_index.html:46
|
||||
#: templates/generic_index.html:57
|
||||
msgid "Start search"
|
||||
msgstr "Starte Suche"
|
||||
|
||||
#: templates/generic_index.html:58
|
||||
#: templates/generic_index.html:69
|
||||
msgid "Results per page"
|
||||
msgstr "Treffer pro Seite"
|
||||
|
||||
#: templates/generic_index.html:82 templates/generic_index.html:99
|
||||
#: templates/generic_index.html:93 templates/generic_index.html:118
|
||||
msgid "Filter"
|
||||
msgstr ""
|
||||
|
||||
#: templates/generic_index.html:101
|
||||
#: templates/generic_index.html:120
|
||||
msgid "Apply filter"
|
||||
msgstr "Filter anwenden"
|
||||
|
||||
@ -3591,6 +3602,12 @@ msgstr ""
|
||||
msgid "Unable to connect to qpid with SASL mechanism %s"
|
||||
msgstr ""
|
||||
|
||||
#~ msgid "On new related data"
|
||||
#~ msgstr "Wenn neue Daten für mich angelegt werden"
|
||||
|
||||
#~ msgid "On disabled share link"
|
||||
#~ msgstr "Wenn ein Freigabelink deaktiviert wird"
|
||||
|
||||
#~ msgid "Deduct"
|
||||
#~ msgstr "Abbuchen"
|
||||
|
||||
|
0
templates/email/sharing/shared_access_removed.html
Normal file
0
templates/email/sharing/shared_access_removed.html
Normal file
@ -1,6 +1,6 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from user.models import UserNotification, KonovaUserExtension, UserActionLogEntry
|
||||
from user.models import UserNotification, UserActionLogEntry, User
|
||||
|
||||
|
||||
class UserNotificationAdmin(admin.ModelAdmin):
|
||||
@ -11,9 +11,13 @@ class UserNotificationAdmin(admin.ModelAdmin):
|
||||
]
|
||||
|
||||
|
||||
class KonovaUserExtensionAdmin(admin.ModelAdmin):
|
||||
class UserAdmin(admin.ModelAdmin):
|
||||
list_display = [
|
||||
"user",
|
||||
"id",
|
||||
"username",
|
||||
"first_name",
|
||||
"last_name",
|
||||
"email",
|
||||
]
|
||||
|
||||
|
||||
@ -27,5 +31,5 @@ class UserActionLogEntryAdmin(admin.ModelAdmin):
|
||||
|
||||
|
||||
admin.site.register(UserNotification, UserNotificationAdmin)
|
||||
admin.site.register(KonovaUserExtension, KonovaUserExtensionAdmin)
|
||||
admin.site.register(UserActionLogEntry, UserActionLogEntryAdmin)
|
||||
admin.site.register(User, UserAdmin)
|
@ -9,9 +9,8 @@ from konova.enums import BaseEnum
|
||||
|
||||
|
||||
class UserNotificationEnum(BaseEnum):
|
||||
NOTIFY_ON_NEW_RELATED_DATA = "NOTIFY_ON_NEW_RELATED_DATA" # notifies in case new data has been added which is related to the user's organisation
|
||||
NOTIFY_ON_SHARE_LINK_DISABLED = "NOTIFY_ON_SHARE_LINK_DISABLED" # notifies in case share link for data has been disabled
|
||||
NOTIFY_ON_SHARED_ACCESS_REMOVED = "NOTIFY_ON_SHARED_ACCESS_REMOVED" # notifies in case shared access to data has been removed
|
||||
NOTIFY_ON_SHARED_DATA_RECORDED = "NOTIFY_ON_SHARED_DATA_RECORDED" # notifies in case data has been "verzeichnet"
|
||||
NOTIFY_ON_SHARED_DATA_DELETED = "NOTIFY_ON_SHARED_DATA_DELETED" # notifies in case data has been deleted
|
||||
NOTIFY_ON_REGISTERED_DATA_EDITED = "NOTIFY_ON_REGISTERED_DATA_EDITED" # notifies in case registered ("verzeichnet") data has been edited
|
||||
NOTIFY_ON_SHARED_ACCESS_GAINED = "NOTIFY_ON_SHARED_ACCESS_GAINED" # notifies in case new access has been gained
|
@ -8,10 +8,10 @@ Created on: 08.07.21
|
||||
from django import forms
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.contrib.auth.models import User
|
||||
from user.models import User
|
||||
|
||||
from konova.forms import BaseForm, BaseModalForm
|
||||
from user.models import UserNotification, KonovaUserExtension
|
||||
from user.models import UserNotification
|
||||
|
||||
|
||||
class UserNotificationForm(BaseForm):
|
||||
@ -50,11 +50,7 @@ class UserNotificationForm(BaseForm):
|
||||
)
|
||||
self.fields["notifications"].choices = choices
|
||||
|
||||
# Set currently selected notifications as initial
|
||||
self.konova_extension = KonovaUserExtension.objects.get_or_create(
|
||||
user=user
|
||||
)[0]
|
||||
users_current_notifications = self.konova_extension.notifications.all()
|
||||
users_current_notifications = self.user.notifications.all()
|
||||
users_current_notifications = [str(n.id) for n in users_current_notifications]
|
||||
self.fields["notifications"].initial = users_current_notifications
|
||||
|
||||
@ -68,7 +64,7 @@ class UserNotificationForm(BaseForm):
|
||||
notifications = UserNotification.objects.filter(
|
||||
id__in=selected_notification_ids,
|
||||
)
|
||||
self.konova_extension.notifications.set(notifications)
|
||||
self.user.notifications.set(notifications)
|
||||
|
||||
|
||||
class UserContactForm(BaseModalForm):
|
||||
|
@ -6,5 +6,5 @@ Created on: 15.11.21
|
||||
|
||||
"""
|
||||
from .user_action import *
|
||||
from .konova_user import *
|
||||
from .user import *
|
||||
from .notification import *
|
||||
|
@ -1,19 +0,0 @@
|
||||
"""
|
||||
Author: Michel Peltriaux
|
||||
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||
Contact: michel.peltriaux@sgdnord.rlp.de
|
||||
Created on: 15.11.21
|
||||
|
||||
"""
|
||||
from django.contrib.auth.models import User
|
||||
from django.db import models
|
||||
|
||||
|
||||
class KonovaUserExtension(models.Model):
|
||||
""" Extension model for additional ksp features
|
||||
|
||||
Extends the default user model for some extras
|
||||
|
||||
"""
|
||||
user = models.OneToOneField(User, on_delete=models.CASCADE)
|
||||
notifications = models.ManyToManyField("user.UserNotification", related_name="+")
|
28
user/models/user.py
Normal file
28
user/models/user.py
Normal file
@ -0,0 +1,28 @@
|
||||
"""
|
||||
Author: Michel Peltriaux
|
||||
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||
Contact: michel.peltriaux@sgdnord.rlp.de
|
||||
Created on: 15.11.21
|
||||
|
||||
"""
|
||||
from django.contrib.auth.models import AbstractUser
|
||||
|
||||
from django.db import models
|
||||
|
||||
from konova.utils.mailer import Mailer
|
||||
|
||||
|
||||
class User(AbstractUser):
|
||||
notifications = models.ManyToManyField("user.UserNotification", related_name="+", blank=True)
|
||||
|
||||
def send_mail_shared_access_removed(self, obj):
|
||||
""" Sends a mail to the user in case of removed shared access
|
||||
|
||||
Args:
|
||||
obj ():
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
mailer = Mailer()
|
||||
mailer.send_mail_shared_access_removed(obj, self)
|
@ -7,7 +7,6 @@ Created on: 15.11.21
|
||||
"""
|
||||
import uuid
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
@ -34,7 +33,7 @@ class UserActionLogEntry(models.Model):
|
||||
primary_key=True,
|
||||
default=uuid.uuid4,
|
||||
)
|
||||
user = models.ForeignKey(User, related_name='+', on_delete=models.CASCADE, help_text="Performing user")
|
||||
user = models.ForeignKey("user.User", related_name='+', on_delete=models.CASCADE, help_text="Performing user")
|
||||
timestamp = models.DateTimeField(auto_now_add=True, help_text="Timestamp of performed action")
|
||||
action = models.CharField(
|
||||
max_length=255,
|
||||
@ -69,7 +68,7 @@ class UserActionLogEntry(models.Model):
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def get_created_action(cls, user: User, comment: str = None):
|
||||
def get_created_action(cls, user, comment: str = None):
|
||||
action = UserActionLogEntry.objects.create(
|
||||
user=user,
|
||||
action=UserAction.CREATED,
|
||||
@ -78,7 +77,7 @@ class UserActionLogEntry(models.Model):
|
||||
return action
|
||||
|
||||
@classmethod
|
||||
def get_edited_action(cls, user: User, comment: str = None):
|
||||
def get_edited_action(cls, user, comment: str = None):
|
||||
action = UserActionLogEntry.objects.create(
|
||||
user=user,
|
||||
action=UserAction.EDITED,
|
||||
@ -87,7 +86,7 @@ class UserActionLogEntry(models.Model):
|
||||
return action
|
||||
|
||||
@classmethod
|
||||
def get_deleted_action(cls, user: User, comment: str = None):
|
||||
def get_deleted_action(cls, user, comment: str = None):
|
||||
action = UserActionLogEntry.objects.create(
|
||||
user=user,
|
||||
action=UserAction.DELETED,
|
||||
@ -96,7 +95,7 @@ class UserActionLogEntry(models.Model):
|
||||
return action
|
||||
|
||||
@classmethod
|
||||
def get_checked_action(cls, user: User, comment: str = None):
|
||||
def get_checked_action(cls, user, comment: str = None):
|
||||
action = UserActionLogEntry.objects.create(
|
||||
user=user,
|
||||
action=UserAction.CHECKED,
|
||||
@ -105,7 +104,7 @@ class UserActionLogEntry(models.Model):
|
||||
return action
|
||||
|
||||
@classmethod
|
||||
def get_recorded_action(cls, user: User, comment: str = None):
|
||||
def get_recorded_action(cls, user, comment: str = None):
|
||||
action = UserActionLogEntry.objects.create(
|
||||
user=user,
|
||||
action=UserAction.RECORDED,
|
||||
@ -114,7 +113,7 @@ class UserActionLogEntry(models.Model):
|
||||
return action
|
||||
|
||||
@classmethod
|
||||
def get_unrecorded_action(cls, user: User, comment: str = None):
|
||||
def get_unrecorded_action(cls, user, comment: str = None):
|
||||
action = UserActionLogEntry.objects.create(
|
||||
user=user,
|
||||
action=UserAction.UNRECORDED,
|
||||
|
@ -1,6 +1,6 @@
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.auth.models import User
|
||||
from user.models import User
|
||||
from django.http import HttpRequest
|
||||
from django.shortcuts import render, redirect, get_object_or_404
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
@ -8,7 +8,6 @@ from django.utils.translation import gettext_lazy as _
|
||||
from konova.contexts import BaseContext
|
||||
from konova.decorators import any_group_check
|
||||
from user.forms import UserNotificationForm, UserContactForm
|
||||
from user.models import KonovaUserExtension
|
||||
|
||||
|
||||
@login_required
|
||||
@ -43,9 +42,6 @@ def notifications_view(request: HttpRequest):
|
||||
"""
|
||||
template = "user/notifications.html"
|
||||
user = request.user
|
||||
konova_ext = KonovaUserExtension.objects.get_or_create(
|
||||
user=user
|
||||
)[0]
|
||||
|
||||
form = UserNotificationForm(user=user, data=request.POST or None)
|
||||
if request.method == "POST":
|
||||
@ -65,7 +61,6 @@ def notifications_view(request: HttpRequest):
|
||||
context = {
|
||||
"user": user,
|
||||
"form": form,
|
||||
"konova_ext": konova_ext,
|
||||
}
|
||||
context = BaseContext(request, context).context
|
||||
return render(request, template, context)
|
||||
|
Loading…
Reference in New Issue
Block a user