Skip to content
Browse files

Merge branch 'refactoring' into dns

  • Loading branch information...
2 parents 59515e6 + 5ecb918 commit a16259a0c71c3b0b94946872886379d464198a44 @sigsalerno sigsalerno committed Aug 7, 2012
View
12 nodeshot/core/base/admin.py
@@ -3,11 +3,15 @@
class BaseAdmin(admin.ModelAdmin):
"""
Abstract administration model for BaseDate models.
- * 'added' and 'updated' fields are everytime readonly
- * save on top button is everytime present
+ * 'added' and 'updated' fields readonly
+ * save-on-top button enabled by default
"""
save_on_top = True
readonly_fields = ['added', 'updated']
- class Meta:
- abstract = True
+ #class Meta:
+ # abstract = True
+
+class BaseStackedInline(admin.StackedInline):
+ readonly_fields = ('added', 'updated')
+ extra = 0
View
2 nodeshot/core/base/choices.py
@@ -135,7 +135,7 @@
#(6, _('batman')),
)
-WIRELESS_STANDARD = (
+WIRELESS_STANDARDS = (
('802.11a', '802.11a'),
('802.11b', '802.11b'),
('802.11g', '802.11g'),
View
7 nodeshot/core/base/models.py
@@ -1,5 +1,6 @@
from django.db import models
from django.utils.translation import ugettext_lazy as _
+from django.utils.timezone import utc
from datetime import datetime
from nodeshot.core.base.choices import ACCESS_LEVELS
@@ -10,14 +11,14 @@ class BaseDate(models.Model):
* an updated field which updates itself automatically
We don't use django's autoaddnow=True because that makes the fields not visible in the admin.
"""
- added = models.DateTimeField(_('created on'), default=datetime.now)
- updated = models.DateTimeField(_('updated on'))
+ added = models.DateTimeField(_('created on'), default=datetime.utcnow().replace(tzinfo=utc))
+ updated = models.DateTimeField(_('updated on'), default=datetime.utcnow().replace(tzinfo=utc))
def save(self, *args, **kwargs):
"""
automatically update updated date field
"""
- self.updated = datetime.now()
+ self.updated = datetime.utcnow().replace(tzinfo=utc)
super(BaseDate, self).save(*args, **kwargs)
class Meta:
View
2 nodeshot/core/links/models.py
@@ -7,7 +7,7 @@
class Link(BaseAccessLevel):
interface_a = models.ForeignKey(Interface, related_name='interface_a')
interface_b = models.ForeignKey(Interface, related_name='interface_b')
- type = models.SmallInteger(_('type'), max_length=10, choices=LINK_TYPE, default=LINK_TYPE[0][0])
+ type = models.SmallIntegerField(_('type'), max_length=10, choices=LINK_TYPE, default=LINK_TYPE[0][0])
metric_type = models.CharField(_('metric type'), max_length=6, choices=METRIC_TYPES, default=METRIC_TYPES[0][0])
metric_value = models.FloatField(_('metric value'))
tx_rate = models.IntegerField(_('TX rate average'), null=True, default=None)
View
42 nodeshot/core/network/admin.py
@@ -1,13 +1,45 @@
from django.contrib import admin
-from nodeshot.core import network
-from nodeshot.core.base.admin import BaseAdmin
+from nodeshot.core.network.models import Device, Interface, Ethernet, Wireless, Bridge, Tunnel, Vap, Vlan, RoutingProtocol, Ip
+from nodeshot.core.base.admin import BaseAdmin, BaseStackedInline
+
+class InterfaceInline(BaseStackedInline):
+ model = Interface
+
+class IpInline(BaseStackedInline):
+ model = Ip
+
+class VapInline(BaseStackedInline):
+ model = Vap
class DeviceAdmin(BaseAdmin):
- pass
+ list_filter = ('added', 'updated', 'node')
+ list_display = ('name', 'node', 'type', 'added', 'updated')
+ search_fields = ('name', 'type')
+ inlines = (InterfaceInline,)
class InterfaceAdmin(BaseAdmin):
+ list_display = ('mac', 'name', 'type', 'device', 'added', 'updated')
+ search_fields = ('mac',)
+ inlines = (IpInline,)
+
+class WirelessAdmin(InterfaceAdmin):
+ inlines = (IpInline,VapInline)
+
+class RoutingProtocolAdmin(BaseAdmin):
pass
-admin.site.register(network.models.Device, DeviceAdmin)
-admin.site.register(network.models.Interface, InterfaceAdmin)
+class IpAdmin(BaseAdmin):
+ pass
+
+admin.site.register(Device, DeviceAdmin)
+#admin.site.register(Interface, InterfaceAdmin)
+
+admin.site.register(Ethernet, InterfaceAdmin)
+admin.site.register(Wireless, WirelessAdmin)
+admin.site.register(Bridge, InterfaceAdmin)
+admin.site.register(Tunnel, InterfaceAdmin)
+admin.site.register(Vlan, InterfaceAdmin)
+
+admin.site.register(RoutingProtocol, RoutingProtocolAdmin)
+admin.site.register(Ip, IpAdmin)
View
7 nodeshot/core/network/models.py
@@ -2,7 +2,7 @@
from django.utils.translation import ugettext_lazy as _
from nodeshot.core.base.models import BaseDate, BaseAccessLevel
from nodeshot.core.nodes.models import Node
-from nodeshot.core.base.choices import ROUTING_PROTOCOLS, DEVICE_STATUS, DEVICE_TYPES, INTERFACE_TYPE, IP_PROTOCOLS, ETHERNET_STANDARDS, DUPLEX_CHOICES
+from nodeshot.core.base.choices import ROUTING_PROTOCOLS, DEVICE_STATUS, DEVICE_TYPES, INTERFACE_TYPE, IP_PROTOCOLS, ETHERNET_STANDARDS, WIRELESS_STANDARDS, DUPLEX_CHOICES
class RoutingProtocol(BaseDate):
name = models.CharField(_('name'), max_length=50, choices=ROUTING_PROTOCOLS)
@@ -21,6 +21,7 @@ class Device(BaseAccessLevel):
firmware = models.CharField(_('firmware'), max_length=20, blank=True, null=True)
os = models.CharField(_('operating system'), max_length=20, blank=True, null=True)
description = models.CharField(_('description'), max_length=255, blank=True, null=True)
+ #notes = models.TextField(_('notes'), blank=True, null=True)
class Interface(BaseAccessLevel):
device = models.ForeignKey(Device)
@@ -46,7 +47,7 @@ class Meta:
class Wireless(Interface):
wireless_mode = models.CharField(max_length=5)
- wireless_standard = models.CharField(max_length=7)
+ wireless_standard = models.CharField(max_length=7, choices=WIRELESS_STANDARDS)
wireless_channel = models.CharField(max_length=4, blank=True, null=True)
channel_width = models.CharField(max_length=6, blank=True, null=True)
transmitpower = models.IntegerField(null=True, blank=True)
@@ -77,7 +78,7 @@ class Meta:
db_table = 'network_interface_vlan'
class Vap(BaseDate):
- interface = models.ForeignKey(Wireless, verbose_name='interface')
+ interface = models.ForeignKey(Wireless, verbose_name='wireless interface')
essid = models.CharField(max_length=50)
bssid = models.CharField(max_length=50, null=True, blank=True)
encryption = models.CharField(max_length=50, null=True, blank=True)
View
19 nodeshot/core/nodes/admin.py
@@ -1,12 +1,21 @@
from django.contrib import admin
-from nodeshot.core import nodes
-from nodeshot.core.base.admin import BaseAdmin
+from nodeshot.core.nodes.models import Node, Zone
+from nodeshot.core.network.models import Device
+from nodeshot.core.base.admin import BaseAdmin, BaseStackedInline
+
+class DeviceInline(BaseStackedInline):
+ model = Device
class ZoneAdmin(BaseAdmin):
pass
class NodeAdmin(BaseAdmin):
- pass
+ list_display = ('name', 'user', 'status', 'added', 'updated')
+ list_filter = ('status', 'added')
+ date_hierarchy = 'added'
+ ordering = ('-id',)
+ prepopulated_fields = {'slug': ('name',)}
+ inlines = (DeviceInline,)
-admin.site.register(nodes.models.Zone, ZoneAdmin)
-admin.site.register(nodes.models.Node, NodeAdmin)
+admin.site.register(Zone, ZoneAdmin)
+admin.site.register(Node, NodeAdmin)
View
8 projects/ninux/ninux/settings.example.py
@@ -28,11 +28,11 @@
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# In a Windows environment this must be set to your system time zone.
-TIME_ZONE = 'America/Chicago'
+TIME_ZONE = 'Europe/Rome'
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
-LANGUAGE_CODE = 'en-us'
+LANGUAGE_CODE = 'en-gb'
SITE_ID = 1
@@ -103,10 +103,10 @@
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
-ROOT_URLCONF = 'nodeshot.urls'
+ROOT_URLCONF = 'myproject.urls' # replace myproject with the name of your project. Default project is "ninux".
# Python dotted path to the WSGI application used by Django's runserver.
-WSGI_APPLICATION = 'nodeshot.wsgi.application'
+WSGI_APPLICATION = 'myproject.wsgi.application'
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
View
3 projects/ninux/ninux/wsgi.py
@@ -14,9 +14,8 @@
"""
import os
-
import sys
-sys.path.append("/home/nodeshot/nodeshot/projects/ninux/")
+sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ninux.settings")

0 comments on commit a16259a

Please sign in to comment.
Something went wrong with that request. Please try again.