admin.py 3.43 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"""
Valentin Samir's avatar
Valentin Samir committed
12
from django.contrib import admin
Valentin Samir's avatar
Valentin Samir committed
13 14
from .models import ServiceTicket, ProxyTicket, ProxyGrantingTicket, User, ServicePattern
from .models import Username, ReplaceAttributName, ReplaceAttributValue, FilterAttributValue
15
from .models import FederatedIendityProvider
Valentin Samir's avatar
Valentin Samir committed
16
from .forms import TicketForm
Valentin Samir's avatar
Valentin Samir committed
17

18
TICKETS_READONLY_FIELDS = ('validate', 'service', 'service_pattern',
Valentin Samir's avatar
PEP8  
Valentin Samir committed
19
                           'creation', 'renew', 'single_log_out', 'value')
20
TICKETS_FIELDS = ('validate', 'service', 'service_pattern',
Valentin Samir's avatar
PEP8  
Valentin Samir committed
21 22 23
                  'creation', 'renew', 'single_log_out')


Valentin Samir's avatar
Valentin Samir committed
24
class ServiceTicketInline(admin.TabularInline):
Valentin Samir's avatar
Valentin Samir committed
25
    """`ServiceTicket` in admin interface"""
Valentin Samir's avatar
Valentin Samir committed
26 27 28
    model = ServiceTicket
    extra = 0
    form = TicketForm
29 30
    readonly_fields = TICKETS_READONLY_FIELDS
    fields = TICKETS_FIELDS
Valentin Samir's avatar
PEP8  
Valentin Samir committed
31 32


Valentin Samir's avatar
Valentin Samir committed
33
class ProxyTicketInline(admin.TabularInline):
Valentin Samir's avatar
Valentin Samir committed
34
    """`ProxyTicket` in admin interface"""
Valentin Samir's avatar
Valentin Samir committed
35 36 37
    model = ProxyTicket
    extra = 0
    form = TicketForm
38 39
    readonly_fields = TICKETS_READONLY_FIELDS
    fields = TICKETS_FIELDS
Valentin Samir's avatar
PEP8  
Valentin Samir committed
40 41


Valentin Samir's avatar
Valentin Samir committed
42
class ProxyGrantingInline(admin.TabularInline):
Valentin Samir's avatar
Valentin Samir committed
43
    """`ProxyGrantingTicket` in admin interface"""
Valentin Samir's avatar
Valentin Samir committed
44 45 46
    model = ProxyGrantingTicket
    extra = 0
    form = TicketForm
47 48
    readonly_fields = TICKETS_READONLY_FIELDS
    fields = TICKETS_FIELDS[1:]
Valentin Samir's avatar
Valentin Samir committed
49

Valentin Samir's avatar
PEP8  
Valentin Samir committed
50

Valentin Samir's avatar
Valentin Samir committed
51
class UserAdmin(admin.ModelAdmin):
Valentin Samir's avatar
Valentin Samir committed
52
    """`User` in admin interface"""
Valentin Samir's avatar
Valentin Samir committed
53
    inlines = (ServiceTicketInline, ProxyTicketInline, ProxyGrantingInline)
Valentin Samir's avatar
PEP8  
Valentin Samir committed
54
    readonly_fields = ('username', 'date', "session_key")
55
    fields = ('username', 'date', "session_key")
56
    list_display = ('username', 'date', "session_key")
Valentin Samir's avatar
Valentin Samir committed
57

Valentin Samir's avatar
PEP8  
Valentin Samir committed
58

Valentin Samir's avatar
Valentin Samir committed
59
class UsernamesInline(admin.TabularInline):
Valentin Samir's avatar
Valentin Samir committed
60 61
    """`Username` in admin interface"""
    model = Username
Valentin Samir's avatar
Valentin Samir committed
62
    extra = 0
Valentin Samir's avatar
PEP8  
Valentin Samir committed
63 64


Valentin Samir's avatar
Valentin Samir committed
65
class ReplaceAttributNameInline(admin.TabularInline):
Valentin Samir's avatar
Valentin Samir committed
66
    """`ReplaceAttributName` in admin interface"""
Valentin Samir's avatar
Valentin Samir committed
67 68
    model = ReplaceAttributName
    extra = 0
Valentin Samir's avatar
PEP8  
Valentin Samir committed
69 70


Valentin Samir's avatar
Valentin Samir committed
71
class ReplaceAttributValueInline(admin.TabularInline):
Valentin Samir's avatar
Valentin Samir committed
72
    """`ReplaceAttributValue` in admin interface"""
Valentin Samir's avatar
Valentin Samir committed
73 74
    model = ReplaceAttributValue
    extra = 0
Valentin Samir's avatar
PEP8  
Valentin Samir committed
75 76


Valentin Samir's avatar
Valentin Samir committed
77
class FilterAttributValueInline(admin.TabularInline):
Valentin Samir's avatar
Valentin Samir committed
78
    """`FilterAttributValue` in admin interface"""
Valentin Samir's avatar
Valentin Samir committed
79 80 81
    model = FilterAttributValue
    extra = 0

Valentin Samir's avatar
PEP8  
Valentin Samir committed
82

Valentin Samir's avatar
Valentin Samir committed
83
class ServicePatternAdmin(admin.ModelAdmin):
Valentin Samir's avatar
Valentin Samir committed
84 85 86 87 88 89 90
    """`ServicePattern` in admin interface"""
    inlines = (
        UsernamesInline,
        ReplaceAttributNameInline,
        ReplaceAttributValueInline,
        FilterAttributValueInline
    )
Valentin Samir's avatar
PEP8  
Valentin Samir committed
91 92
    list_display = ('pos', 'name', 'pattern', 'proxy',
                    'single_log_out', 'proxy_callback', 'restrict_users')
Valentin Samir's avatar
Valentin Samir committed
93 94


95
class FederatedIendityProviderAdmin(admin.ModelAdmin):
Valentin Samir's avatar
Valentin Samir committed
96
    """`FederatedIendityProvider` in admin interface"""
97 98
    fields = ('pos', 'suffix', 'server_url', 'cas_protocol_version', 'verbose_name', 'display')
    list_display = ('verbose_name', 'suffix', 'display')
99 100


Valentin Samir's avatar
Valentin Samir committed
101 102
admin.site.register(User, UserAdmin)
admin.site.register(ServicePattern, ServicePatternAdmin)
103
admin.site.register(FederatedIendityProvider, FederatedIendityProviderAdmin)