Changeset 6437
- Timestamp:
- Dec 10, 2008, 11:05:12 PM (16 years ago)
- Location:
- trunk/exodus
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/exodus/admin.py
r6435 r6437 2 2 from django.contrib import admin 3 3 from django.contrib import databrowse 4 from django import forms5 from exodus.models import * 4 from exodus.models import Location, Node, Network, Interface, Antenna, \ 5 DnsServer, DhcpStatic 6 6 from exodus.forms import NodeForm, InterfaceForm 7 7 from exodus.contrib import ReadOnlyAdminFields … … 10 10 plain_admin = AdminSite() 11 11 12 #class PublicAPInline(admin.TabularInline):13 # model = PublicAP14 # extra = 115 16 class InterfaceInline(admin.TabularInline):17 model = Interface18 form = InterfaceForm19 extra = 220 fieldsets = (21 (None, {22 'classes': ('collapse',),23 'fields': ('type', 'iface', 'polar', 'antenna', 'link')24 }),25 )26 #inlines = [ PublicAPInline, ]27 28 12 class NodeAdmin(ReadOnlyAdminFields, admin.ModelAdmin): 29 13 readonly = ('masterip', ) 30 14 form = NodeForm 31 15 list_display = ('name', 'location','network') 32 search_fields = ['name']16 search_fields = ('name',) 33 17 list_filter = ('network',) 34 18 fieldsets = ( … … 38 22 ) 39 23 40 inlines = [InterfaceInline, ] 41 42 class NodeInline(admin.TabularInline): 43 model = Node 44 form = NodeForm 45 extra = 2 46 fields = ('name', 'status', 'location', 'network') 47 48 class LocationAdmin(admin.ModelAdmin): 49 search_fields = ['description'] 50 inlines = [ NodeInline, ] 24 class InterfaceAdmin(ReadOnlyAdminFields, admin.ModelAdmin): 25 #readonly = ('ip', 'netmask', 'mode', 'ssid', 'shortdesc', 'desc') 26 form = InterfaceForm 27 list_display = ('node', 'iface', 'type', 'ip', 'channel', 'polar', 28 'shortdesc', 'link') 29 search_fields = ('node__name','iface') 30 list_filter = ('type', 'accesspoint', 'polar', 'node', 'antenna') 31 ordering =('node',) 51 32 52 33 advanced_admin.register(Antenna) 53 advanced_admin.register(Location , LocationAdmin)34 advanced_admin.register(Location) 54 35 advanced_admin.register(DnsServer) 55 36 advanced_admin.register(Network) 56 37 advanced_admin.register(Node, NodeAdmin) 57 advanced_admin.register(Interface )38 advanced_admin.register(Interface, InterfaceAdmin) 58 39 #advanced_admin.register(PublicAP) 59 40 advanced_admin.register(DhcpStatic) -
trunk/exodus/forms.py
r6434 r6437 1 1 from django import forms 2 2 from exodus.models import Node, Interface 3 from exodus.wllogic import free_master_ip, free_interlink_ip, add_interlink_ip 4 from exodus.contrib import ReadOnlyWidget 3 from exodus.wllogic import free_master_ip, link_has_compat_type 5 4 6 5 class NodeForm(forms.ModelForm): 7 #masterip = forms.IPAddressField(widget=forms.HiddenInput)8 6 class Meta: 9 7 model = Node … … 29 27 class Meta: 30 28 model = Interface 29 30 def clean_link(self): 31 import pdb; pdb.set_trace() ; 32 link = self.cleaned_data.get('link') 33 34 if link: 35 try: 36 # if link is to self we don't need to check anything else 37 if self.instance.pk == link.pk: 38 return link 39 # Link can't be to same node. 40 if self.instance.node_id == link.node_id: 41 raise forms.ValidationError( 42 "A link can't be to another interface on the same node") 43 except Interface.DoesNotExist: 44 pass 45 if self.cleaned_data.get('accesspoint') and \ 46 self.instance.pk != link.pk: 47 raise forms.ValidationError( "A link can't be made to another interface when this interface has an accesspoint.") 48 49 # if link is referenced to itself, link is master and linkable 50 if link.link.pk == link.pk: 51 return link 52 53 # if we get at this elif, it means that link is in managed mode 54 # but masterlink and managed can be switched 55 # And check if that master has only 2, including himself, links 56 # and is not an accesspoint himself. 57 elif len(link.link.interface_set.all()) == 2 and not \ 58 link.link.accesspoint: 59 import pdb; pdb.set_trace() 60 # convert master to slave 61 #XXX: update mode 62 old_slave = link 63 old_master = old_slave.link 64 old_master.link = old_slave 65 old_slave.link = old_slave 66 old_slave.save() 67 old_master.save() 68 #XXX: do ip address switch stuff 69 return link 70 71 # check if the two links are compatible 72 type = self.cleaned_data.get('type') 73 if not link_has_compat_type(link.type, type): 74 raise forms.ValidationError( 75 'Link type %s is not compatible with %s' 76 %(link.type, type)) 77 78 79 return link 80 -
trunk/exodus/models.py
r6432 r6437 116 116 shortdesc = models.CharField(blank=True, max_length=10) 117 117 desc = models.CharField(blank=True, max_length=100) 118 accesspoint = models.BooleanField() 118 119 link = models.ForeignKey('self', blank=True, null=True) 119 accesspoint = models.BooleanField()120 120 121 121 class Meta: -
trunk/exodus/wllogic.py
r6432 r6437 154 154 return True 155 155 156 def link_has_compat_type(link1, link2): 157 # if this is a link to self, the link is always valid 158 if link1 == link2: 159 return True 156 def link_has_compat_type(type1, type2): 160 157 # link types must the same 161 if link1.type == link2.type:158 if type1 == type2: 162 159 return True 163 160 # or link types must be compatible 164 161 compat = ('11b', '11g') 165 if link1.type in compat and link2.typein compat:162 if type1 in compat and type2 in compat: 166 163 return True 167 164
Note:
See TracChangeset
for help on using the changeset viewer.