# Path: protector/admin.py
# class PermissionObjectInline(GenericTabularInline):
#     fields = (
#         'owner_object_id', 'owner_content_type',
#         'permission', 'roles', 'responsible'
#     )
#     raw_id_fields = ('responsible', 'owner_content_type', 'permission')
#     readonly_fields = ('date_issued', )
#     verbose_name = _('Permission on this object')
#     verbose_name_plural = _('Permissions on this object')
#     model = OwnerToPermission
#     ct_field = 'content_type'
#     ct_fk_field = 'object_id'
#     extra = 1
# 
# class PermissionOwnerInline(GenericTabularInline):
#     fields = (
#         'object_id', 'content_type', 'permission',
#         'roles', 'responsible'
#     )
#     raw_id_fields = ('responsible', 'content_type', 'permission')
#     verbose_name = _('Permission')
#     verbose_name_plural = _('Permissions')
#     readonly_fields = ('date_issued', )
#     model = OwnerToPermission
#     ct_field = 'owner_content_type'
#     ct_fk_field = 'owner_object_id'
#     extra = 1
# 
# class RestrictedAdminMixin(admin.ModelAdmin):
# 
#     def __init__(self, *args, **kwargs):
#         super(RestrictedAdminMixin, self).__init__(*args, **kwargs)
#         if not self.raw_id_fields:
#             self.raw_id_fields = []
#         self.raw_id_fields = list(self.raw_id_fields)
#         if 'restriction_content_type' not in self.raw_id_fields:
#             self.raw_id_fields.append('restriction_content_type')
# 
#     def get_fieldsets(self, request, obj=None):
#         fieldsets = super(RestrictedAdminMixin, self).get_fieldsets(request, obj)
#         restricted_fields = ('restriction_content_type', 'restriction_id')
#         for fieldset in fieldsets:
#             fieldset[1]['fields'] = [
#                 field for field in fieldset[1]['fields'] if field not in restricted_fields
#             ]
#         return fieldsets + [
#             (
#                 _('Restriction options'), {'fields': (restricted_fields,)}
#             ),
#         ]
# 
# class GenericGroupAdminMixin(admin.ModelAdmin):
# 
#     save_on_top = True
# 
#     def __init__(self, *args, **kwargs):
#         super(GenericGroupAdminMixin, self).__init__(*args, **kwargs)
#         if not self.inlines:
#             self.inlines = []
#         if UserGroupInline not in self.inlines:
#             self.inlines = list(self.inlines)
#             self.inlines.append(UserGroupInline)
#             self.inlines.append(PermissionOwnerInline)


from django.contrib import admin
from test_app.models import TestUser, TestGroup
from protector.admin import PermissionObjectInline, PermissionOwnerInline, RestrictedAdminMixin, GenericGroupAdminMixin


class TestUserAdmin(admin.ModelAdmin):
    list_display = ('username', 'email')
    inlines = (
        PermissionOwnerInline, 
    )


class TestGroupAdmin(GenericGroupAdminMixin, RestrictedAdminMixin):
    list_display = ('name', )
    inlines = (
        PermissionObjectInline,
    )



# Path: protector/admin.py
# class PermissionObjectInline(GenericTabularInline):
#     fields = (
#         'owner_object_id', 'owner_content_type',
#         'permission', 'roles', 'responsible'
#     )
#     raw_id_fields = ('responsible', 'owner_content_type', 'permission')
#     readonly_fields = ('date_issued', )
#     verbose_name = _('Permission on this object')
#     verbose_name_plural = _('Permissions on this object')
#     model = OwnerToPermission
#     ct_field = 'content_type'
#     ct_fk_field = 'object_id'
#     extra = 1
# 
# class PermissionOwnerInline(GenericTabularInline):
#     fields = (
#         'object_id', 'content_type', 'permission',
#         'roles', 'responsible'
#     )
#     raw_id_fields = ('responsible', 'content_type', 'permission')
#     verbose_name = _('Permission')
#     verbose_name_plural = _('Permissions')
#     readonly_fields = ('date_issued', )
#     model = OwnerToPermission
#     ct_field = 'owner_content_type'
#     ct_fk_field = 'owner_object_id'
#     extra = 1
# 
# class RestrictedAdminMixin(admin.ModelAdmin):
# 
#     def __init__(self, *args, **kwargs):
#         super(RestrictedAdminMixin, self).__init__(*args, **kwargs)
#         if not self.raw_id_fields:
#             self.raw_id_fields = []
#         self.raw_id_fields = list(self.raw_id_fields)
#         if 'restriction_content_type' not in self.raw_id_fields:
#             self.raw_id_fields.append('restriction_content_type')
# 
#     def get_fieldsets(self, request, obj=None):
#         fieldsets = super(RestrictedAdminMixin, self).get_fieldsets(request, obj)
#         restricted_fields = ('restriction_content_type', 'restriction_id')
#         for fieldset in fieldsets:
#             fieldset[1]['fields'] = [
#                 field for field in fieldset[1]['fields'] if field not in restricted_fields
#             ]
#         return fieldsets + [
#             (
#                 _('Restriction options'), {'fields': (restricted_fields,)}
#             ),
#         ]
# 
# class GenericGroupAdminMixin(admin.ModelAdmin):
# 
#     save_on_top = True
# 
#     def __init__(self, *args, **kwargs):
#         super(GenericGroupAdminMixin, self).__init__(*args, **kwargs)
#         if not self.inlines:
#             self.inlines = []
#         if UserGroupInline not in self.inlines:
#             self.inlines = list(self.inlines)
#             self.inlines.append(UserGroupInline)
#             self.inlines.append(PermissionOwnerInline)


# Path: test_project/test_app/admin.py
from django.contrib import admin
from test_app.models import TestUser, TestGroup
from protector.admin import PermissionObjectInline, PermissionOwnerInline, RestrictedAdminMixin, GenericGroupAdminMixin



class TestUserAdmin(admin.ModelAdmin):
    list_display = ('username', 'email')
    inlines = (
        PermissionOwnerInline, 
    )


class TestGroupAdmin(GenericGroupAdminMixin, RestrictedAdminMixin):
    list_display = ('name', )
    inlines = (
        PermissionObjectInline,
    )



admin.site.register(TestUser, TestUserAdmin)