##// END OF EJS Templates
Update new and edit "views"...
Update new and edit "views" git-svn-id: http://jro-dev.igp.gob.pe/svn/jro_hard/radarsys/trunk/webapp@112 aa17d016-51d5-4e8b-934c-7b2bbb1bbe71

File last commit:

r91:620bd5874a5a
r91:620bd5874a5a
Show More
models.py
389 lines | 11.8 KiB | text/x-python | PythonLexer
Juan C. Espinoza
Update several views and models in main app...
r85
from datetime import datetime
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'),
Fiorella Quino
Main Models...
r72 (2, 'Running'),
)
EXP_STATES = (
Fiorella Quino
Task #487: Operation. Views: radar_play y radar_stop. Models: RunningExperiment. Attributes: status. Methods: get_status(), status_color()...
r84 (0,'Error'), #RED
(1,'Configurated'), #BLUE
(2,'Running'), #GREEN
(3,'Waiting'), #YELLOW
(4,'Not Configured'), #WHITE
Miguel Urco
template attribute added to RadarSys Models...
r47 )
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'),
Fiorella Quino
Task #487: Operation. Views: radar_play y radar_stop. Models: RunningExperiment. Attributes: status. Methods: get_status(), status_color()...
r84 (1, 'Connected'),
Fiorella Quino
Se agrego tabla "Radar" y Estados del Radar...
r49 (2, 'Configured'),
(3, 'Running'),
(4, 'Scheduled'),
)
Miguel Urco
Campaign has been added to RadarSys Model...
r13 # Create your models here.
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
Update views and templates of main app...
r89 def get_absolute_url(self):
return reverse('url_device', args=[str(self.id)])
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
Juan C. Espinoza
Update views and templates of main app...
r89 def get_status(self):
Miguel Urco
template attribute added to RadarSys Models...
r47 return self.status
Juan C. Espinoza
Update views and templates of main app...
r89 def get_absolute_url(self):
return reverse('url_device', args=[str(self.id)])
Miguel Urco
Campaign has been added to RadarSys Model...
r13
class Campaign(models.Model):
Juan C. Espinoza
Update several views and models in main app...
r85 template = models.BooleanField(default=False)
name = models.CharField(max_length=60, unique=True)
Miguel Urco
Campaign has been added to RadarSys Model...
r13 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)
Juan C. Espinoza
Update several views and models in main app...
r85 experiments = models.ManyToManyField('Experiment', blank=True)
Miguel Urco
Campaign has been added to RadarSys Model...
r13
class Meta:
db_table = 'db_campaigns'
Juan C. Espinoza
Update several views and models in main app...
r85 ordering = ('name',)
Miguel Urco
Campaign has been added to RadarSys Model...
r13
def __unicode__(self):
Miguel Urco
models are passed as instances to templates (dictionaries are not used anymore)...
r22 return u'%s' % (self.name)
Fiorella Quino
Main Models...
r72
Juan C. Espinoza
Update views and templates of main app...
r89 def get_absolute_url(self):
return reverse('url_campaign', args=[str(self.id)])
Juan C. Espinoza
Update several views and models in main app...
r85
Fiorella Quino
Task #487: Operation. Views: radar_play y radar_stop. Models: RunningExperiment. Attributes: status. Methods: get_status(), status_color()...
r84 class RunningExperiment(models.Model):
radar = models.OneToOneField('Location', on_delete=models.CASCADE)
running_experiment = models.ManyToManyField('Experiment')
status = models.PositiveSmallIntegerField(default=0, choices=RADAR_STATES)
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):
Juan C. Espinoza
Update several views and models in main app...
r85 template = models.BooleanField(default=False)
location = models.ForeignKey('Location', null=True, blank=True, on_delete=models.CASCADE)
name = models.CharField(max_length=40, default='', unique=True)
Miguel Urco
Models changed:...
r53 location = models.ForeignKey('Location', null=True, blank=True, on_delete=models.CASCADE)
Miguel Urco
Campaign has been added to RadarSys Model...
r13 start_time = models.TimeField(default='00:00:00')
end_time = models.TimeField(default='23:59:59')
Fiorella Quino
Task #487: Operation. Views: radar_play y radar_stop. Models: RunningExperiment. Attributes: status. Methods: get_status(), status_color()...
r84 status = models.PositiveSmallIntegerField(default=0, choices=EXP_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_experiments'
Juan C. Espinoza
Update new and edit "views"...
r91 ordering = ('template', 'name')
Juan C. Espinoza
Actualizacion de templates y modelos base #263...
r2
def __unicode__(self):
Juan C. Espinoza
Update new and edit "views"...
r91 if self.template:
return u'%s (template)' % (self.name)
else:
return u'%s' % (self.name)
Juan C. Espinoza
Updating base models and views ...
r6
Juan C. Espinoza
Update views and templates of main app...
r89 @property
def radar(self):
return self.location
Juan C. Espinoza
Update several views and models in main app...
r85 def clone(self, **kwargs):
confs = Configuration.objects.filter(experiment=self, type=0)
self.pk = None
self.name = '{} [{:%Y/%m/%d}]'.format(self.name, datetime.now())
for attr, value in kwargs.items():
setattr(self, attr, value)
self.save()
for conf in confs:
conf.clone(experiment=self, template=False)
return self
Fiorella Quino
Task #487: Operation. Views: radar_play y radar_stop. Models: RunningExperiment. Attributes: status. Methods: get_status(), status_color()...
r84
def get_status(self):
configurations = Configuration.objects.filter(experiment=self)
exp_status=[]
for conf in configurations:
print conf.status_device()
exp_status.append(conf.status_device())
if not exp_status: #No Configuration
self.status = 4
self.save()
return
total = 1
for e_s in exp_status:
total = total*e_s
if total == 0: #Error
status = 0
elif total == (3**len(exp_status)): #Running
status = 2
else:
status = 1 #Configurated
self.status = status
self.save()
def status_color(self):
color = 'danger'
if self.status == 0:
color = "danger"
elif self.status == 1:
color = "info"
elif self.status == 2:
Juan C. Espinoza
Update new and edit "views"...
r91 color = "success"
Fiorella Quino
Task #487: Operation. Views: radar_play y radar_stop. Models: RunningExperiment. Attributes: status. Methods: get_status(), status_color()...
r84 elif self.status == 3:
color = "warning"
else:
color = "muted"
return color
Juan C. Espinoza
Update views and templates of main app...
r89 def get_absolute_url(self):
return reverse('url_experiment', args=[str(self.id)])
Juan C. Espinoza
Update several views and models in main app...
r85
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):
Juan C. Espinoza
- Update rc app...
r79
if self.experiment:
return u'[%s, %s]: %s' % (self.experiment.name,
self.device.name,
self.name)
else:
return u'%s' % self.device.name
Juan C. Espinoza
Update several views and models in main app...
r85 def clone(self, **kwargs):
Juan C. Espinoza
- Update rc app...
r79
Juan C. Espinoza
Update several views and models in main app...
r85 self.pk = None
self.id = None
for attr, value in kwargs.items():
setattr(self, attr, value)
self.save()
return self
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)
Juan C. Espinoza
- Update rc app...
r79 content = json.dumps(self.parms_to_dict(), indent=2)
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)])