- Timestamp:
- Nov 29, 2008, 3:51:29 PM (16 years ago)
- Location:
- branches/exodus-admin/exodus
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/exodus-admin/exodus/admin.py
r6397 r6398 1 1 from django.contrib import admin 2 2 from django.contrib import databrowse 3 from django import forms 3 4 from exodus.models import * 5 6 from exodus.wllogic import free_masterip, newSSIDName, addInterlinkIP, \ 7 freeInterlinkIP, freePublicAPIP 8 9 from exodus.contrib import ReadOnlyAdminFields 10 11 class 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 38 class PublicAPInline(ReadOnlyAdminFields,admin.TabularInline): 39 model = PublicAP 40 extra = 1 41 42 class InterfaceAdmin(InterfaceCommon, admin.ModelAdmin): 43 inlines = (PublicAPInline,) 44 pass 45 46 class InterfaceInline(InterfaceCommon, admin.TabularInline): 47 model = Interface 48 extra = 1 49 50 class DhcpStaticInline(admin.TabularInline): 51 model = DhcpStatic 52 extra = 1 53 54 class PublicAPAdmin(ReadOnlyAdminFields,admin.ModelAdmin): 55 inlines = (DhcpStaticInline,) 4 56 5 57 class NodeAdmin(admin.ModelAdmin): 6 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,) 7 62 8 63 def save_model(self, request, obj, form, change): 9 64 #XXX: Testing hidden field commits 10 obj.masterip = '172.168.1.1'65 obj.masterip = free_masterip(obj.network) 11 66 obj.save() 12 67 … … 16 71 admin.site.register(Network) 17 72 admin.site.register(Node,NodeAdmin) 18 admin.site.register(Interface )19 admin.site.register(PublicAP )73 admin.site.register(Interface,InterfaceAdmin) 74 admin.site.register(PublicAP, PublicAPAdmin) 20 75 admin.site.register(DhcpStatic) 21 76 -
branches/exodus-admin/exodus/models.py
r6389 r6398 45 45 gain = models.IntegerField(max_length=3) 46 46 47 class Meta: 48 verbose_name = 'Antenna' 49 47 50 def __str__(self): 48 51 return self.type … … 84 87 85 88 89 90 86 91 class Node(ExtendedModel): 87 92 name = models.CharField(max_length=30, unique=True) … … 104 109 iface = models.CharField(max_length=10, verbose_name="interface", \ 105 110 default='eth0') 106 ip = models.IPAddressField(unique=True )111 ip = models.IPAddressField(unique=True, blank=True) 107 112 netmask = models.IntegerField(default=30) 108 113 polar = models.CharField(blank=True, max_length=10, choices=POLAR_CHOICES) 109 114 ssid = models.CharField(max_length=30, blank=True, null=True) 110 mode = models.CharField(max_length=10, choices=WIFI_MODE_CHOICES )115 mode = models.CharField(max_length=10, choices=WIFI_MODE_CHOICES, blank=True) 111 116 channel = models.IntegerField(blank=True, null=True) 112 117 antenna = models.ForeignKey(Antenna, blank=True, null=True) … … 116 121 117 122 class Meta: 118 unique_together = ('node', 'iface')123 #unique_together = ('node', 'iface') 119 124 verbose_name = 'Interface' 120 125
Note:
See TracChangeset
for help on using the changeset viewer.