Statistics
| Branch: | Tag: | Revision:

root / flowspec / admin.py @ 6d153302

History | View | Annotate | Download (2.3 kB)

1
from django.contrib import admin
2
from flowspy.flowspec.models import *
3
from flowspy.accounts.models import *
4
from utils import proxy as PR
5
from flowspec.tasks import *
6
from django.contrib.auth.models import User
7
from django.contrib.auth.admin import UserAdmin
8
from accounts.models import UserProfile
9

    
10

    
11
class RouteAdmin(admin.ModelAdmin):
12
    
13
    actions = ['deactivate']
14
    
15
    def deactivate(self, request, queryset):
16
        queryset = queryset.filter(status='ACTIVE')
17
        rows = queryset.update(status='PENDING')
18
        response = batch_delete.delay(queryset, reason="ADMININACTIVE")
19
        self.message_user(request, "Added request %s to job que. Check in a while for result" % response)
20
    deactivate.short_description = "Remove selected routes from network"
21

    
22
    list_display = ('name', 'status', 'applier' , 'applier_peer', 'get_match', 'get_then', 'response', "expires", "comments")
23

    
24
    fieldsets = [
25
        (None,               {'fields': ['name','applier']}),
26
        ("Match",               {'fields': ['source', 'sourceport', 'destination', 'destinationport', 'port']}),
27
        ('Advanced Match Statements', {'fields': ['dscp', 'fragmenttype', 'icmpcode', 'icmptype', 'packetlength', 'protocol', 'tcpflag'], 'classes': ['collapse']}),
28
        ("Then",               {'fields': ['then' ]}),
29
        (None,               {'fields': ['comments',]}),
30
        
31
    ]
32
    
33
class UserProfileInline(admin.StackedInline):
34
    model = UserProfile
35
    
36
class UserProfileAdmin(UserAdmin):
37
    inlines = [UserProfileInline]
38
#    fields = ('name', 'applier', 'expires')
39

    
40
    #def formfield_for_dbfield(self, db_field, **kwargs):
41
    #    if db_field.name == 'password':
42
    #        kwargs['widget'] = PasswordInput
43
    #    return db_field.formfield(**kwargs)
44

    
45
#admin.site.register(MatchAddress)
46
admin.site.unregister(User)
47
admin.site.register(MatchPort)
48
admin.site.register(MatchDscp)
49
admin.site.register(UserProfile)
50
#admin.site.register(MatchFragmentType)
51
#admin.site.register(MatchIcmpCode)
52
#admin.site.register(MatchIcmpType)
53
#admin.site.register(MatchPacketLength)
54
#admin.site.register(MatchProtocol)
55
#admin.site.register(MatchTcpFlag)
56
admin.site.register(ThenAction)
57
#admin.site.register(ThenStatement)
58
#admin.site.register(MatchStatement)
59
admin.site.register(Route, RouteAdmin)
60
admin.site.register(User, UserProfileAdmin)
61
admin.site.disable_action('delete_selected')
62

    
63