##// END OF EJS Templates
Task #487: Vista de Operation...
Task #487: Vista de Operation git-svn-id: http://jro-dev.igp.gob.pe/svn/jro_hard/radarsys/trunk/webapp@92 aa17d016-51d5-4e8b-934c-7b2bbb1bbe71

File last commit:

r57:2d56fb753e14
r71:7bc3ac987634
Show More
models.py
294 lines | 9.0 KiB | text/x-python | PythonLexer
Juan C. Espinoza
Proyecto base en Django (refs #259) ...
r0 from django.db import models
Juan C. Espinoza
Updating base models and views ...
r6 from polymorphic import PolymorphicModel
Juan C. Espinoza
Proyecto base en Django (refs #259) ...
r0
Miguel Urco
DDS app updated...
r32 from django.core.urlresolvers import reverse
Miguel Urco
Location model added to RadarSys...
r41 CONF_STATES = (
Miguel Urco
template attribute added to RadarSys Models...
r47 (0, 'Disconnected'),
(1, 'Connected'),
(1, 'Running'),
)
Miguel Urco
Location model added to RadarSys...
r41
Miguel Urco
Configuration model changed: status and date fields were replaced by type and created fields....
r21 CONF_TYPES = (
Miguel Urco
template attribute added to RadarSys Models...
r47 (0, 'Active'),
(1, 'Historical'),
)
Miguel Urco
status field added to Device and DevConfiguration model...
r16
DEV_STATES = (
Miguel Urco
template attribute added to RadarSys Models...
r47 (0, 'No connected'),
(1, 'Connected'),
(2, 'Configured'),
(3, 'Running'),
)
Juan C. Espinoza
Actualizacion de templates y modelos base #263...
r2
Miguel Urco
Campaign has been added to RadarSys Model...
r13 DEV_TYPES = (
Miguel Urco
template attribute added to RadarSys Models...
r47 ('', 'Select a device type'),
('rc', 'Radar Controller'),
('dds', 'Direct Digital Synthesizer'),
('jars', 'Jicamarca Radar Acquisition System'),
('usrp', 'Universal Software Radio Peripheral'),
('cgs', 'Clock Generator System'),
('abs', 'Automatic Beam Switching'),
)
DEV_PORTS = {
'rc' : 2000,
'dds' : 2000,
'jars' : 2000,
'usrp' : 2000,
'cgs' : 8080,
'abs' : 8080
}
Juan C. Espinoza
Actualizacion de templates y modelos base #263...
r2
Fiorella Quino
Se agrego tabla "Radar" y Estados del Radar...
r49 RADAR_STATES = (
(0, 'No connected'),
(1, 'Connnected'),
(2, 'Configured'),
(3, 'Running'),
(4, 'Scheduled'),
)
Miguel Urco
Campaign has been added to RadarSys Model...
r13 # Create your models here.
Miguel Urco
Location model added to RadarSys...
r41
Miguel Urco
Models changed:...
r53
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
Juan C. Espinoza
Actualizacion de templates y modelos base #263...
r2 class DeviceType(models.Model):
Miguel Urco
Campaign has been added to RadarSys Model...
r13 name = models.CharField(max_length = 10, choices = DEV_TYPES, default = 'rc')
description = models.TextField(blank=True, null=True)
Juan C. Espinoza
Actualizacion de templates y modelos base #263...
r2
class Meta:
Miguel Urco
Campaign has been added to RadarSys Model...
r13 db_table = 'db_device_types'
Juan C. Espinoza
Actualizacion de templates y modelos base #263...
r2
def __unicode__(self):
Miguel Urco
models are passed as instances to templates (dictionaries are not used anymore)...
r22 return u'%s' % self.get_name_display()
Juan C. Espinoza
Actualizacion de templates y modelos base #263...
r2
class Device(models.Model):
Miguel Urco
Models changed:...
r53 device_type = models.ForeignKey(DeviceType, on_delete=models.CASCADE)
location = models.ForeignKey(Location, on_delete=models.CASCADE)
Miguel Urco
Location model added to RadarSys...
r41
Miguel Urco
Device model changed: ...
r9 name = models.CharField(max_length=40, default='')
Juan C. Espinoza
Updating base models and views ...
r6 ip_address = models.GenericIPAddressField(protocol='IPv4', default='0.0.0.0')
Miguel Urco
Campaign has been added to RadarSys Model...
r13 port_address = models.PositiveSmallIntegerField(default=2000)
Miguel Urco
Device model changed: ...
r9 description = models.TextField(blank=True, null=True)
Miguel Urco
status field added to Device and DevConfiguration model...
r16 status = models.PositiveSmallIntegerField(default=0, choices=DEV_STATES)
Juan C. Espinoza
Actualizacion de templates y modelos base #263...
r2
class Meta:
Miguel Urco
Campaign has been added to RadarSys Model...
r13 db_table = 'db_devices'
Juan C. Espinoza
Actualizacion de templates y modelos base #263...
r2
def __unicode__(self):
Miguel Urco
models are passed as instances to templates (dictionaries are not used anymore)...
r22 return u'%s | %s' % (self.name, self.ip_address)
Miguel Urco
template attribute added to RadarSys Models...
r47
def get_status(self):
return self.status
Miguel Urco
Campaign has been added to RadarSys Model...
r13
class Campaign(models.Model):
Miguel Urco
template attribute added to RadarSys Models...
r47 template = models.BooleanField(default=False)
Miguel Urco
Campaign has been added to RadarSys Model...
r13 name = models.CharField(max_length=40, unique=True)
start_date = models.DateTimeField(blank=True, null=True)
end_date = models.DateTimeField(blank=True, null=True)
tags = models.CharField(max_length=40)
description = models.TextField(blank=True, null=True)
class Meta:
db_table = 'db_campaigns'
def __unicode__(self):
Miguel Urco
models are passed as instances to templates (dictionaries are not used anymore)...
r22 return u'%s' % (self.name)
Juan C. Espinoza
Actualizacion de templates y modelos base #263...
r2
Miguel Urco
Models changed:...
r53 # class Radar(models.Model):
#
# # name = models.CharField(max_length = 30)
# experiment = models.ForeignKey('Experiment', on_delete=models.CASCADE)
# location = models.OneToOneField('Location', on_delete=models.CASCADE)
# status = models.PositiveSmallIntegerField(default=0, choices=RADAR_STATES)
#
# class Meta:
# db_table = 'db_radar'
#
# def __unicode__(self):
# return u'%s' % self.location
Fiorella Quino
A "Campaign" has many "Locations", A "Location" has many Experiments....
r48
Fiorella Quino
Se agrego tabla "Radar" y Estados del Radar...
r49
Juan C. Espinoza
Actualizacion de templates y modelos base #263...
r2 class Experiment(models.Model):
Miguel Urco
template attribute added to RadarSys Models...
r47 template = models.BooleanField(default=False)
Miguel Urco
Models changed:...
r53 campaign = models.ForeignKey('Campaign', null=True, blank=True, on_delete=models.CASCADE)
location = models.ForeignKey('Location', null=True, blank=True, on_delete=models.CASCADE)
Miguel Urco
Campaign has been added to RadarSys Model...
r13 name = models.CharField(max_length=40, default='')
start_time = models.TimeField(default='00:00:00')
end_time = models.TimeField(default='23:59:59')
Juan C. Espinoza
Actualizacion de templates y modelos base #263...
r2
class Meta:
Miguel Urco
Campaign has been added to RadarSys Model...
r13 db_table = 'db_experiments'
Juan C. Espinoza
Actualizacion de templates y modelos base #263...
r2
def __unicode__(self):
Miguel Urco
Models changed:...
r53 return u'%s' % (self.name)
Juan C. Espinoza
Updating base models and views ...
r6
class Configuration(PolymorphicModel):
Juan C. Espinoza
Actualizacion de templates y modelos base #263...
r2
Miguel Urco
template attribute added to RadarSys Models...
r47 template = models.BooleanField(default=False)
name = models.CharField(verbose_name="Configuration Name", max_length=40, default='')
Miguel Urco
Models changed:...
r53 experiment = models.ForeignKey('Experiment', null=True, blank=True, on_delete=models.CASCADE)
device = models.ForeignKey(Device, on_delete=models.CASCADE)
Miguel Urco
Location model added to RadarSys...
r41
Miguel Urco
Configuration model changed: status and date fields were replaced by type and created fields....
r21 type = models.PositiveSmallIntegerField(default=0, choices=CONF_TYPES)
Miguel Urco
status field added to Device and DevConfiguration model...
r16
Miguel Urco
models are passed as instances to templates (dictionaries are not used anymore)...
r22 created_date = models.DateTimeField(auto_now_add=True)
programmed_date = models.DateTimeField(auto_now=True)
parameters = models.TextField(default='{}')
Miguel Urco
Models changed:...
r53 message = ""
Juan C. Espinoza
Actualizacion de templates y modelos base #263...
r2 class Meta:
Miguel Urco
Campaign has been added to RadarSys Model...
r13 db_table = 'db_configurations'
Juan C. Espinoza
Actualizacion de templates y modelos base #263...
r2
def __unicode__(self):
Miguel Urco
DDS commands working...
r57 return u'[%s, %s]: %s' % (self.experiment.name,
self.device.name,
self.name)
Miguel Urco
Models changed:...
r53
def parms_to_dict(self):
parameters = {}
for key in self.__dict__.keys():
parameters[key] = getattr(self, key)
return parameters
Miguel Urco
DDS commands working...
r57 def parms_to_text(self):
raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper()
return ''
def parms_to_binary(self):
raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper()
return ''
Miguel Urco
Models changed:...
r53 def dict_to_parms(self, parameters):
if type(parameters) != type({}):
return
for key in parameters.keys():
setattr(self, key, parameters[key])
def export_to_file(self, format="json"):
import json
Miguel Urco
DDS app updated...
r32
Miguel Urco
DDS commands working...
r57 content_type = ''
Miguel Urco
Models changed:...
r53
if format == 'text':
content_type = 'text/plain'
Miguel Urco
DDS commands working...
r57 filename = '%s_%s.%s' %(self.device.device_type.name, self.name, self.device.device_type.name)
content = self.parms_to_text()
Miguel Urco
Models changed:...
r53
if format == 'binary':
content_type = 'application/octet-stream'
Miguel Urco
DDS commands working...
r57 filename = '%s_%s.bin' %(self.device.device_type.name, self.name)
content = self.parms_to_binary()
if not content_type:
content_type = 'application/json'
filename = '%s_%s.json' %(self.device.device_type.name, self.name)
content = json.dumps(self.parms_to_dict())
Miguel Urco
Models changed:...
r53
fields = {'content_type':content_type,
'filename':filename,
'content':content
}
return fields
Miguel Urco
DDS commands working...
r57 def import_from_file(self, fp):
import os, json
parms = {}
path, ext = os.path.splitext(fp.name)
Miguel Urco
Models changed:...
r53
Miguel Urco
DDS commands working...
r57 if ext == '.json':
parms = json.load(fp)
Miguel Urco
Models changed:...
r53
Miguel Urco
DDS commands working...
r57 return parms
Miguel Urco
Models changed:...
r53
def status_device(self):
Miguel Urco
DDS commands working...
r57 raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper()
Miguel Urco
Models changed:...
r53
return None
def stop_device(self):
Miguel Urco
DDS commands working...
r57 raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper()
Miguel Urco
Models changed:...
r53
return None
def start_device(self):
Miguel Urco
DDS commands working...
r57 raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper()
Miguel Urco
Models changed:...
r53
return None
def write_device(self, parms):
Miguel Urco
DDS commands working...
r57 raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper()
Miguel Urco
Models changed:...
r53
return None
def read_device(self):
Miguel Urco
DDS commands working...
r57 raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper()
Miguel Urco
Models changed:...
r53
return None
Miguel Urco
template attribute added to RadarSys Models...
r47 def get_absolute_url(self):
Juan C. Espinoza
Add rc config mods...
r23 return reverse('url_%s_conf' % self.device.device_type.name, args=[str(self.id)])
Miguel Urco
Buttons "Import", "Export, "Read" and "Write" added to Configuration View...
r30
def get_absolute_url_edit(self):
return reverse('url_edit_%s_conf' % self.device.device_type.name, args=[str(self.id)])
def get_absolute_url_import(self):
Miguel Urco
Models changed:...
r53 return reverse('url_import_dev_conf', args=[str(self.id)])
Miguel Urco
Buttons "Import", "Export, "Read" and "Write" added to Configuration View...
r30
def get_absolute_url_export(self):
Miguel Urco
Models changed:...
r53 return reverse('url_export_dev_conf', args=[str(self.id)])
Miguel Urco
Buttons "Import", "Export, "Read" and "Write" added to Configuration View...
r30
def get_absolute_url_write(self):
Miguel Urco
Models changed:...
r53 return reverse('url_write_dev_conf', args=[str(self.id)])
Miguel Urco
Buttons "Import", "Export, "Read" and "Write" added to Configuration View...
r30
def get_absolute_url_read(self):
Miguel Urco
Models changed:...
r53 return reverse('url_read_dev_conf', args=[str(self.id)])
Fiorella Quino
Se agrego tabla "Radar" y Estados del Radar...
r49
Miguel Urco
Models changed:...
r53 def get_absolute_url_start(self):
return reverse('url_start_dev_conf', args=[str(self.id)])
Fiorella Quino
Se agrego tabla "Radar" y Estados del Radar...
r49
Miguel Urco
Models changed:...
r53 def get_absolute_url_stop(self):
return reverse('url_stop_dev_conf', args=[str(self.id)])
def get_absolute_url_status(self):
return reverse('url_status_dev_conf', args=[str(self.id)])