Changeset 6398 for branches


Ignore:
Timestamp:
Nov 29, 2008, 3:51:29 PM (16 years ago)
Author:
RIck van der Zwet
Message:

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

Location:
branches/exodus-admin/exodus
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • branches/exodus-admin/exodus/admin.py

    r6397 r6398  
    11from django.contrib import admin
    22from django.contrib import databrowse
     3from django import forms
    34from 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,)
    456
    557class NodeAdmin(admin.ModelAdmin):
    658    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,)
    762
    863    def save_model(self, request, obj, form, change):
    964        #XXX: Testing hidden field commits
    10         obj.masterip = '172.168.1.1'
     65        obj.masterip = free_masterip(obj.network)
    1166        obj.save()
    1267
     
    1671admin.site.register(Network)
    1772admin.site.register(Node,NodeAdmin)
    18 admin.site.register(Interface)
    19 admin.site.register(PublicAP)
     73admin.site.register(Interface,InterfaceAdmin)
     74admin.site.register(PublicAP, PublicAPAdmin)
    2075admin.site.register(DhcpStatic)
    2176
  • branches/exodus-admin/exodus/models.py

    r6389 r6398  
    4545    gain = models.IntegerField(max_length=3)
    4646
     47    class Meta:
     48        verbose_name = 'Antenna'
     49
    4750    def __str__(self):
    4851        return self.type
     
    8487
    8588
     89
     90
    8691class Node(ExtendedModel):
    8792    name = models.CharField(max_length=30, unique=True)
     
    104109        iface = models.CharField(max_length=10, verbose_name="interface", \
    105110            default='eth0')
    106         ip = models.IPAddressField(unique=True)
     111        ip = models.IPAddressField(unique=True, blank=True)
    107112        netmask = models.IntegerField(default=30)
    108113        polar = models.CharField(blank=True, max_length=10, choices=POLAR_CHOICES)
    109114        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)
    111116        channel = models.IntegerField(blank=True, null=True)
    112117        antenna = models.ForeignKey(Antenna, blank=True, null=True)
     
    116121       
    117122        class Meta:
    118                 unique_together = ('node', 'iface')
     123                #unique_together = ('node', 'iface')
    119124                verbose_name = 'Interface'
    120125       
Note: See TracChangeset for help on using the changeset viewer.