1 # -*- coding: utf-8 -*- vim:fileencoding=utf-8:
2 # vim: tabstop=4:shiftwidth=4:softtabstop=4:expandtab
4 # Copyright (C) 2010-2014 GRNET S.A.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 from django.contrib import admin
21 from flowspec.models import *
22 from accounts.models import *
23 from utils import proxy as PR
25 from django.contrib.auth.models import User
26 from django.contrib.auth.admin import UserAdmin
27 from peers.models import *
28 from flowspec.forms import *
30 from django.conf import settings
31 from longerusername.forms import UserCreationForm, UserChangeForm
34 class RouteAdmin(admin.ModelAdmin):
36 actions = ['deactivate']
38 def deactivate(self, request, queryset):
39 queryset = queryset.filter(status='ACTIVE')
40 response = batch_delete.delay(queryset, reason="ADMININACTIVE")
41 self.message_user(request, "Added request %s to job que. Check in a while for result" % response)
42 deactivate.short_description = "Remove selected routes from network"
44 def save_model(self, request, obj, form, change):
45 obj.status = "PENDING"
52 def has_delete_permission(self, request, obj=None):
55 list_display = ('name', 'status', 'applier' , 'applier_peer', 'get_match', 'get_then', 'response', "expires", "comments")
58 (None, {'fields': ['name','applier']}),
59 ("Match", {'fields': ['source', 'sourceport', 'destination', 'destinationport', 'port']}),
60 ('Advanced Match Statements', {'fields': ['dscp', 'fragmenttype', 'icmpcode', 'icmptype', 'packetlength', 'protocol', 'tcpflag'], 'classes': ['collapse']}),
61 ("Then", {'fields': ['then' ]}),
62 ("Expires", {'fields': ['expires' ]}),
63 (None, {'fields': ['comments',]}),
69 class UserProfileInline(admin.StackedInline):
72 class UserProfileAdmin(UserAdmin):
73 add_form = UserCreationForm
75 actions = ['deactivate', 'activate']
76 list_display = ('username', 'email', 'first_name' , 'last_name', 'is_staff', 'is_active', 'is_superuser', 'get_userprofile_peer')
77 inlines = [UserProfileInline]
79 def deactivate(self, request, queryset):
80 queryset = queryset.update(is_active=False)
81 deactivate.short_description = "Deactivate Selected Users"
83 def activate(self, request, queryset):
84 queryset = queryset.update(is_active=True)
85 activate.short_description = "Activate Selected Users"
87 def get_userprofile_peer(self, instance):
88 # instance is User instance
89 return instance.get_profile().peer
90 get_userprofile_peer.short_description = "User Peer"
91 # fields = ('name', 'applier', 'expires')
93 #def formfield_for_dbfield(self, db_field, **kwargs):
94 # if db_field.name == 'password':
95 # kwargs['widget'] = PasswordInput
96 # return db_field.formfield(**kwargs)
98 admin.site.unregister(User)
99 admin.site.register(MatchPort)
100 admin.site.register(MatchProtocol)
101 admin.site.register(MatchDscp)
102 admin.site.register(ThenAction)
103 admin.site.register(FragmentType)
104 admin.site.register(Route, RouteAdmin)
105 admin.site.register(User, UserProfileAdmin)
106 admin.site.disable_action('delete_selected')