admin.py 6.65 KB
Newer Older
Valentin Samir's avatar
Valentin Samir committed
1 2 3 4 5 6 7 8 9
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License version 3 for
# more details.
#
# You should have received a copy of the GNU General Public License version 3
# along with this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
Valentin Samir's avatar
Valentin Samir committed
10
# (c) 2015-2016 Valentin Samir
Valentin Samir's avatar
Valentin Samir committed
11
"""module for the admin interface of the app"""
12 13
from .default_settings import settings

Valentin Samir's avatar
Valentin Samir committed
14
from django.contrib import admin
Valentin Samir's avatar
Valentin Samir committed
15 16
from .models import ServiceTicket, ProxyTicket, ProxyGrantingTicket, User, ServicePattern
from .models import Username, ReplaceAttributName, ReplaceAttributValue, FilterAttributValue
17
from .models import FederatedIendityProvider, FederatedUser, UserAttributes
Valentin Samir's avatar
Valentin Samir committed
18
from .forms import TicketForm
Valentin Samir's avatar
Valentin Samir committed
19

Valentin Samir's avatar
Valentin Samir committed
20

21 22 23
class BaseInlines(admin.TabularInline):
    """
        Bases: :class:`django.contrib.admin.TabularInline`
Valentin Samir's avatar
Valentin Samir committed
24

25 26 27 28
        Base class for inlines in the admin interface.
    """
    #: This controls the number of extra forms the formset will display in addition to
    #: the initial forms.
Valentin Samir's avatar
Valentin Samir committed
29
    extra = 0
30 31 32 33 34 35 36 37 38


class UserAdminInlines(BaseInlines):
    """
        Bases: :class:`BaseInlines`

        Base class for inlines in :class:`UserAdmin` interface
    """
    #: The form :class:`TicketForm<cas_server.forms.TicketForm>` used to display tickets.
Valentin Samir's avatar
Valentin Samir committed
39
    form = TicketForm
40 41 42 43 44 45 46 47 48 49 50
    #: Fields to display on a object that are read only (not editable).
    readonly_fields = (
        'validate', 'service', 'service_pattern',
        'creation', 'renew', 'single_log_out', 'value'
    )
    #: Fields to display on a object.
    fields = (
        'validate', 'service', 'service_pattern',
        'creation', 'renew', 'single_log_out'
    )

Valentin Samir's avatar
Valentin Samir committed
51

52 53 54
class ServiceTicketInline(UserAdminInlines):
    """
        Bases: :class:`UserAdminInlines`
Valentin Samir's avatar
Valentin Samir committed
55

56 57 58 59 60 61 62 63 64 65 66 67 68
        :class:`ServiceTicket<cas_server.models.ServiceTicket>` in admin interface
    """
    #: The model which the inline is using.
    model = ServiceTicket


class ProxyTicketInline(UserAdminInlines):
    """
        Bases: :class:`UserAdminInlines`

        :class:`ProxyTicket<cas_server.models.ProxyTicket>` in admin interface
    """
    #: The model which the inline is using.
Valentin Samir's avatar
Valentin Samir committed
69
    model = ProxyTicket
Valentin Samir's avatar
Valentin Samir committed
70 71


72 73 74 75 76 77 78
class ProxyGrantingInline(UserAdminInlines):
    """
        Bases: :class:`UserAdminInlines`

        :class:`ProxyGrantingTicket<cas_server.models.ProxyGrantingTicket>` in admin interface
    """
    #: The model which the inline is using.
Valentin Samir's avatar
Valentin Samir committed
79 80
    model = ProxyGrantingTicket

Valentin Samir's avatar
Valentin Samir committed
81

Valentin Samir's avatar
Valentin Samir committed
82
class UserAdmin(admin.ModelAdmin):
83 84 85 86 87 88 89
    """
        Bases: :class:`django.contrib.admin.ModelAdmin`

        :class:`User<cas_server.models.User>` in admin interface
    """
    #: See :class:`ServiceTicketInline`, :class:`ProxyTicketInline`, :class:`ProxyGrantingInline`
    #: objects below the :class:`UserAdmin` fields.
Valentin Samir's avatar
Valentin Samir committed
90
    inlines = (ServiceTicketInline, ProxyTicketInline, ProxyGrantingInline)
91
    #: Fields to display on a object that are read only (not editable).
Valentin Samir's avatar
Valentin Samir committed
92
    readonly_fields = ('username', 'date', "session_key")
93
    #: Fields to display on a object.
94
    fields = ('username', 'date', "session_key")
95
    #: Fields to display on the list of class:`UserAdmin` objects.
96
    list_display = ('username', 'date', "session_key")
Valentin Samir's avatar
Valentin Samir committed
97

Valentin Samir's avatar
Valentin Samir committed
98

99 100 101 102 103 104 105
class UsernamesInline(BaseInlines):
    """
        Bases: :class:`BaseInlines`

        :class:`Username<cas_server.models.Username>` in admin interface
    """
    #: The model which the inline is using.
Valentin Samir's avatar
Valentin Samir committed
106
    model = Username
Valentin Samir's avatar
Valentin Samir committed
107 108


109 110 111 112 113 114 115
class ReplaceAttributNameInline(BaseInlines):
    """
        Bases: :class:`BaseInlines`

        :class:`ReplaceAttributName<cas_server.models.ReplaceAttributName>` in admin interface
    """
    #: The model which the inline is using.
Valentin Samir's avatar
Valentin Samir committed
116
    model = ReplaceAttributName
Valentin Samir's avatar
Valentin Samir committed
117 118


119 120 121 122 123 124 125
class ReplaceAttributValueInline(BaseInlines):
    """
        Bases: :class:`BaseInlines`

        :class:`ReplaceAttributValue<cas_server.models.ReplaceAttributValue>` in admin interface
    """
    #: The model which the inline is using.
Valentin Samir's avatar
Valentin Samir committed
126
    model = ReplaceAttributValue
Valentin Samir's avatar
Valentin Samir committed
127 128


129 130 131 132 133 134 135
class FilterAttributValueInline(BaseInlines):
    """
        Bases: :class:`BaseInlines`

        :class:`FilterAttributValue<cas_server.models.FilterAttributValue>` in admin interface
    """
    #: The model which the inline is using.
Valentin Samir's avatar
Valentin Samir committed
136 137
    model = FilterAttributValue

Valentin Samir's avatar
Valentin Samir committed
138

Valentin Samir's avatar
Valentin Samir committed
139
class ServicePatternAdmin(admin.ModelAdmin):
140 141 142 143 144 145 146 147
    """
        Bases: :class:`django.contrib.admin.ModelAdmin`

        :class:`ServicePattern<cas_server.models.ServicePattern>` in admin interface
    """
    #: See :class:`UsernamesInline`, :class:`ReplaceAttributNameInline`,
    #: :class:`ReplaceAttributValueInline`, :class:`FilterAttributValueInline` objects below
    #: the :class:`ServicePatternAdmin` fields.
Valentin Samir's avatar
Valentin Samir committed
148 149 150 151 152 153
    inlines = (
        UsernamesInline,
        ReplaceAttributNameInline,
        ReplaceAttributValueInline,
        FilterAttributValueInline
    )
154
    #: Fields to display on the list of class:`ServicePatternAdmin` objects.
Valentin Samir's avatar
Valentin Samir committed
155 156
    list_display = ('pos', 'name', 'pattern', 'proxy',
                    'single_log_out', 'proxy_callback', 'restrict_users')
Valentin Samir's avatar
Valentin Samir committed
157 158


159
class FederatedIendityProviderAdmin(admin.ModelAdmin):
160 161 162 163 164 165 166
    """
        Bases: :class:`django.contrib.admin.ModelAdmin`

        :class:`FederatedIendityProvider<cas_server.models.FederatedIendityProvider>` in admin
        interface
    """
    #: Fields to display on a object.
167
    fields = ('pos', 'suffix', 'server_url', 'cas_protocol_version', 'verbose_name', 'display')
168
    #: Fields to display on the list of class:`FederatedIendityProviderAdmin` objects.
169
    list_display = ('verbose_name', 'suffix', 'display')
170 171


172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
class FederatedUserAdmin(admin.ModelAdmin):
    """
        Bases: :class:`django.contrib.admin.ModelAdmin`

        :class:`FederatedUser<cas_server.models.FederatedUser>` in admin
        interface
    """
    #: Fields to display on a object.
    fields = ('username', 'provider', 'last_update')
    #: Fields to display on the list of class:`FederatedUserAdmin` objects.
    list_display = ('username', 'provider', 'last_update')


class UserAttributesAdmin(admin.ModelAdmin):
    """
        Bases: :class:`django.contrib.admin.ModelAdmin`

        :class:`UserAttributes<cas_server.models.UserAttributes>` in admin
        interface
    """
    #: Fields to display on a object.
    fields = ('username', '_attributs')


Valentin Samir's avatar
Valentin Samir committed
196
admin.site.register(ServicePattern, ServicePatternAdmin)
197
admin.site.register(FederatedIendityProvider, FederatedIendityProviderAdmin)
198 199 200 201
if settings.DEBUG:  # pragma: no branch (we always test with DEBUG True)
    admin.site.register(User, UserAdmin)
    admin.site.register(FederatedUser, FederatedUserAdmin)
    admin.site.register(UserAttributes, UserAttributesAdmin)