source: branches/exodus-admin/exodus/admin.py@ 6398

Last change on this file since 6398 was 6398, checked in by RIck van der Zwet, 16 years ago

Rough template how it should look like, we havely really on inline forms which are far from perfect yet

File size: 2.6 KB
Line 
1from django.contrib import admin
2from django.contrib import databrowse
3from django import forms
4from exodus.models import *
5
6from exodus.wllogic import free_masterip, newSSIDName, addInterlinkIP, \
7 freeInterlinkIP, freePublicAPIP
8
9from exodus.contrib import ReadOnlyAdminFields
10
11class InterfaceCommon(ReadOnlyAdminFields):
12 readonly = ('ip', )
13 def save_model(self, request, obj, form, change):
14 if obj.link and (obj.type != obj.link.type):
15 raise ValueError,'Type of local and remote interface needs to match'
16 if str(obj.type) != "eth":
17 obj.ssid = newSSIDName(obj.node, obj.iface, 'unused')
18 obj.channel = '1'
19 obj.mode = 1 # set to master
20
21 # Only change IP if changes in interface link/mask or new of course :-)
22 #if change or self.is_changed.has_key('link') or \
23 # self.is_changed.has_key('netmask'):
24 if not obj.link:
25 obj.ip = freeInterlinkIP(obj)
26 else:
27 obj.ip = addInterlinkIP(obj.link)
28
29 # XXX: Change in netmask requires full range of netmask changes \
30 # on slaves
31 obj.save()
32 #Dirty to hack to get reference to self working
33 if not obj.link:
34 obj.link = obj
35 obj.save()
36
37
38class PublicAPInline(ReadOnlyAdminFields,admin.TabularInline):
39 model = PublicAP
40 extra = 1
41
42class InterfaceAdmin(InterfaceCommon, admin.ModelAdmin):
43 inlines = (PublicAPInline,)
44 pass
45
46class InterfaceInline(InterfaceCommon, admin.TabularInline):
47 model = Interface
48 extra = 1
49
50class DhcpStaticInline(admin.TabularInline):
51 model = DhcpStatic
52 extra = 1
53
54class PublicAPAdmin(ReadOnlyAdminFields,admin.ModelAdmin):
55 inlines = (DhcpStaticInline,)
56
57class NodeAdmin(admin.ModelAdmin):
58 exclude = ('masterip',)
59# Inline forms sucks bigtime, editing deleting, making readonly broken or non existing
60# XXX: Every save creates a new interface :-(
61 inlines = (InterfaceInline,)
62
63 def save_model(self, request, obj, form, change):
64 #XXX: Testing hidden field commits
65 obj.masterip = free_masterip(obj.network)
66 obj.save()
67
68admin.site.register(Antenna)
69admin.site.register(Location)
70admin.site.register(DnsServer)
71admin.site.register(Network)
72admin.site.register(Node,NodeAdmin)
73admin.site.register(Interface,InterfaceAdmin)
74admin.site.register(PublicAP, PublicAPAdmin)
75admin.site.register(DhcpStatic)
76
77databrowse.site.register(Antenna)
78databrowse.site.register(Location)
79databrowse.site.register(DnsServer)
80databrowse.site.register(Network)
81databrowse.site.register(Node)
82databrowse.site.register(Interface)
83databrowse.site.register(PublicAP)
84databrowse.site.register(DhcpStatic)
Note: See TracBrowser for help on using the repository browser.