Commit 724123a9 authored by Lukas Burgey's avatar Lukas Burgey
Browse files

Restructure admin into a subdir

parent a9813a4d
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import Group as AuthGroup
from django.contrib.auth.forms import UserCreationForm
from polymorphic.admin import PolymorphicParentModelAdmin, PolymorphicChildModelAdmin
from . import models
from .models import deployments
from .auth.v1.models import OIDCConfig
from .auth.v1.models.vo import VO, Group, Entitlement, EntitlementNameSpace
# from https://docs.djangoproject.com/en/2.2/topics/auth/customizing/#custom-users-and-the-built-in-auth-forms
class CustomUserCreationForm(UserCreationForm):
class Meta(UserCreationForm.Meta):
model = models.User
fields = UserCreationForm.Meta.fields + ('user_type',)
class TypeFilter(admin.SimpleListFilter):
title = 'Type'
parameter_name = 'user_type'
def lookups(self, request, model_admin):
return models.User.TYPE_CHOICES
def queryset(self, request, queryset):
if self.value():
return queryset.filter(user_type=self.value())
return queryset
class ClientAdmin(UserAdmin):
list_filter = (TypeFilter,)
admin.site.register(models.User, ClientAdmin)
admin.site.register(models.SSHPublicKey)
admin.site.unregister(AuthGroup)
@admin.register(Group)
class GroupAdmin(PolymorphicChildModelAdmin):
base_model = Group # Explicitly set here!
show_in_index = True # makes child model admin visible in main admin site
# define custom features here
@admin.register(Entitlement)
class EntitlementAdmin(PolymorphicChildModelAdmin):
base_model = Entitlement # Explicitly set here!
show_in_index = True # makes child model admin visible in main admin site
# define custom features here
@admin.register(VO)
class VOParentAdmin(PolymorphicParentModelAdmin):
""" The parent model admin """
base_model = VO # Optional, explicitly set here.
child_models = (Group, Entitlement)
admin.site.register(EntitlementNameSpace)
admin.site.register(OIDCConfig)
admin.site.register(models.Site)
admin.site.register(models.Service)
@admin.register(deployments.VODeployment)
class VODeploymentAdmin(PolymorphicChildModelAdmin):
show_in_index = True
@admin.register(deployments.ServiceDeployment)
class ServiceDeploymentAdmin(PolymorphicChildModelAdmin):
show_in_index = True
@admin.register(deployments.Deployment)
class DeploymentAdmin(PolymorphicChildModelAdmin):
base_model = Entitlement # Explicitly set here!
show_in_index = True # makes child model admin visible in main admin site
child_models = (deployments.VODeployment, deployments.ServiceDeployment)
admin.site.register([
deployments.DeploymentState,
deployments.CredentialState,
])
from django.contrib import admin
from django.contrib.auth.models import Group as AuthGroup
from .. import models
from ..auth.v1.models import OIDCConfig
from ..auth.v1.models.vo import VO, Group, Entitlement, EntitlementNameSpace
from ..models import User
from ..models.deployments import VODeployment, ServiceDeployment, Deployment, DeploymentState, CredentialState
from .users import CustomUserAdmin
from .vos import GroupAdmin, EntitlementAdmin, VOAdmin
from .deployments import VODeploymentAdmin, ServiceDeploymentAdmin, DeploymentAdmin
# users
admin.site.register(User, CustomUserAdmin)
admin.site.unregister(AuthGroup)
# vos
admin.site.register(Group, GroupAdmin)
admin.site.register(Entitlement, EntitlementAdmin)
admin.site.register(VO, VOAdmin)
admin.site.register(EntitlementNameSpace)
admin.site.register(OIDCConfig)
# deployments
admin.site.register(VODeployment, VODeploymentAdmin)
admin.site.register(ServiceDeployment, ServiceDeploymentAdmin)
admin.site.register(Deployment, DeploymentAdmin)
# other
admin.site.register([
DeploymentState,
CredentialState,
models.SSHPublicKey,
models.Site,
models.Service,
])
from polymorphic.admin import PolymorphicParentModelAdmin, PolymorphicChildModelAdmin
from ..auth.v1.models.vo import Entitlement
from ..models import deployments
class VODeploymentAdmin(PolymorphicChildModelAdmin):
show_in_index = True
class ServiceDeploymentAdmin(PolymorphicChildModelAdmin):
show_in_index = True
class DeploymentAdmin(PolymorphicParentModelAdmin):
base_model = Entitlement # Explicitly set here!
show_in_index = True # makes child model admin visible in main admin site
child_models = (deployments.VODeployment, deployments.ServiceDeployment)
from django.contrib.admin import SimpleListFilter
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.forms import UserCreationForm
from ..models import User
class TypeFilter(SimpleListFilter):
title = 'Type'
parameter_name = 'user_type'
def lookups(self, request, model_admin):
return User.TYPE_CHOICES
def queryset(self, request, queryset):
if self.value():
return queryset.filter(user_type=self.value())
return queryset
# from https://docs.djangoproject.com/en/2.2/topics/auth/customizing/#custom-users-and-the-built-in-auth-forms
class CustomUserCreationForm(UserCreationForm):
class Meta(UserCreationForm.Meta):
model = User
fields = UserCreationForm.Meta.fields + (
'user_type',
)
class CustomUserAdmin(UserAdmin):
list_filter = (TypeFilter,)
add_form = CustomUserCreationForm
fieldsets = UserAdmin.fieldsets + (
(None, {'fields': ('user_type',)}),
)
add_fieldsets = UserAdmin.add_fieldsets + (
(None, {'fields': ('user_type',)}),
)
from polymorphic.admin import PolymorphicParentModelAdmin, PolymorphicChildModelAdmin
from ..auth.v1.models.vo import VO, Group, Entitlement
class GroupAdmin(PolymorphicChildModelAdmin):
base_model = Group # Explicitly set here!
show_in_index = True # makes child model admin visible in main admin site
# define custom features here
class EntitlementAdmin(PolymorphicChildModelAdmin):
base_model = Entitlement # Explicitly set here!
show_in_index = True # makes child model admin visible in main admin site
# define custom features here
class VOAdmin(PolymorphicParentModelAdmin):
""" The parent model admin """
base_model = VO # Optional, explicitly set here.
child_models = (Group, Entitlement)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment