mpeltriaux
e7031d0bc2
* adds restorable delete functionality to Team model * refactors minor code model parts by introducing DeletableObjectMixin * only non-deleted Teams can be chosen for sharing * deleted Teams can be restored using the proper function on the backend admin * deleted Teams do not provide * adds migration
151 lines
3.2 KiB
Python
151 lines
3.2 KiB
Python
"""
|
|
Author: Michel Peltriaux
|
|
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
|
Contact: michel.peltriaux@sgdnord.rlp.de
|
|
Created on: 22.07.21
|
|
|
|
"""
|
|
from django.contrib import admin
|
|
|
|
from konova.models import Geometry, Deadline, GeometryConflict, Parcel, District, Municipal, ParcelGroup
|
|
from konova.sub_settings.lanis_settings import DEFAULT_SRID_RLP
|
|
from konova.utils.message_templates import COMPENSATION_REMOVED_TEMPLATE
|
|
from user.models import UserAction
|
|
|
|
|
|
class GeometryAdmin(admin.ModelAdmin):
|
|
list_display = [
|
|
"id",
|
|
"created",
|
|
"st_area",
|
|
]
|
|
readonly_fields = [
|
|
"st_area",
|
|
"created",
|
|
"modified",
|
|
]
|
|
|
|
def st_area(self, obj):
|
|
val = None
|
|
geom = obj.geom
|
|
if geom is not None:
|
|
geom.transform(ct=DEFAULT_SRID_RLP)
|
|
val = geom.area
|
|
return val
|
|
st_area.short_description = f"Area (srid={DEFAULT_SRID_RLP})"
|
|
|
|
|
|
class ParcelAdmin(admin.ModelAdmin):
|
|
list_display = [
|
|
"id",
|
|
"parcel_group",
|
|
"flr",
|
|
"flrstck_nnr",
|
|
"flrstck_zhlr",
|
|
"updated_on",
|
|
]
|
|
|
|
|
|
class DistrictAdmin(admin.ModelAdmin):
|
|
list_display = [
|
|
"name",
|
|
"key",
|
|
"id",
|
|
]
|
|
|
|
|
|
class MunicipalAdmin(admin.ModelAdmin):
|
|
list_display = [
|
|
"name",
|
|
"key",
|
|
"district",
|
|
"id",
|
|
]
|
|
|
|
|
|
class ParcelGroupAdmin(admin.ModelAdmin):
|
|
list_display = [
|
|
"name",
|
|
"key",
|
|
"municipal",
|
|
"id",
|
|
]
|
|
|
|
|
|
class GeometryConflictAdmin(admin.ModelAdmin):
|
|
list_display = [
|
|
"conflicting_geometry",
|
|
"affected_geometry",
|
|
"detected_on",
|
|
]
|
|
|
|
|
|
class AbstractDocumentAdmin(admin.ModelAdmin):
|
|
list_display = [
|
|
"id",
|
|
"title",
|
|
"comment",
|
|
"created",
|
|
]
|
|
|
|
|
|
class DeadlineAdmin(admin.ModelAdmin):
|
|
list_display = [
|
|
"id",
|
|
"type",
|
|
"date",
|
|
"comment",
|
|
]
|
|
|
|
|
|
class DeletableObjectMixinAdmin(admin.ModelAdmin):
|
|
class Meta:
|
|
abstract = True
|
|
|
|
def restore_deleted_data(self, request, queryset):
|
|
queryset = queryset.filter(
|
|
deleted__isnull=False
|
|
)
|
|
for entry in queryset:
|
|
entry.deleted.delete()
|
|
|
|
|
|
class BaseResourceAdmin(admin.ModelAdmin):
|
|
fields = [
|
|
"created",
|
|
"modified",
|
|
]
|
|
readonly_fields = [
|
|
"modified",
|
|
"created",
|
|
]
|
|
|
|
|
|
class BaseObjectAdmin(BaseResourceAdmin, DeletableObjectMixinAdmin):
|
|
search_fields = [
|
|
"identifier",
|
|
"title",
|
|
]
|
|
actions = [
|
|
"restore_deleted_data"
|
|
]
|
|
|
|
def get_fields(self, request, obj=None):
|
|
return super().get_fields(request, obj) + ["deleted"]
|
|
|
|
def get_readonly_fields(self, request, obj=None):
|
|
return super().get_readonly_fields(request, obj) + [
|
|
"deleted",
|
|
]
|
|
|
|
|
|
|
|
# Outcommented for a cleaner admin backend on production
|
|
#admin.site.register(Geometry, GeometryAdmin)
|
|
#admin.site.register(Parcel, ParcelAdmin)
|
|
#admin.site.register(District, DistrictAdmin)
|
|
#admin.site.register(Municipal, MunicipalAdmin)
|
|
#admin.site.register(ParcelGroup, ParcelGroupAdmin)
|
|
#admin.site.register(GeometryConflict, GeometryConflictAdmin)
|
|
#admin.site.register(Deadline, DeadlineAdmin)
|