#99 Admin backend cleanup
* removes admin backend views which are not important for production * adds filtering functionalities on index views * simplifies detail views on intervention, compensation, ecoaccount and ema * adds autocomplete fields on detail views * adds handy horizontal filter fields on detail views
This commit is contained in:
parent
568a288e92
commit
5b0b376405
@ -12,5 +12,9 @@ class APITokenAdmin(admin.ModelAdmin):
|
|||||||
readonly_fields = [
|
readonly_fields = [
|
||||||
"token"
|
"token"
|
||||||
]
|
]
|
||||||
|
search_fields = [
|
||||||
|
"token"
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(APIUserToken, APITokenAdmin)
|
admin.site.register(APIUserToken, APITokenAdmin)
|
||||||
|
@ -35,6 +35,13 @@ class KonovaCodeAdmin(admin.ModelAdmin):
|
|||||||
"parent",
|
"parent",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
search_fields = [
|
||||||
|
"id",
|
||||||
|
"atom_id",
|
||||||
|
"long_name",
|
||||||
|
"short_name",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
#admin.site.register(KonovaCodeList, KonovaCodeListAdmin)
|
#admin.site.register(KonovaCodeList, KonovaCodeListAdmin)
|
||||||
admin.site.register(KonovaCode, KonovaCodeAdmin)
|
admin.site.register(KonovaCode, KonovaCodeAdmin)
|
||||||
|
@ -2,7 +2,100 @@ from django.contrib import admin
|
|||||||
|
|
||||||
from compensation.models import Compensation, CompensationAction, CompensationState, Payment, \
|
from compensation.models import Compensation, CompensationAction, CompensationState, Payment, \
|
||||||
EcoAccountDeduction, EcoAccount
|
EcoAccountDeduction, EcoAccount
|
||||||
from konova.admin import BaseObjectAdmin
|
from konova.admin import BaseObjectAdmin, BaseResourceAdmin
|
||||||
|
|
||||||
|
|
||||||
|
class AbstractCompensationAdmin(BaseObjectAdmin):
|
||||||
|
list_display = [
|
||||||
|
"id",
|
||||||
|
"identifier",
|
||||||
|
"title",
|
||||||
|
"created",
|
||||||
|
"deleted",
|
||||||
|
]
|
||||||
|
|
||||||
|
def get_fields(self, request, obj=None):
|
||||||
|
return super().get_fields(request, obj) + [
|
||||||
|
"identifier",
|
||||||
|
"title",
|
||||||
|
"comment",
|
||||||
|
"after_states",
|
||||||
|
"before_states",
|
||||||
|
]
|
||||||
|
|
||||||
|
def get_readonly_fields(self, request, obj=None):
|
||||||
|
return super().get_readonly_fields(request, obj) + [
|
||||||
|
"after_states",
|
||||||
|
"before_states",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class CompensationAdmin(AbstractCompensationAdmin):
|
||||||
|
autocomplete_fields = [
|
||||||
|
"intervention",
|
||||||
|
]
|
||||||
|
|
||||||
|
def get_fields(self, request, obj=None):
|
||||||
|
return super().get_fields(request, obj) + [
|
||||||
|
"is_cef",
|
||||||
|
"is_coherence_keeping",
|
||||||
|
"intervention",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class EcoAccountAdmin(AbstractCompensationAdmin):
|
||||||
|
list_display = [
|
||||||
|
"id",
|
||||||
|
"identifier",
|
||||||
|
"title",
|
||||||
|
"created",
|
||||||
|
"deleted",
|
||||||
|
]
|
||||||
|
|
||||||
|
filter_horizontal = [
|
||||||
|
"users"
|
||||||
|
]
|
||||||
|
|
||||||
|
def get_fields(self, request, obj=None):
|
||||||
|
return super().get_fields(request, obj) + [
|
||||||
|
"deductable_surface",
|
||||||
|
"users"
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class PaymentAdmin(admin.ModelAdmin):
|
||||||
|
list_display = [
|
||||||
|
"id",
|
||||||
|
"amount",
|
||||||
|
"due_on",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class EcoAccountDeductionAdmin(BaseResourceAdmin):
|
||||||
|
list_display = [
|
||||||
|
"id",
|
||||||
|
"account",
|
||||||
|
"intervention",
|
||||||
|
"surface",
|
||||||
|
]
|
||||||
|
search_fields = [
|
||||||
|
"account__identifier",
|
||||||
|
"account__title",
|
||||||
|
"intervention__identifier",
|
||||||
|
"intervention__title",
|
||||||
|
"surface",
|
||||||
|
]
|
||||||
|
autocomplete_fields = [
|
||||||
|
"account",
|
||||||
|
"intervention",
|
||||||
|
]
|
||||||
|
|
||||||
|
def get_fields(self, request, obj=None):
|
||||||
|
return super().get_fields(request, obj) + [
|
||||||
|
"account",
|
||||||
|
"intervention",
|
||||||
|
"surface",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class CompensationStateAdmin(admin.ModelAdmin):
|
class CompensationStateAdmin(admin.ModelAdmin):
|
||||||
@ -23,44 +116,11 @@ class CompensationActionAdmin(admin.ModelAdmin):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class CompensationAdmin(BaseObjectAdmin):
|
|
||||||
list_display = [
|
|
||||||
"id",
|
|
||||||
"identifier",
|
|
||||||
"title",
|
|
||||||
"created",
|
|
||||||
"deleted",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class EcoAccountAdmin(admin.ModelAdmin):
|
|
||||||
list_display = [
|
|
||||||
"id",
|
|
||||||
"identifier",
|
|
||||||
"title",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class PaymentAdmin(admin.ModelAdmin):
|
|
||||||
list_display = [
|
|
||||||
"id",
|
|
||||||
"amount",
|
|
||||||
"due_on",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class EcoAccountDeductionAdmin(admin.ModelAdmin):
|
|
||||||
list_display = [
|
|
||||||
"id",
|
|
||||||
"account",
|
|
||||||
"intervention",
|
|
||||||
"surface",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(Compensation, CompensationAdmin)
|
admin.site.register(Compensation, CompensationAdmin)
|
||||||
admin.site.register(Payment, PaymentAdmin)
|
|
||||||
admin.site.register(CompensationAction, CompensationActionAdmin)
|
|
||||||
admin.site.register(CompensationState, CompensationStateAdmin)
|
|
||||||
admin.site.register(EcoAccount, EcoAccountAdmin)
|
admin.site.register(EcoAccount, EcoAccountAdmin)
|
||||||
admin.site.register(EcoAccountDeduction, EcoAccountDeductionAdmin)
|
admin.site.register(EcoAccountDeduction, EcoAccountDeductionAdmin)
|
||||||
|
|
||||||
|
# For a more cleaner admin interface these rarely used admin views are not important for deployment
|
||||||
|
#admin.site.register(Payment, PaymentAdmin)
|
||||||
|
#admin.site.register(CompensationAction, CompensationActionAdmin)
|
||||||
|
#admin.site.register(CompensationState, CompensationStateAdmin)
|
@ -59,7 +59,7 @@ class CompensationAction(BaseResource):
|
|||||||
objects = CompensationActionManager()
|
objects = CompensationActionManager()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "{} | {} {}".format(self.action_type, self.amount, self.unit)
|
return f"{self.action_type} | {self.amount} {self.unit}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_humanize(self):
|
def unit_humanize(self):
|
||||||
|
@ -46,7 +46,7 @@ class EcoAccount(AbstractCompensation, ShareableObjectMixin, RecordableObjectMix
|
|||||||
objects = EcoAccountManager()
|
objects = EcoAccountManager()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "{}".format(self.identifier)
|
return f"{self.identifier} ({self.title})"
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
# Deductable surface can not be larger than added states after surface
|
# Deductable surface can not be larger than added states after surface
|
||||||
|
@ -44,4 +44,4 @@ class CompensationState(UuidModel):
|
|||||||
objects = CompensationStateManager()
|
objects = CompensationStateManager()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "{} | {} m²".format(self.biotope_type, self.surface)
|
return f"{self.biotope_type} | {self.surface} m²"
|
||||||
|
13
ema/admin.py
13
ema/admin.py
@ -1,10 +1,17 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
from compensation.admin import CompensationAdmin
|
from compensation.admin import AbstractCompensationAdmin
|
||||||
from ema.models import Ema
|
from ema.models import Ema
|
||||||
|
|
||||||
|
|
||||||
class EmaAdmin(CompensationAdmin):
|
class EmaAdmin(AbstractCompensationAdmin):
|
||||||
pass
|
filter_horizontal = [
|
||||||
|
"users"
|
||||||
|
]
|
||||||
|
|
||||||
|
def get_fields(self, request, obj=None):
|
||||||
|
return super().get_fields(request, obj) + [
|
||||||
|
"users"
|
||||||
|
]
|
||||||
|
|
||||||
admin.site.register(Ema, EmaAdmin)
|
admin.site.register(Ema, EmaAdmin)
|
||||||
|
@ -13,6 +13,26 @@ class InterventionAdmin(BaseObjectAdmin):
|
|||||||
"deleted",
|
"deleted",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
filter_horizontal = [
|
||||||
|
"users"
|
||||||
|
]
|
||||||
|
|
||||||
|
def get_fields(self, request, obj=None):
|
||||||
|
return super().get_fields(request, obj) + [
|
||||||
|
"identifier",
|
||||||
|
"title",
|
||||||
|
"comment",
|
||||||
|
"checked",
|
||||||
|
"recorded",
|
||||||
|
"users",
|
||||||
|
]
|
||||||
|
|
||||||
|
def get_readonly_fields(self, request, obj=None):
|
||||||
|
return super().get_readonly_fields(request, obj) + [
|
||||||
|
"checked",
|
||||||
|
"recorded",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class InterventionDocumentAdmin(AbstractDocumentAdmin):
|
class InterventionDocumentAdmin(AbstractDocumentAdmin):
|
||||||
pass
|
pass
|
||||||
@ -48,7 +68,9 @@ class RevocationAdmin(admin.ModelAdmin):
|
|||||||
|
|
||||||
|
|
||||||
admin.site.register(Intervention, InterventionAdmin)
|
admin.site.register(Intervention, InterventionAdmin)
|
||||||
admin.site.register(Responsibility, ResponsibilityAdmin)
|
|
||||||
admin.site.register(Legal, LegalAdmin)
|
# Outcommented for a cleaner admin backend on production
|
||||||
admin.site.register(Revocation, RevocationAdmin)
|
#admin.site.register(Responsibility, ResponsibilityAdmin)
|
||||||
admin.site.register(InterventionDocument, InterventionDocumentAdmin)
|
#admin.site.register(Legal, LegalAdmin)
|
||||||
|
#admin.site.register(Revocation, RevocationAdmin)
|
||||||
|
#admin.site.register(InterventionDocument, InterventionDocumentAdmin)
|
||||||
|
@ -51,7 +51,7 @@ class Intervention(BaseObject, ShareableObjectMixin, RecordableObjectMixin, Chec
|
|||||||
objects = InterventionManager()
|
objects = InterventionManager()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "{} ({})".format(self.identifier, self.title)
|
return f"{self.identifier} ({self.title})"
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
""" Custom save functionality
|
""" Custom save functionality
|
||||||
|
@ -62,16 +62,35 @@ class DeadlineAdmin(admin.ModelAdmin):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class BaseObjectAdmin(admin.ModelAdmin):
|
class BaseResourceAdmin(admin.ModelAdmin):
|
||||||
|
fields = [
|
||||||
|
"created",
|
||||||
|
"modified",
|
||||||
|
]
|
||||||
readonly_fields = [
|
readonly_fields = [
|
||||||
"modified",
|
"modified",
|
||||||
"deleted",
|
|
||||||
"created",
|
"created",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(Geometry, GeometryAdmin)
|
class BaseObjectAdmin(BaseResourceAdmin):
|
||||||
admin.site.register(Parcel, ParcelAdmin)
|
search_fields = [
|
||||||
admin.site.register(District, DistrictAdmin)
|
"identifier",
|
||||||
admin.site.register(GeometryConflict, GeometryConflictAdmin)
|
"title",
|
||||||
admin.site.register(Deadline, DeadlineAdmin)
|
]
|
||||||
|
|
||||||
|
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(GeometryConflict, GeometryConflictAdmin)
|
||||||
|
#admin.site.register(Deadline, DeadlineAdmin)
|
||||||
|
@ -4,11 +4,23 @@ from news.models import ServerMessage
|
|||||||
|
|
||||||
|
|
||||||
class ServerMessageAdmin(admin.ModelAdmin):
|
class ServerMessageAdmin(admin.ModelAdmin):
|
||||||
|
readonly_fields = [
|
||||||
|
"modified",
|
||||||
|
"created",
|
||||||
|
]
|
||||||
list_display = [
|
list_display = [
|
||||||
"id",
|
"id",
|
||||||
"subject",
|
"subject",
|
||||||
"publish_on",
|
"publish_on",
|
||||||
"is_active",
|
"is_active",
|
||||||
]
|
]
|
||||||
|
search_fields = [
|
||||||
|
"subject"
|
||||||
|
]
|
||||||
|
|
||||||
|
def save_model(self, request, obj, form, change):
|
||||||
|
obj.save(user=request.user)
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(ServerMessage, ServerMessageAdmin)
|
admin.site.register(ServerMessage, ServerMessageAdmin)
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ from django.db import models
|
|||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from konova.models import BaseResource
|
from konova.models import BaseResource
|
||||||
|
from user.models import UserActionLogEntry
|
||||||
|
|
||||||
|
|
||||||
class ServerMessageImportance(models.TextChoices):
|
class ServerMessageImportance(models.TextChoices):
|
||||||
@ -23,3 +24,13 @@ class ServerMessage(BaseResource):
|
|||||||
publish_on = models.DateTimeField()
|
publish_on = models.DateTimeField()
|
||||||
unpublish_on = models.DateTimeField()
|
unpublish_on = models.DateTimeField()
|
||||||
importance = models.CharField(max_length=100, choices=ServerMessageImportance.choices)
|
importance = models.CharField(max_length=100, choices=ServerMessageImportance.choices)
|
||||||
|
|
||||||
|
def save(self, user=None, *args, **kwargs):
|
||||||
|
user = kwargs.pop("user", None)
|
||||||
|
if user is not None:
|
||||||
|
if self.created is None:
|
||||||
|
self.created = UserActionLogEntry.get_created_action(user)
|
||||||
|
else:
|
||||||
|
self.modified = UserActionLogEntry.get_edited_action(user)
|
||||||
|
|
||||||
|
super().save(*args, **kwargs)
|
||||||
|
@ -19,6 +19,40 @@ class UserAdmin(admin.ModelAdmin):
|
|||||||
"last_name",
|
"last_name",
|
||||||
"email",
|
"email",
|
||||||
]
|
]
|
||||||
|
fields = [
|
||||||
|
"username",
|
||||||
|
"first_name",
|
||||||
|
"last_name",
|
||||||
|
"email",
|
||||||
|
"is_active",
|
||||||
|
"is_staff",
|
||||||
|
"is_superuser",
|
||||||
|
"api_token",
|
||||||
|
"groups",
|
||||||
|
"notifications",
|
||||||
|
"date_joined",
|
||||||
|
"last_login",
|
||||||
|
]
|
||||||
|
search_fields = [
|
||||||
|
"username",
|
||||||
|
"first_name",
|
||||||
|
"last_name",
|
||||||
|
"email",
|
||||||
|
]
|
||||||
|
filter_horizontal = [
|
||||||
|
"groups",
|
||||||
|
"notifications",
|
||||||
|
]
|
||||||
|
readonly_fields = [
|
||||||
|
"date_joined",
|
||||||
|
"last_login",
|
||||||
|
]
|
||||||
|
autocomplete_fields = [
|
||||||
|
"api_token",
|
||||||
|
]
|
||||||
|
exclude = [
|
||||||
|
"user_permissions",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class UserActionLogEntryAdmin(admin.ModelAdmin):
|
class UserActionLogEntryAdmin(admin.ModelAdmin):
|
||||||
@ -30,6 +64,8 @@ class UserActionLogEntryAdmin(admin.ModelAdmin):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(UserNotification, UserNotificationAdmin)
|
|
||||||
admin.site.register(UserActionLogEntry, UserActionLogEntryAdmin)
|
|
||||||
admin.site.register(User, UserAdmin)
|
admin.site.register(User, UserAdmin)
|
||||||
|
|
||||||
|
# Outcommented for a cleaner admin backend on production
|
||||||
|
#admin.site.register(UserNotification, UserNotificationAdmin)
|
||||||
|
#admin.site.register(UserActionLogEntry, UserActionLogEntryAdmin)
|
||||||
|
@ -10,6 +10,8 @@ import uuid
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
from konova.sub_settings.django_settings import DEFAULT_DATE_FORMAT, DEFAULT_DATE_TIME_FORMAT
|
||||||
|
|
||||||
|
|
||||||
class UserAction(models.TextChoices):
|
class UserAction(models.TextChoices):
|
||||||
"""
|
"""
|
||||||
@ -49,6 +51,9 @@ class UserActionLogEntry(models.Model):
|
|||||||
"-timestamp",
|
"-timestamp",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.timestamp.strftime(DEFAULT_DATE_TIME_FORMAT)} | {self.action} | {self.user}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def action_humanize(self):
|
def action_humanize(self):
|
||||||
""" Returns humanized version of enum
|
""" Returns humanized version of enum
|
||||||
|
Loading…
Reference in New Issue
Block a user