diff --git a/apps/main/forms.py b/apps/main/forms.py index 941069c..d8c46b9 100644 --- a/apps/main/forms.py +++ b/apps/main/forms.py @@ -1,7 +1,7 @@ from django import forms from django.utils.safestring import mark_safe -from .models import DeviceType, Device, Experiment, Campaign, Configuration +from .models import DeviceType, Device, Experiment, Campaign, Configuration, Location def add_empty_choice(choices, pos=0, label='-----'): if len(choices)>0: @@ -45,6 +45,11 @@ class ExperimentForm(forms.ModelForm): model = Experiment fields = ['campaign', 'name', 'start_time', 'end_time'] +class LocationForm(forms.ModelForm): + class Meta: + model = Location + exclude = [''] + class DeviceForm(forms.ModelForm): class Meta: model = Device @@ -57,4 +62,3 @@ class ConfigurationForm(forms.ModelForm): class DeviceTypeForm(forms.Form): device_type = forms.ChoiceField(choices=add_empty_choice(DeviceType.objects.all().order_by('name').values_list('id', 'name'))) - diff --git a/apps/main/models.py b/apps/main/models.py index 2e0fb2a..cd1e8d1 100644 --- a/apps/main/models.py +++ b/apps/main/models.py @@ -1,9 +1,14 @@ -from itertools import chain from django.db import models from polymorphic import PolymorphicModel from django.core.urlresolvers import reverse +CONF_STATES = ( + (0, 'Disconnected'), + (1, 'Connected'), + (1, 'Running'), + ) + CONF_TYPES = ( (0, 'Active'), (1, 'Historical'), @@ -27,15 +32,22 @@ DEV_TYPES = ( ) # Create your models here. + +class Location(models.Model): + + name = models.CharField(max_length = 30) + description = models.TextField(blank=True, null=True) + + class Meta: + db_table = 'db_location' + + def __unicode__(self): + return u'%s' % self.name class DeviceType(models.Model): name = models.CharField(max_length = 10, choices = DEV_TYPES, default = 'rc') - description = models.TextField(blank=True, null=True) - -# info = models.TextField(blank=True, null=True) -# status = models.PositiveSmallIntegerField(default=1, choices=STATES) class Meta: db_table = 'db_device_types' @@ -46,15 +58,13 @@ class DeviceType(models.Model): class Device(models.Model): device_type = models.ForeignKey(DeviceType) +# location = models.ForeignKey(Location) + name = models.CharField(max_length=40, default='') ip_address = models.GenericIPAddressField(protocol='IPv4', default='0.0.0.0') port_address = models.PositiveSmallIntegerField(default=2000) description = models.TextField(blank=True, null=True) status = models.PositiveSmallIntegerField(default=0, choices=DEV_STATES) - -# serial_number = models.CharField(max_length=40, default='') -# mac_address = models.CharField(max_length = 20, null=True, blank=True) - class Meta: db_table = 'db_devices' @@ -94,8 +104,12 @@ class Configuration(PolymorphicModel): experiment = models.ForeignKey(Experiment) device = models.ForeignKey(Device) + + status = models.PositiveSmallIntegerField(default=0, choices=CONF_STATES) type = models.PositiveSmallIntegerField(default=0, choices=CONF_TYPES) + name = models.CharField(max_length=40, default='') + created_date = models.DateTimeField(auto_now_add=True) programmed_date = models.DateTimeField(auto_now=True) diff --git a/apps/main/templates/base.html b/apps/main/templates/base.html index 992e3f2..7e6ac50 100644 --- a/apps/main/templates/base.html +++ b/apps/main/templates/base.html @@ -37,13 +37,15 @@