2024-02-09 19:32:12 +01:00
|
|
|
"""Admin classes and registrations for core app."""
|
2024-08-20 16:42:27 +02:00
|
|
|
|
2024-01-09 15:30:36 +01:00
|
|
|
from django.contrib import admin
|
2024-02-09 19:32:12 +01:00
|
|
|
from django.contrib.auth import admin as auth_admin
|
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
2024-01-09 15:30:36 +01:00
|
|
|
|
2024-12-16 16:58:14 +01:00
|
|
|
from treebeard.admin import TreeAdmin
|
|
|
|
|
from treebeard.forms import movenodeform_factory
|
|
|
|
|
|
2024-01-09 15:30:36 +01:00
|
|
|
from . import models
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TemplateAccessInline(admin.TabularInline):
|
|
|
|
|
"""Inline admin class for template accesses."""
|
|
|
|
|
|
2024-12-16 16:58:14 +01:00
|
|
|
autocomplete_fields = ["user"]
|
2024-01-09 15:30:36 +01:00
|
|
|
model = models.TemplateAccess
|
|
|
|
|
extra = 0
|
|
|
|
|
|
|
|
|
|
|
2024-02-09 19:32:12 +01:00
|
|
|
@admin.register(models.User)
|
|
|
|
|
class UserAdmin(auth_admin.UserAdmin):
|
|
|
|
|
"""Admin class for the User model"""
|
|
|
|
|
|
|
|
|
|
fieldsets = (
|
|
|
|
|
(
|
|
|
|
|
None,
|
|
|
|
|
{
|
|
|
|
|
"fields": (
|
|
|
|
|
"id",
|
|
|
|
|
"admin_email",
|
|
|
|
|
"password",
|
|
|
|
|
)
|
|
|
|
|
},
|
|
|
|
|
),
|
2024-09-30 15:13:42 +02:00
|
|
|
(
|
|
|
|
|
_("Personal info"),
|
|
|
|
|
{
|
|
|
|
|
"fields": (
|
|
|
|
|
"sub",
|
|
|
|
|
"email",
|
|
|
|
|
"full_name",
|
|
|
|
|
"short_name",
|
|
|
|
|
"language",
|
|
|
|
|
"timezone",
|
|
|
|
|
)
|
|
|
|
|
},
|
|
|
|
|
),
|
2024-02-09 19:32:12 +01:00
|
|
|
(
|
|
|
|
|
_("Permissions"),
|
|
|
|
|
{
|
|
|
|
|
"fields": (
|
|
|
|
|
"is_active",
|
|
|
|
|
"is_device",
|
|
|
|
|
"is_staff",
|
|
|
|
|
"is_superuser",
|
|
|
|
|
"groups",
|
|
|
|
|
"user_permissions",
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
(_("Important dates"), {"fields": ("created_at", "updated_at")}),
|
|
|
|
|
)
|
|
|
|
|
add_fieldsets = (
|
|
|
|
|
(
|
|
|
|
|
None,
|
|
|
|
|
{
|
|
|
|
|
"classes": ("wide",),
|
|
|
|
|
"fields": ("email", "password1", "password2"),
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
inlines = (TemplateAccessInline,)
|
|
|
|
|
list_display = (
|
|
|
|
|
"id",
|
|
|
|
|
"sub",
|
2024-09-30 15:13:42 +02:00
|
|
|
"full_name",
|
2024-02-09 19:32:12 +01:00
|
|
|
"admin_email",
|
|
|
|
|
"email",
|
|
|
|
|
"is_active",
|
|
|
|
|
"is_staff",
|
|
|
|
|
"is_superuser",
|
|
|
|
|
"is_device",
|
|
|
|
|
"created_at",
|
|
|
|
|
"updated_at",
|
|
|
|
|
)
|
|
|
|
|
list_filter = ("is_staff", "is_superuser", "is_device", "is_active")
|
2024-09-30 15:13:42 +02:00
|
|
|
ordering = (
|
|
|
|
|
"is_active",
|
|
|
|
|
"-is_superuser",
|
|
|
|
|
"-is_staff",
|
|
|
|
|
"-is_device",
|
|
|
|
|
"-updated_at",
|
|
|
|
|
"full_name",
|
|
|
|
|
)
|
|
|
|
|
readonly_fields = (
|
|
|
|
|
"id",
|
|
|
|
|
"sub",
|
|
|
|
|
"email",
|
|
|
|
|
"full_name",
|
|
|
|
|
"short_name",
|
|
|
|
|
"created_at",
|
|
|
|
|
"updated_at",
|
|
|
|
|
)
|
|
|
|
|
search_fields = ("id", "sub", "admin_email", "email", "full_name")
|
2024-02-09 19:32:12 +01:00
|
|
|
|
|
|
|
|
|
2024-01-09 15:30:36 +01:00
|
|
|
@admin.register(models.Template)
|
|
|
|
|
class TemplateAdmin(admin.ModelAdmin):
|
|
|
|
|
"""Template admin interface declaration."""
|
|
|
|
|
|
|
|
|
|
inlines = (TemplateAccessInline,)
|
2024-05-22 10:59:09 +02:00
|
|
|
|
2024-05-13 23:31:00 +02:00
|
|
|
|
2024-05-22 10:59:09 +02:00
|
|
|
class DocumentAccessInline(admin.TabularInline):
|
|
|
|
|
"""Inline admin class for template accesses."""
|
|
|
|
|
|
2024-12-16 16:58:14 +01:00
|
|
|
autocomplete_fields = ["user"]
|
2024-05-22 10:59:09 +02:00
|
|
|
model = models.DocumentAccess
|
|
|
|
|
extra = 0
|
|
|
|
|
|
2024-05-13 23:31:00 +02:00
|
|
|
|
2024-05-22 10:59:09 +02:00
|
|
|
@admin.register(models.Document)
|
2024-12-16 16:58:14 +01:00
|
|
|
class DocumentAdmin(TreeAdmin):
|
2024-05-22 10:59:09 +02:00
|
|
|
"""Document admin interface declaration."""
|
|
|
|
|
|
2024-12-16 16:58:14 +01:00
|
|
|
fieldsets = (
|
|
|
|
|
(
|
|
|
|
|
None,
|
|
|
|
|
{
|
|
|
|
|
"fields": (
|
|
|
|
|
"id",
|
|
|
|
|
"title",
|
|
|
|
|
)
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
(
|
|
|
|
|
_("Permissions"),
|
|
|
|
|
{
|
|
|
|
|
"fields": (
|
|
|
|
|
"creator",
|
|
|
|
|
"link_reach",
|
|
|
|
|
"link_role",
|
|
|
|
|
)
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
(
|
|
|
|
|
_("Tree structure"),
|
|
|
|
|
{
|
|
|
|
|
"fields": (
|
|
|
|
|
"path",
|
|
|
|
|
"depth",
|
|
|
|
|
"numchild",
|
2025-01-20 10:23:18 +01:00
|
|
|
"duplicated_from",
|
|
|
|
|
"attachments",
|
2024-12-16 16:58:14 +01:00
|
|
|
)
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
form = movenodeform_factory(models.Document)
|
2024-05-22 10:59:09 +02:00
|
|
|
inlines = (DocumentAccessInline,)
|
2024-09-08 23:37:49 +02:00
|
|
|
list_display = (
|
|
|
|
|
"id",
|
|
|
|
|
"title",
|
|
|
|
|
"link_reach",
|
|
|
|
|
"link_role",
|
|
|
|
|
"created_at",
|
|
|
|
|
"updated_at",
|
|
|
|
|
)
|
2024-12-16 16:58:14 +01:00
|
|
|
readonly_fields = (
|
2025-01-20 10:23:18 +01:00
|
|
|
"attachments",
|
2024-12-16 16:58:14 +01:00
|
|
|
"creator",
|
|
|
|
|
"depth",
|
2025-01-20 10:23:18 +01:00
|
|
|
"duplicated_from",
|
2024-12-16 16:58:14 +01:00
|
|
|
"id",
|
|
|
|
|
"numchild",
|
|
|
|
|
"path",
|
|
|
|
|
)
|
|
|
|
|
search_fields = ("id", "title")
|
2024-05-25 08:15:34 +02:00
|
|
|
|
2024-05-13 23:31:00 +02:00
|
|
|
|
|
|
|
|
@admin.register(models.Invitation)
|
|
|
|
|
class InvitationAdmin(admin.ModelAdmin):
|
|
|
|
|
"""Admin interface to handle invitations."""
|
|
|
|
|
|
|
|
|
|
fields = (
|
|
|
|
|
"email",
|
|
|
|
|
"document",
|
|
|
|
|
"role",
|
|
|
|
|
"created_at",
|
|
|
|
|
"issuer",
|
|
|
|
|
)
|
|
|
|
|
readonly_fields = (
|
|
|
|
|
"created_at",
|
|
|
|
|
"is_expired",
|
|
|
|
|
"issuer",
|
|
|
|
|
)
|
|
|
|
|
list_display = (
|
|
|
|
|
"email",
|
|
|
|
|
"document",
|
|
|
|
|
"created_at",
|
|
|
|
|
"is_expired",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def save_model(self, request, obj, form, change):
|
|
|
|
|
obj.issuer = request.user
|
|
|
|
|
obj.save()
|