@@ -0,0 +1,1 | |||||
|
1 | {% extends "dev_conf_edit.html" %} No newline at end of file |
@@ -0,0 +1,1 | |||||
|
1 | {% extends "dev_conf_edit.html" %} No newline at end of file |
@@ -1,10 +1,9 | |||||
1 | from django.contrib import admin |
|
1 | from django.contrib import admin | |
2 |
from .models import Device, DeviceType, Experiment, Campaign, Location |
|
2 | from .models import Device, DeviceType, Experiment, Campaign, Location | |
3 |
|
3 | |||
4 | # Register your models here. |
|
4 | # Register your models here. | |
5 | admin.site.register(Campaign) |
|
5 | admin.site.register(Campaign) | |
6 | admin.site.register(Experiment) |
|
6 | admin.site.register(Experiment) | |
7 | admin.site.register(Device) |
|
7 | admin.site.register(Device) | |
8 | admin.site.register(DeviceType) |
|
8 | admin.site.register(DeviceType) | |
9 |
admin.site.register(Location) |
|
9 | admin.site.register(Location) | |
No newline at end of file |
|
||||
10 | admin.site.register(Radar) No newline at end of file |
|
@@ -1,74 +1,80 | |||||
1 | from django import forms |
|
1 | from django import forms | |
2 | from django.utils.safestring import mark_safe |
|
2 | from django.utils.safestring import mark_safe | |
3 | from datetime import datetime |
|
|||
4 |
|
||||
5 | from apps.main.widgets import Filtering_ComboBox_Widget, Datepicker, HTMLrender,Filtering_ComboBox_Widget2 |
|
|||
6 |
|
||||
7 |
|
3 | |||
8 | from .models import DeviceType, Device, Experiment, Campaign, Configuration, Location |
|
4 | from .models import DeviceType, Device, Experiment, Campaign, Configuration, Location | |
9 |
|
5 | |||
10 | def add_empty_choice(choices, pos=0, label='-----'): |
|
6 | def add_empty_choice(choices, pos=0, label='-----'): | |
11 | if len(choices)>0: |
|
7 | if len(choices)>0: | |
12 | choices = list(choices) |
|
8 | choices = list(choices) | |
13 | choices.insert(0, (0, label)) |
|
9 | choices.insert(0, (0, label)) | |
14 | return choices |
|
10 | return choices | |
15 | else: |
|
11 | else: | |
16 | return [(0, label)] |
|
12 | return [(0, label)] | |
17 |
|
13 | |||
18 | class DatepickerWidget(forms.widgets.TextInput): |
|
14 | class DatepickerWidget(forms.widgets.TextInput): | |
19 | def render(self, name, value, attrs=None): |
|
15 | def render(self, name, value, attrs=None): | |
20 | input_html = super(DatepickerWidget, self).render(name, value, attrs) |
|
16 | input_html = super(DatepickerWidget, self).render(name, value, attrs) | |
21 | html = '<div class="input-group date">'+input_html+'<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span></div>' |
|
17 | html = '<div class="input-group date">'+input_html+'<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span></div>' | |
22 | return mark_safe(html) |
|
18 | return mark_safe(html) | |
23 |
|
19 | |||
24 | class TimepickerWidget(forms.widgets.TextInput): |
|
20 | class TimepickerWidget(forms.widgets.TextInput): | |
25 | def render(self, name, value, attrs=None): |
|
21 | def render(self, name, value, attrs=None): | |
26 | input_html = super(TimepickerWidget, self).render(name, value, attrs) |
|
22 | input_html = super(TimepickerWidget, self).render(name, value, attrs) | |
27 | html = '<div class="input-group time">'+input_html+'<span class="input-group-addon"><i class="glyphicon glyphicon-time"></i></span></div>' |
|
23 | html = '<div class="input-group time">'+input_html+'<span class="input-group-addon"><i class="glyphicon glyphicon-time"></i></span></div>' | |
28 | return mark_safe(html) |
|
24 | return mark_safe(html) | |
29 |
|
25 | |||
30 | class CampaignForm(forms.ModelForm): |
|
26 | class CampaignForm(forms.ModelForm): | |
31 | def __init__(self, *args, **kwargs): |
|
27 | def __init__(self, *args, **kwargs): | |
32 | super(CampaignForm, self).__init__(*args, **kwargs) |
|
28 | super(CampaignForm, self).__init__(*args, **kwargs) | |
33 | self.fields['start_date'].widget = DatepickerWidget(self.fields['start_date'].widget.attrs) |
|
29 | self.fields['start_date'].widget = DatepickerWidget(self.fields['start_date'].widget.attrs) | |
34 | self.fields['end_date'].widget = DatepickerWidget(self.fields['end_date'].widget.attrs) |
|
30 | self.fields['end_date'].widget = DatepickerWidget(self.fields['end_date'].widget.attrs) | |
35 |
|
31 | |||
36 | class Meta: |
|
32 | class Meta: | |
37 | model = Campaign |
|
33 | model = Campaign | |
38 | exclude = [''] |
|
34 | exclude = [''] | |
39 |
|
35 | |||
40 | class ExperimentForm(forms.ModelForm): |
|
36 | class ExperimentForm(forms.ModelForm): | |
|
37 | ||||
41 | def __init__(self, *args, **kwargs): |
|
38 | def __init__(self, *args, **kwargs): | |
42 | super(ExperimentForm, self).__init__(*args, **kwargs) |
|
39 | super(ExperimentForm, self).__init__(*args, **kwargs) | |
43 | self.fields['start_time'].widget = TimepickerWidget(self.fields['start_time'].widget.attrs) |
|
40 | self.fields['start_time'].widget = TimepickerWidget(self.fields['start_time'].widget.attrs) | |
44 | self.fields['end_time'].widget = TimepickerWidget(self.fields['end_time'].widget.attrs) |
|
41 | self.fields['end_time'].widget = TimepickerWidget(self.fields['end_time'].widget.attrs) | |
45 |
|
42 | |||
46 | self.fields['campaign'].widget.attrs['readonly'] = True |
|
43 | self.fields['campaign'].widget.attrs['readonly'] = True | |
47 |
|
44 | |||
48 | class Meta: |
|
45 | class Meta: | |
49 | model = Experiment |
|
46 | model = Experiment | |
50 | exclude = [''] |
|
47 | exclude = [''] | |
51 |
|
48 | |||
52 | class LocationForm(forms.ModelForm): |
|
49 | class LocationForm(forms.ModelForm): | |
53 | class Meta: |
|
50 | class Meta: | |
54 | model = Location |
|
51 | model = Location | |
55 | exclude = [''] |
|
52 | exclude = [''] | |
56 |
|
53 | |||
57 | class DeviceForm(forms.ModelForm): |
|
54 | class DeviceForm(forms.ModelForm): | |
58 | class Meta: |
|
55 | class Meta: | |
59 | model = Device |
|
56 | model = Device | |
60 | exclude = ['status'] |
|
57 | exclude = ['status'] | |
61 |
|
58 | |||
62 | class ConfigurationForm(forms.ModelForm): |
|
59 | class ConfigurationForm(forms.ModelForm): | |
63 | class Meta: |
|
60 | class Meta: | |
64 | model = Configuration |
|
61 | model = Configuration | |
65 | exclude = ['type', 'created_date', 'programmed_date', 'parameters'] |
|
62 | exclude = ['type', 'created_date', 'programmed_date', 'parameters'] | |
66 |
|
63 | |||
67 | class DeviceTypeForm(forms.Form): |
|
64 | class DeviceTypeForm(forms.Form): | |
68 | device_type = forms.ChoiceField(choices=add_empty_choice(DeviceType.objects.all().order_by('name').values_list('id', 'name'))) |
|
65 | device_type = forms.ChoiceField(choices=add_empty_choice(DeviceType.objects.all().order_by('name').values_list('id', 'name'))) | |
69 |
|
66 | |||
|
67 | ||||
|
68 | class UploadFileForm(forms.Form): | |||
|
69 | ||||
|
70 | file = forms.FileField() | |||
|
71 | ||||
|
72 | class DownloadFileForm(forms.Form): | |||
|
73 | ||||
|
74 | format = forms.ComboField() | |||
|
75 | ||||
70 | class OperationForm(forms.Form): |
|
76 | class OperationForm(forms.Form): | |
71 | today = datetime.today() |
|
77 | # today = datetime.today() | |
72 | # -----Campaigns from this month------ |
|
78 | # -----Campaigns from this month------ | |
73 |
campaign = forms.ChoiceField(choices=Campaign.objects. |
|
79 | campaign = forms.ChoiceField(choices=Campaign.objects.all().order_by('-start_date').values_list('id', 'name')[:5], label="Campaign") | |
74 | No newline at end of file |
|
80 |
@@ -1,180 +1,273 | |||||
1 | from django.db import models |
|
1 | from django.db import models | |
2 | from polymorphic import PolymorphicModel |
|
2 | from polymorphic import PolymorphicModel | |
3 |
|
3 | |||
4 | from django.core.urlresolvers import reverse |
|
4 | from django.core.urlresolvers import reverse | |
5 |
|
5 | |||
6 | CONF_STATES = ( |
|
6 | CONF_STATES = ( | |
7 | (0, 'Disconnected'), |
|
7 | (0, 'Disconnected'), | |
8 | (1, 'Connected'), |
|
8 | (1, 'Connected'), | |
9 | (1, 'Running'), |
|
9 | (1, 'Running'), | |
10 | ) |
|
10 | ) | |
11 |
|
11 | |||
12 | CONF_TYPES = ( |
|
12 | CONF_TYPES = ( | |
13 | (0, 'Active'), |
|
13 | (0, 'Active'), | |
14 | (1, 'Historical'), |
|
14 | (1, 'Historical'), | |
15 | ) |
|
15 | ) | |
16 |
|
16 | |||
17 | DEV_STATES = ( |
|
17 | DEV_STATES = ( | |
18 | (0, 'No connected'), |
|
18 | (0, 'No connected'), | |
19 | (1, 'Connected'), |
|
19 | (1, 'Connected'), | |
20 | (2, 'Configured'), |
|
20 | (2, 'Configured'), | |
21 | (3, 'Running'), |
|
21 | (3, 'Running'), | |
22 | ) |
|
22 | ) | |
23 |
|
23 | |||
24 | DEV_TYPES = ( |
|
24 | DEV_TYPES = ( | |
25 | ('', 'Select a device type'), |
|
25 | ('', 'Select a device type'), | |
26 | ('rc', 'Radar Controller'), |
|
26 | ('rc', 'Radar Controller'), | |
27 | ('dds', 'Direct Digital Synthesizer'), |
|
27 | ('dds', 'Direct Digital Synthesizer'), | |
28 | ('jars', 'Jicamarca Radar Acquisition System'), |
|
28 | ('jars', 'Jicamarca Radar Acquisition System'), | |
29 | ('usrp', 'Universal Software Radio Peripheral'), |
|
29 | ('usrp', 'Universal Software Radio Peripheral'), | |
30 | ('cgs', 'Clock Generator System'), |
|
30 | ('cgs', 'Clock Generator System'), | |
31 | ('abs', 'Automatic Beam Switching'), |
|
31 | ('abs', 'Automatic Beam Switching'), | |
32 | ) |
|
32 | ) | |
33 |
|
33 | |||
34 | DEV_PORTS = { |
|
34 | DEV_PORTS = { | |
35 | 'rc' : 2000, |
|
35 | 'rc' : 2000, | |
36 | 'dds' : 2000, |
|
36 | 'dds' : 2000, | |
37 | 'jars' : 2000, |
|
37 | 'jars' : 2000, | |
38 | 'usrp' : 2000, |
|
38 | 'usrp' : 2000, | |
39 | 'cgs' : 8080, |
|
39 | 'cgs' : 8080, | |
40 | 'abs' : 8080 |
|
40 | 'abs' : 8080 | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | RADAR_STATES = ( |
|
43 | RADAR_STATES = ( | |
44 | (0, 'No connected'), |
|
44 | (0, 'No connected'), | |
45 | (1, 'Connnected'), |
|
45 | (1, 'Connnected'), | |
46 | (2, 'Configured'), |
|
46 | (2, 'Configured'), | |
47 | (3, 'Running'), |
|
47 | (3, 'Running'), | |
48 | (4, 'Scheduled'), |
|
48 | (4, 'Scheduled'), | |
49 | ) |
|
49 | ) | |
50 | # Create your models here. |
|
50 | # Create your models here. | |
51 |
|
51 | |||
|
52 | ||||
|
53 | class Location(models.Model): | |||
|
54 | ||||
|
55 | name = models.CharField(max_length = 30) | |||
|
56 | description = models.TextField(blank=True, null=True) | |||
|
57 | ||||
|
58 | class Meta: | |||
|
59 | db_table = 'db_location' | |||
|
60 | ||||
|
61 | def __unicode__(self): | |||
|
62 | return u'%s' % self.name | |||
|
63 | ||||
52 | class DeviceType(models.Model): |
|
64 | class DeviceType(models.Model): | |
53 |
|
65 | |||
54 | name = models.CharField(max_length = 10, choices = DEV_TYPES, default = 'rc') |
|
66 | name = models.CharField(max_length = 10, choices = DEV_TYPES, default = 'rc') | |
55 | description = models.TextField(blank=True, null=True) |
|
67 | description = models.TextField(blank=True, null=True) | |
56 |
|
68 | |||
57 | class Meta: |
|
69 | class Meta: | |
58 | db_table = 'db_device_types' |
|
70 | db_table = 'db_device_types' | |
59 |
|
71 | |||
60 | def __unicode__(self): |
|
72 | def __unicode__(self): | |
61 | return u'%s' % self.get_name_display() |
|
73 | return u'%s' % self.get_name_display() | |
62 |
|
74 | |||
63 | class Device(models.Model): |
|
75 | class Device(models.Model): | |
64 |
|
76 | |||
65 | device_type = models.ForeignKey(DeviceType) |
|
77 | device_type = models.ForeignKey(DeviceType, on_delete=models.CASCADE) | |
66 |
|
|
78 | location = models.ForeignKey(Location, on_delete=models.CASCADE) | |
67 |
|
79 | |||
68 | name = models.CharField(max_length=40, default='') |
|
80 | name = models.CharField(max_length=40, default='') | |
69 | ip_address = models.GenericIPAddressField(protocol='IPv4', default='0.0.0.0') |
|
81 | ip_address = models.GenericIPAddressField(protocol='IPv4', default='0.0.0.0') | |
70 | port_address = models.PositiveSmallIntegerField(default=2000) |
|
82 | port_address = models.PositiveSmallIntegerField(default=2000) | |
71 | description = models.TextField(blank=True, null=True) |
|
83 | description = models.TextField(blank=True, null=True) | |
72 | status = models.PositiveSmallIntegerField(default=0, choices=DEV_STATES) |
|
84 | status = models.PositiveSmallIntegerField(default=0, choices=DEV_STATES) | |
73 |
|
85 | |||
74 | class Meta: |
|
86 | class Meta: | |
75 | db_table = 'db_devices' |
|
87 | db_table = 'db_devices' | |
76 |
|
88 | |||
77 | def __unicode__(self): |
|
89 | def __unicode__(self): | |
78 | return u'%s | %s' % (self.name, self.ip_address) |
|
90 | return u'%s | %s' % (self.name, self.ip_address) | |
79 |
|
91 | |||
80 | def get_status(self): |
|
92 | def get_status(self): | |
81 |
|
93 | |||
82 | return self.status |
|
94 | return self.status | |
83 |
|
95 | |||
84 |
|
96 | |||
85 | class Campaign(models.Model): |
|
97 | class Campaign(models.Model): | |
86 |
|
98 | |||
87 | template = models.BooleanField(default=False) |
|
99 | template = models.BooleanField(default=False) | |
88 |
|
100 | |||
89 | name = models.CharField(max_length=40, unique=True) |
|
101 | name = models.CharField(max_length=40, unique=True) | |
90 | start_date = models.DateTimeField(blank=True, null=True) |
|
102 | start_date = models.DateTimeField(blank=True, null=True) | |
91 | end_date = models.DateTimeField(blank=True, null=True) |
|
103 | end_date = models.DateTimeField(blank=True, null=True) | |
92 | tags = models.CharField(max_length=40) |
|
104 | tags = models.CharField(max_length=40) | |
93 | description = models.TextField(blank=True, null=True) |
|
105 | description = models.TextField(blank=True, null=True) | |
94 |
|
106 | |||
95 | class Meta: |
|
107 | class Meta: | |
96 | db_table = 'db_campaigns' |
|
108 | db_table = 'db_campaigns' | |
97 |
|
109 | |||
98 | def __unicode__(self): |
|
110 | def __unicode__(self): | |
99 | return u'%s' % (self.name) |
|
111 | return u'%s' % (self.name) | |
100 |
|
112 | |||
101 | class Radar(models.Model): |
|
113 | # class Radar(models.Model): | |
102 |
|
114 | # | ||
103 | name = models.CharField(max_length = 30) |
|
115 | # # name = models.CharField(max_length = 30) | |
104 | campaign = models.ForeignKey(Campaign) |
|
116 | # experiment = models.ForeignKey('Experiment', on_delete=models.CASCADE) | |
105 | status = models.PositiveSmallIntegerField(default=0, choices=RADAR_STATES) |
|
117 | # location = models.OneToOneField('Location', on_delete=models.CASCADE) | |
106 |
|
118 | # status = models.PositiveSmallIntegerField(default=0, choices=RADAR_STATES) | ||
107 | class Meta: |
|
119 | # | |
108 | db_table = 'db_radar' |
|
120 | # class Meta: | |
109 |
|
121 | # db_table = 'db_radar' | ||
110 | def __unicode__(self): |
|
122 | # | |
111 | return u'%s' % self.name |
|
123 | # def __unicode__(self): | |
|
124 | # return u'%s' % self.location | |||
112 |
|
125 | |||
113 |
|
126 | |||
114 | class Experiment(models.Model): |
|
127 | class Experiment(models.Model): | |
115 |
|
128 | |||
116 | template = models.BooleanField(default=False) |
|
129 | template = models.BooleanField(default=False) | |
117 |
|
130 | |||
118 | radar = models.ForeignKey(Radar) |
|
131 | campaign = models.ForeignKey('Campaign', null=True, blank=True, on_delete=models.CASCADE) | |
|
132 | location = models.ForeignKey('Location', null=True, blank=True, on_delete=models.CASCADE) | |||
|
133 | ||||
119 | name = models.CharField(max_length=40, default='') |
|
134 | name = models.CharField(max_length=40, default='') | |
120 | start_time = models.TimeField(default='00:00:00') |
|
135 | start_time = models.TimeField(default='00:00:00') | |
121 | end_time = models.TimeField(default='23:59:59') |
|
136 | end_time = models.TimeField(default='23:59:59') | |
122 |
|
137 | |||
123 | class Meta: |
|
138 | class Meta: | |
124 | db_table = 'db_experiments' |
|
139 | db_table = 'db_experiments' | |
125 |
|
140 | |||
126 | def __unicode__(self): |
|
141 | def __unicode__(self): | |
127 |
return u' |
|
142 | return u'%s' % (self.name) | |
128 |
|
143 | |||
129 | class Configuration(PolymorphicModel): |
|
144 | class Configuration(PolymorphicModel): | |
130 |
|
145 | |||
131 | template = models.BooleanField(default=False) |
|
146 | template = models.BooleanField(default=False) | |
132 |
|
147 | |||
133 | name = models.CharField(verbose_name="Configuration Name", max_length=40, default='') |
|
148 | name = models.CharField(verbose_name="Configuration Name", max_length=40, default='') | |
134 |
|
149 | |||
135 | experiment = models.ForeignKey(Experiment) |
|
150 | experiment = models.ForeignKey('Experiment', null=True, blank=True, on_delete=models.CASCADE) | |
136 | device = models.ForeignKey(Device) |
|
151 | device = models.ForeignKey(Device, on_delete=models.CASCADE) | |
137 |
|
152 | |||
138 | type = models.PositiveSmallIntegerField(default=0, choices=CONF_TYPES) |
|
153 | type = models.PositiveSmallIntegerField(default=0, choices=CONF_TYPES) | |
139 |
|
154 | |||
140 | created_date = models.DateTimeField(auto_now_add=True) |
|
155 | created_date = models.DateTimeField(auto_now_add=True) | |
141 | programmed_date = models.DateTimeField(auto_now=True) |
|
156 | programmed_date = models.DateTimeField(auto_now=True) | |
142 |
|
157 | |||
143 | parameters = models.TextField(default='{}') |
|
158 | parameters = models.TextField(default='{}') | |
144 |
|
159 | |||
|
160 | message = "" | |||
|
161 | ||||
145 | class Meta: |
|
162 | class Meta: | |
146 | db_table = 'db_configurations' |
|
163 | db_table = 'db_configurations' | |
147 |
|
164 | |||
148 | def __unicode__(self): |
|
165 | def __unicode__(self): | |
149 |
return u'[%s - %s]: %s' % (self.experiment. |
|
166 | return u'[%s - %s]: %s' % (self.experiment.name, | |
150 | self.experiment.name, |
|
167 | self.experiment.name, | |
151 | self.device.name) |
|
168 | self.device.name) | |
152 |
|
|
169 | ||
|
170 | def parms_to_dict(self): | |||
|
171 | ||||
|
172 | parameters = {} | |||
|
173 | ||||
|
174 | for key in self.__dict__.keys(): | |||
|
175 | parameters[key] = getattr(self, key) | |||
|
176 | ||||
|
177 | return parameters | |||
|
178 | ||||
|
179 | def dict_to_parms(self, parameters): | |||
|
180 | ||||
|
181 | if type(parameters) != type({}): | |||
|
182 | return | |||
|
183 | ||||
|
184 | for key in parameters.keys(): | |||
|
185 | setattr(self, key, parameters[key]) | |||
|
186 | ||||
|
187 | def export_to_file(self, format="json"): | |||
|
188 | ||||
|
189 | import json | |||
|
190 | ||||
|
191 | content_type = 'application/json' | |||
|
192 | filename = '%s.json' %self.name | |||
|
193 | content = json.dumps(self.params_to_dict()) | |||
|
194 | ||||
|
195 | if format == 'text': | |||
|
196 | content_type = 'text/plain' | |||
|
197 | filename = '%s.%s' %(self.name, self.device.device_type.name) | |||
|
198 | content = self.params_to_text() | |||
|
199 | ||||
|
200 | if format == 'binary': | |||
|
201 | content_type = 'application/octet-stream' | |||
|
202 | filename = '%s.bin' %self.name | |||
|
203 | content = self.params_to_binary() | |||
|
204 | ||||
|
205 | fields = {'content_type':content_type, | |||
|
206 | 'filename':filename, | |||
|
207 | 'content':content | |||
|
208 | } | |||
|
209 | ||||
|
210 | return fields | |||
|
211 | ||||
|
212 | def import_from_file(self, filename): | |||
|
213 | ||||
|
214 | raise NotImplementedError, "This method should be implemented in each Configuration model" | |||
|
215 | ||||
|
216 | return {} | |||
|
217 | ||||
|
218 | def status_device(self): | |||
|
219 | ||||
|
220 | raise NotImplementedError, "This method should be implemented in each Configuration model" | |||
|
221 | ||||
|
222 | return None | |||
|
223 | ||||
|
224 | def stop_device(self): | |||
|
225 | ||||
|
226 | raise NotImplementedError, "This method should be implemented in each Configuration model" | |||
|
227 | ||||
|
228 | return None | |||
|
229 | ||||
|
230 | def start_device(self): | |||
|
231 | ||||
|
232 | raise NotImplementedError, "This method should be implemented in each Configuration model" | |||
|
233 | ||||
|
234 | return None | |||
|
235 | ||||
|
236 | def write_device(self, parms): | |||
|
237 | ||||
|
238 | raise NotImplementedError, "This method should be implemented in each Configuration model" | |||
|
239 | ||||
|
240 | return None | |||
|
241 | ||||
|
242 | def read_device(self): | |||
|
243 | ||||
|
244 | raise NotImplementedError, "This method should be implemented in each Configuration model" | |||
|
245 | ||||
|
246 | return None | |||
|
247 | ||||
153 | def get_absolute_url(self): |
|
248 | def get_absolute_url(self): | |
154 | return reverse('url_%s_conf' % self.device.device_type.name, args=[str(self.id)]) |
|
249 | return reverse('url_%s_conf' % self.device.device_type.name, args=[str(self.id)]) | |
155 |
|
250 | |||
156 | def get_absolute_url_edit(self): |
|
251 | def get_absolute_url_edit(self): | |
157 | return reverse('url_edit_%s_conf' % self.device.device_type.name, args=[str(self.id)]) |
|
252 | return reverse('url_edit_%s_conf' % self.device.device_type.name, args=[str(self.id)]) | |
158 |
|
253 | |||
159 | def get_absolute_url_import(self): |
|
254 | def get_absolute_url_import(self): | |
160 |
return reverse('url_import_ |
|
255 | return reverse('url_import_dev_conf', args=[str(self.id)]) | |
161 |
|
256 | |||
162 | def get_absolute_url_export(self): |
|
257 | def get_absolute_url_export(self): | |
163 |
return reverse('url_export_ |
|
258 | return reverse('url_export_dev_conf', args=[str(self.id)]) | |
164 |
|
259 | |||
165 | def get_absolute_url_write(self): |
|
260 | def get_absolute_url_write(self): | |
166 |
return reverse('url_write_ |
|
261 | return reverse('url_write_dev_conf', args=[str(self.id)]) | |
167 |
|
262 | |||
168 | def get_absolute_url_read(self): |
|
263 | def get_absolute_url_read(self): | |
169 |
return reverse('url_read_ |
|
264 | return reverse('url_read_dev_conf', args=[str(self.id)]) | |
170 |
|
265 | |||
171 | class Location(models.Model): |
|
266 | def get_absolute_url_start(self): | |
|
267 | return reverse('url_start_dev_conf', args=[str(self.id)]) | |||
172 |
|
268 | |||
173 | name = models.CharField(max_length = 30) |
|
269 | def get_absolute_url_stop(self): | |
174 | description = models.TextField(blank=True, null=True) |
|
270 | return reverse('url_stop_dev_conf', args=[str(self.id)]) | |
175 |
|
271 | |||
176 | class Meta: |
|
272 | def get_absolute_url_status(self): | |
177 | db_table = 'db_location' |
|
273 | return reverse('url_status_dev_conf', args=[str(self.id)]) No newline at end of file | |
178 |
|
||||
179 | def __unicode__(self): |
|
|||
180 | return u'%s' % self.name No newline at end of file |
|
@@ -1,64 +1,72 | |||||
1 | {% extends "base.html" %} |
|
1 | {% extends "base.html" %} | |
2 | {% load bootstrap3 %} |
|
2 | {% load bootstrap3 %} | |
3 | {% load static %} |
|
3 | {% load static %} | |
4 | {% load main_tags %} |
|
4 | {% load main_tags %} | |
5 |
|
5 | |||
6 | {% block conf-active %}active{% endblock %} |
|
6 | {% block conf-active %}active{% endblock %} | |
7 |
|
7 | |||
8 | {% block content-title %}{{title}}{% endblock %} |
|
8 | {% block content-title %}{{title}}{% endblock %} | |
9 | {% block content-suptitle %}{{suptitle}}{% endblock %} |
|
9 | {% block content-suptitle %}{{suptitle}}{% endblock %} | |
10 |
|
10 | |||
11 | {% block content %} |
|
11 | {% block content %} | |
12 |
|
12 | |||
|
13 | <span class=" dropdown pull-right"> | |||
|
14 | <a href="#" class="dropdown-toggle" data-toggle="dropdown">Options<span class="caret"></span></a> | |||
|
15 | <ul class="dropdown-menu" role="menu"> | |||
|
16 | <li><a href="{{ dev_conf.get_absolute_url_edit }}">Edit</a></li> | |||
|
17 | <li><a href="{{ dev_conf.get_absolute_url_import }}">Import </a></li> | |||
|
18 | <li><a href="{{ dev_conf.get_absolute_url_export }}">Export </a></li> | |||
|
19 | <li><a>----------------</a></li> | |||
|
20 | <li><a href="{{ dev_conf.get_absolute_url_write }}">Write</a></li> | |||
|
21 | <li><a href="{{ dev_conf.get_absolute_url_read }}">Read</a></li> | |||
|
22 | <li><a href="{{ dev_conf.get_absolute_url_start}}">Start</a></li> | |||
|
23 | <li><a href="{{ dev_conf.get_absolute_url_stop }}">Stop</a></li> | |||
|
24 | <li><a href="{{ dev_conf.get_absolute_url_status }}">Update Status</a></li> | |||
|
25 | </ul> | |||
|
26 | </span> | |||
|
27 | ||||
13 | <table class="table table-bordered"> |
|
28 | <table class="table table-bordered"> | |
14 | <tr> |
|
29 | <tr> | |
15 | <th>Status</th> |
|
30 | <th>Status</th> | |
16 |
<td>{%if |
|
31 | <td>{%if status %} <span class="glyphicon glyphicon-ok-circle text-success" aria-hidden="true"></span> {{status}} {% else %} <span class="glyphicon glyphicon-remove-circle text-danger" aria-hidden="true"></span> Disconnected {% endif %}</td> | |
17 | </tr> |
|
32 | </tr> | |
18 |
|
33 | |||
19 | {% for key in dev_conf_keys %} |
|
34 | {% for key in dev_conf_keys %} | |
20 | <tr> |
|
35 | <tr> | |
21 | <th>{% get_verbose_field_name dev_conf key %}</th> |
|
36 | <th>{% get_verbose_field_name dev_conf key %}</th> | |
22 | <td>{{dev_conf|attr:key}}</td> |
|
37 | <td>{{dev_conf|attr:key}}</td> | |
23 | </tr> |
|
38 | </tr> | |
24 | {% endfor %} |
|
39 | {% endfor %} | |
25 | </table> |
|
40 | </table> | |
26 |
|
41 | |||
27 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_export">Export</button> |
|
|||
28 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_import">Import</button> |
|
|||
29 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_edit">Edit</button> |
|
|||
30 |
|
||||
31 | <button class="btn btn-primary pull-left" style="margin-left: 10px" id="bt_read">Read</button> |
|
|||
32 | <button class="btn btn-primary pull-left" style="margin-left: 10px" id="bt_write">Write</button> |
|
|||
33 |
|
||||
34 | {% endblock %} |
|
42 | {% endblock %} | |
35 |
|
43 | |||
36 | {% block sidebar%} |
|
44 | {% block sidebar%} | |
37 | {% include "sidebar_devices.html" %} |
|
45 | {% include "sidebar_devices.html" %} | |
38 | {% endblock %} |
|
46 | {% endblock %} | |
39 |
|
47 | |||
40 | {% block extra-js%} |
|
48 | {% block extra-js%} | |
41 | <script type="text/javascript"> |
|
49 | <script type="text/javascript"> | |
42 |
|
50 | |||
43 | $("#bt_edit").click(function() { |
|
51 | $("#bt_edit").click(function() { | |
44 | document.location = "{{ dev_conf.get_absolute_url_edit }}"; |
|
52 | document.location = "{{ dev_conf.get_absolute_url_edit }}"; | |
45 | }); |
|
53 | }); | |
46 |
|
54 | |||
47 | $("#bt_read").click(function() { |
|
55 | $("#bt_read").click(function() { | |
48 | document.location = "{{ dev_conf.get_absolute_url_read }}"; |
|
56 | document.location = "{{ dev_conf.get_absolute_url_read }}"; | |
49 | }); |
|
57 | }); | |
50 |
|
58 | |||
51 | $("#bt_write").click(function() { |
|
59 | $("#bt_write").click(function() { | |
52 | document.location = "{{ dev_conf.get_absolute_url_write }}"; |
|
60 | document.location = "{{ dev_conf.get_absolute_url_write }}"; | |
53 | }); |
|
61 | }); | |
54 |
|
62 | |||
55 | $("#bt_import").click(function() { |
|
63 | $("#bt_import").click(function() { | |
56 | document.location = "{{ dev_conf.get_absolute_url_import }}"; |
|
64 | document.location = "{{ dev_conf.get_absolute_url_import }}"; | |
57 | }); |
|
65 | }); | |
58 |
|
66 | |||
59 | $("#bt_export").click(function() { |
|
67 | $("#bt_export").click(function() { | |
60 | document.location = "{{ dev_conf.get_absolute_url_export }}"; |
|
68 | document.location = "{{ dev_conf.get_absolute_url_export }}"; | |
61 | }); |
|
69 | }); | |
62 |
|
70 | |||
63 | </script> |
|
71 | </script> | |
64 | {% endblock %} No newline at end of file |
|
72 | {% endblock %} |
@@ -1,104 +1,103 | |||||
1 | {% extends "base.html" %} |
|
1 | {% extends "base.html" %} | |
2 | {% load bootstrap3 %} |
|
2 | {% load bootstrap3 %} | |
3 | {% load static %} |
|
3 | {% load static %} | |
4 | {% load main_tags %} |
|
4 | {% load main_tags %} | |
5 | {% block extra-head %} |
|
5 | {% block extra-head %} | |
6 | <link href="{% static 'css/bootstrap-datetimepicker.min.css' %}" media="screen" rel="stylesheet"> |
|
6 | <link href="{% static 'css/bootstrap-datetimepicker.min.css' %}" media="screen" rel="stylesheet"> | |
7 | {% endblock %} |
|
7 | {% endblock %} | |
8 |
|
8 | |||
9 | {% block camp-active %}active{% endblock %} |
|
9 | {% block camp-active %}active{% endblock %} | |
10 |
|
10 | |||
11 | {% block content-title %}{{title}}{% endblock %} |
|
11 | {% block content-title %}{{title}}{% endblock %} | |
12 | {% block content-suptitle %}{{suptitle}}{% endblock %} |
|
12 | {% block content-suptitle %}{{suptitle}}{% endblock %} | |
13 |
|
13 | |||
14 | {% block content %} |
|
14 | {% block content %} | |
15 |
|
15 | |||
16 | <form class="form" method="post" action=""> |
|
16 | <form class="form" method="post" action=""> | |
17 | {% csrf_token %} |
|
17 | {% csrf_token %} | |
18 | {% bootstrap_form form layout='horizontal' size='medium' %} |
|
18 | {% bootstrap_form form layout='horizontal' size='medium' %} | |
19 | <div style="clear: both;"></div> |
|
19 | <div style="clear: both;"></div> | |
20 | <br> |
|
20 | <br> | |
21 | <button type="submit" class="btn btn-primary pull-right">{{button}}</button> |
|
21 | <button type="submit" class="btn btn-primary pull-right">{{button}}</button> | |
22 | <br> |
|
22 | <br> | |
23 | <br> |
|
23 | <br> | |
24 | </form> |
|
24 | </form> | |
25 | <br> |
|
25 | <br> | |
|
26 | <br> | |||
26 |
|
27 | |||
27 | <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true" > |
|
28 | <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true" > | |
28 |
|
29 | |||
29 |
{% for |
|
30 | {% for location in locations %} | |
30 |
|
31 | |||
31 | <div class="panel panel-default"> |
|
32 | <div class="panel panel-default"> | |
32 | <div class="panel-heading" role="tab" id="headingTwo"> |
|
33 | <div class="panel-heading" role="tab" id="headingTwo"> | |
33 | <h4 class="panel-title"> |
|
34 | <h4 class="panel-title"> | |
34 |
|
35 | <a class="collapsed" role="button" data-toggle="collapse" href="#collapseTwo-{{ location.id }}" aria-expanded="false" aria-controls="collapseTwo"> | ||
35 | <a class="collapsed" role="button" data-toggle="collapse" href="#collapseTwo-{{ radar.id }}" aria-expanded="false" aria-controls="collapseTwo"> |
|
36 | {{location.name}}: Experiment List | |
36 | {{radar.name}}: Experiment List |
|
|||
37 | <span> |
|
37 | <span> | |
38 | </span> |
|
38 | </span> | |
39 | </a> |
|
39 | </a> | |
40 | <button type="button" class="btn btn-primary pull-right btn-xs" aria-label="Left Align" style="margin-left: 10px"> |
|
40 | <button type="button" class="btn btn-primary pull-right btn-xs" aria-label="Left Align" style="margin-left: 10px"> | |
41 | <span class="glyphicon glyphicon-play" aria-hidden="true"></span> |
|
41 | <span class="glyphicon glyphicon-play" aria-hidden="true"></span> | |
42 | </button> |
|
42 | </button> | |
43 | <button type="button" class="btn btn-primary pull-right btn-xs" aria-label="Left Align" style="margin-left: 10px"> |
|
43 | <button type="button" class="btn btn-primary pull-right btn-xs" aria-label="Left Align" style="margin-left: 10px"> | |
44 | <span class="glyphicon glyphicon-stop" aria-hidden="true"></span> |
|
44 | <span class="glyphicon glyphicon-stop" aria-hidden="true"></span> | |
45 | </button> |
|
45 | </button> | |
46 |
|
46 | |||
47 | </h4> |
|
47 | </h4> | |
48 | </div> |
|
48 | </div> | |
49 |
|
49 | |||
50 |
<div id="collapseTwo-{{ |
|
50 | <div id="collapseTwo-{{ location.name }}" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo"> | |
51 | <div class="panel-body"> |
|
51 | <div class="panel-body"> | |
52 | <table class="table table-hover"> |
|
52 | <table class="table table-hover"> | |
53 | <tr> |
|
53 | <tr> | |
54 |
|
54 | <th>#</th> | ||
55 | {% for header in experiment_keys %} |
|
55 | {% for header in experiment_keys %} | |
56 | <th>{{ header|title }}</th> |
|
56 | <th>{{ header|title }}</th> | |
57 | {% endfor%} |
|
57 | {% endfor%} | |
58 | </tr> |
|
58 | </tr> | |
59 | {% for item in experiments %} |
|
|||
60 | {% for exs in item %} |
|
|||
61 | <tr class="clickable-row" data-href="{% url 'url_experiment' exs.id %}" > |
|
|||
62 |
|
|
59 | ||
|
60 | {% for item in experiments %} | |||
|
61 | {% if location.name in item.location.name %} | |||
|
62 | <tr class="clickable-row" data-href="{% url 'url_experiment' item.id %}" > | |||
|
63 | <td>{{ forloop.counter }}</td> | |||
63 | {% for key in experiment_keys %} |
|
64 | {% for key in experiment_keys %} | |
64 | {% if radar.name in exs.radar.name %} |
|
65 | <td>{{ item|value:key }}</td> | |
65 | <td>{{ exs|attr:key }}</td> |
|
|||
66 | {% endif %} |
|
|||
67 | {% endfor %} |
|
|||
68 | {% endfor %} |
|
66 | {% endfor %} | |
69 | </tr> |
|
67 | </tr> | |
|
68 | {% endif %} | |||
70 | {% endfor %} |
|
69 | {% endfor %} | |
71 | </table> |
|
70 | </table> | |
72 | </div> |
|
71 | </div> | |
73 | </div> |
|
72 | </div> | |
74 | </div> |
|
73 | </div> | |
75 | {% endfor %} |
|
74 | {% endfor %} | |
76 | </div> |
|
75 | </div> | |
77 |
|
76 | |||
78 | {% endblock %} |
|
77 | {% endblock %} | |
79 |
|
78 | |||
80 |
|
79 | |||
81 |
|
80 | |||
82 | {% block extra-js%} |
|
81 | {% block extra-js%} | |
83 | <script type="text/javascript"> |
|
82 | <script type="text/javascript"> | |
84 |
|
83 | |||
85 | //$("#bt_add").click(function() { |
|
84 | //$("#bt_add").click(function() { | |
86 | //alert("sometext"); |
|
85 | //alert("sometext"); | |
87 | // document.location = "{% url 'url_operation' campaign.id %}"; |
|
86 | // document.location = "{% url 'url_operation' campaign.id %}"; | |
88 | //}); |
|
87 | //}); | |
89 |
|
88 | |||
90 | $(".clickable-row").click(function() { |
|
89 | $(".clickable-row").click(function() { | |
91 | document.location = $(this).data("href"); |
|
90 | document.location = $(this).data("href"); | |
92 | }); |
|
91 | }); | |
93 |
|
92 | |||
94 | $(document).ready(function() { |
|
93 | $(document).ready(function() { | |
95 | $("#id_campaign").change(function() { |
|
94 | $("#id_campaign").change(function() { | |
96 | var id_camp = document.getElementById("id_campaign").value; |
|
95 | var id_camp = document.getElementById("id_campaign").value; | |
97 | //alert(id_camp); |
|
96 | //alert(id_camp); | |
98 | document.location = "{% url 'url_operation'%}"+String(id_camp); |
|
97 | document.location = "{% url 'url_operation'%}"+String(id_camp); | |
99 | }); |
|
98 | }); | |
100 | }); |
|
99 | }); | |
101 |
|
100 | |||
102 |
|
101 | |||
103 | </script> |
|
102 | </script> | |
104 | {% endblock %} No newline at end of file |
|
103 | {% endblock %} |
@@ -1,37 +1,45 | |||||
1 | from django.conf.urls import url |
|
1 | from django.conf.urls import url | |
2 |
|
2 | |||
3 | urlpatterns = ( |
|
3 | urlpatterns = ( | |
4 | url(r'^location/new/$', 'apps.main.views.location_new', name='url_add_location'), |
|
4 | url(r'^location/new/$', 'apps.main.views.location_new', name='url_add_location'), | |
5 | url(r'^location/$', 'apps.main.views.locations', name='url_locations'), |
|
5 | url(r'^location/$', 'apps.main.views.locations', name='url_locations'), | |
6 | url(r'^location/(?P<id_loc>-?\d+)/$', 'apps.main.views.location', name='url_location'), |
|
6 | url(r'^location/(?P<id_loc>-?\d+)/$', 'apps.main.views.location', name='url_location'), | |
7 | url(r'^location/(?P<id_loc>-?\d+)/edit/$', 'apps.main.views.location_edit', name='url_edit_location'), |
|
7 | url(r'^location/(?P<id_loc>-?\d+)/edit/$', 'apps.main.views.location_edit', name='url_edit_location'), | |
8 | url(r'^location/(?P<id_loc>-?\d+)/delete/$', 'apps.main.views.location_delete', name='url_delete_location'), |
|
8 | url(r'^location/(?P<id_loc>-?\d+)/delete/$', 'apps.main.views.location_delete', name='url_delete_location'), | |
9 |
|
9 | |||
10 | url(r'^device/new/$', 'apps.main.views.device_new', name='url_add_device'), |
|
10 | url(r'^device/new/$', 'apps.main.views.device_new', name='url_add_device'), | |
11 | url(r'^device/$', 'apps.main.views.devices', name='url_devices'), |
|
11 | url(r'^device/$', 'apps.main.views.devices', name='url_devices'), | |
12 | url(r'^device/(?P<id_dev>-?\d+)/$', 'apps.main.views.device', name='url_device'), |
|
12 | url(r'^device/(?P<id_dev>-?\d+)/$', 'apps.main.views.device', name='url_device'), | |
13 | url(r'^device/(?P<id_dev>-?\d+)/edit/$', 'apps.main.views.device_edit', name='url_edit_device'), |
|
13 | url(r'^device/(?P<id_dev>-?\d+)/edit/$', 'apps.main.views.device_edit', name='url_edit_device'), | |
14 | url(r'^device/(?P<id_dev>-?\d+)/delete/$', 'apps.main.views.device_delete', name='url_delete_device'), |
|
14 | url(r'^device/(?P<id_dev>-?\d+)/delete/$', 'apps.main.views.device_delete', name='url_delete_device'), | |
15 |
|
15 | |||
16 | url(r'^campaign/new/$', 'apps.main.views.campaign_new', name='url_add_campaign'), |
|
16 | url(r'^campaign/new/$', 'apps.main.views.campaign_new', name='url_add_campaign'), | |
17 | url(r'^campaign/$', 'apps.main.views.campaigns', name='url_campaigns'), |
|
17 | url(r'^campaign/$', 'apps.main.views.campaigns', name='url_campaigns'), | |
18 | url(r'^campaign/(?P<id_camp>-?\d+)/$', 'apps.main.views.campaign', name='url_campaign'), |
|
18 | url(r'^campaign/(?P<id_camp>-?\d+)/$', 'apps.main.views.campaign', name='url_campaign'), | |
19 | url(r'^campaign/(?P<id_camp>-?\d+)/edit/$', 'apps.main.views.campaign_edit', name='url_edit_campaign'), |
|
19 | url(r'^campaign/(?P<id_camp>-?\d+)/edit/$', 'apps.main.views.campaign_edit', name='url_edit_campaign'), | |
20 | url(r'^campaign/(?P<id_camp>-?\d+)/delete/$', 'apps.main.views.campaign_delete', name='url_delete_campaign'), |
|
20 | url(r'^campaign/(?P<id_camp>-?\d+)/delete/$', 'apps.main.views.campaign_delete', name='url_delete_campaign'), | |
21 |
|
21 | |||
22 | url(r'^campaign/(?P<id_camp>-?\d+)/new_experiment/$', 'apps.main.views.experiment_new', name='url_add_experiment'), |
|
22 | url(r'^campaign/(?P<id_camp>-?\d+)/new_experiment/$', 'apps.main.views.experiment_new', name='url_add_experiment'), | |
23 | url(r'^experiment/$', 'apps.main.views.experiments', name='url_experiments'), |
|
23 | url(r'^experiment/$', 'apps.main.views.experiments', name='url_experiments'), | |
24 | url(r'^experiment/(?P<id_exp>-?\d+)/$', 'apps.main.views.experiment', name='url_experiment'), |
|
24 | url(r'^experiment/(?P<id_exp>-?\d+)/$', 'apps.main.views.experiment', name='url_experiment'), | |
25 | url(r'^experiment/(?P<id_exp>-?\d+)/edit/$', 'apps.main.views.experiment_edit', name='url_edit_experiment'), |
|
25 | url(r'^experiment/(?P<id_exp>-?\d+)/edit/$', 'apps.main.views.experiment_edit', name='url_edit_experiment'), | |
26 | url(r'^experiment/(?P<id_exp>-?\d+)/delete/$', 'apps.main.views.experiment_delete', name='url_delete_experiment'), |
|
26 | url(r'^experiment/(?P<id_exp>-?\d+)/delete/$', 'apps.main.views.experiment_delete', name='url_delete_experiment'), | |
27 |
|
27 | |||
28 | url(r'^experiment/(?P<id_exp>-?\d+)/new_dev_conf/$', 'apps.main.views.dev_conf_new', name='url_add_dev_conf'), |
|
28 | url(r'^experiment/(?P<id_exp>-?\d+)/new_dev_conf/$', 'apps.main.views.dev_conf_new', name='url_add_dev_conf'), | |
29 | url(r'^dev_conf/$', 'apps.main.views.dev_confs', name='url_dev_confs'), |
|
29 | url(r'^dev_conf/$', 'apps.main.views.dev_confs', name='url_dev_confs'), | |
30 | url(r'^dev_conf/(?P<id_conf>-?\d+)/$', 'apps.main.views.dev_conf', name='url_dev_conf'), |
|
30 | url(r'^dev_conf/(?P<id_conf>-?\d+)/$', 'apps.main.views.dev_conf', name='url_dev_conf'), | |
31 | url(r'^dev_conf/(?P<id_conf>-?\d+)/edit/$', 'apps.main.views.dev_conf_edit', name='url_edit_dev_conf'), |
|
31 | url(r'^dev_conf/(?P<id_conf>-?\d+)/edit/$', 'apps.main.views.dev_conf_edit', name='url_edit_dev_conf'), | |
32 | url(r'^dev_conf/(?P<id_conf>-?\d+)/delete/$', 'apps.main.views.dev_conf_delete', name='url_delete_dev_conf'), |
|
32 | url(r'^dev_conf/(?P<id_conf>-?\d+)/delete/$', 'apps.main.views.dev_conf_delete', name='url_delete_dev_conf'), | |
33 |
|
33 | |||
|
34 | url(r'^dev_conf/(?P<id_conf>-?\d+)/write/$', 'apps.main.views.dev_conf_write', name='url_write_dev_conf'), | |||
|
35 | url(r'^dev_conf/(?P<id_conf>-?\d+)/read/$', 'apps.main.views.dev_conf_read', name='url_read_dev_conf'), | |||
|
36 | url(r'^dev_conf/(?P<id_conf>-?\d+)/import/$', 'apps.main.views.dev_conf_import', name='url_import_dev_conf'), | |||
|
37 | url(r'^dev_conf/(?P<id_conf>-?\d+)/export/$', 'apps.main.views.dev_conf_export', name='url_export_dev_conf'), | |||
|
38 | url(r'^dev_conf/(?P<id_conf>-?\d+)/start/$', 'apps.main.views.dev_conf_start', name='url_start_dev_conf'), | |||
|
39 | url(r'^dev_conf/(?P<id_conf>-?\d+)/stop/$', 'apps.main.views.dev_conf_stop', name='url_stop_dev_conf'), | |||
|
40 | url(r'^dev_conf/(?P<id_conf>-?\d+)/status/$', 'apps.main.views.dev_conf_status', name='url_status_dev_conf'), | |||
|
41 | ||||
34 | url(r'^operation/$', 'apps.main.views.operation', name='url_operation'), |
|
42 | url(r'^operation/$', 'apps.main.views.operation', name='url_operation'), | |
35 | url(r'^operation/(?P<id_camp>-?\d+)/$', 'apps.main.views.operation', name='url_operation'), |
|
43 | url(r'^operation/(?P<id_camp>-?\d+)/$', 'apps.main.views.operation', name='url_operation'), | |
36 |
|
44 | |||
37 | ) |
|
45 | ) |
@@ -1,631 +1,798 | |||||
1 | from django.shortcuts import render, redirect, get_object_or_404, HttpResponse |
|
1 | from django.shortcuts import render, redirect, get_object_or_404, HttpResponse | |
2 | from django.contrib import messages |
|
2 | from django.contrib import messages | |
3 |
|
3 | |||
4 | from datetime import datetime |
|
4 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm, UploadFileForm, DownloadFileForm, OperationForm | |
5 |
|
||||
6 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm, OperationForm |
|
|||
7 | from apps.cgs.forms import CGSConfigurationForm |
|
5 | from apps.cgs.forms import CGSConfigurationForm | |
8 | from apps.jars.forms import JARSConfigurationForm |
|
6 | from apps.jars.forms import JARSConfigurationForm | |
9 | from apps.usrp.forms import USRPConfigurationForm |
|
7 | from apps.usrp.forms import USRPConfigurationForm | |
10 | from apps.abs.forms import ABSConfigurationForm |
|
8 | from apps.abs.forms import ABSConfigurationForm | |
11 | from apps.rc.forms import RCConfigurationForm |
|
9 | from apps.rc.forms import RCConfigurationForm | |
12 | from apps.dds.forms import DDSConfigurationForm |
|
10 | from apps.dds.forms import DDSConfigurationForm | |
13 |
|
11 | |||
14 |
from .models import Campaign, Experiment, Device, Configuration, Location |
|
12 | from .models import Campaign, Experiment, Device, Configuration, Location | |
15 | from apps.cgs.models import CGSConfiguration |
|
13 | from apps.cgs.models import CGSConfiguration | |
16 | from apps.jars.models import JARSConfiguration |
|
14 | from apps.jars.models import JARSConfiguration | |
17 | from apps.usrp.models import USRPConfiguration |
|
15 | from apps.usrp.models import USRPConfiguration | |
18 | from apps.abs.models import ABSConfiguration |
|
16 | from apps.abs.models import ABSConfiguration | |
19 | from apps.rc.models import RCConfiguration |
|
17 | from apps.rc.models import RCConfiguration | |
20 | from apps.dds.models import DDSConfiguration |
|
18 | from apps.dds.models import DDSConfiguration | |
21 |
|
19 | |||
22 | # Create your views here. |
|
20 | # Create your views here. | |
23 |
|
21 | |||
24 | CONF_FORMS = { |
|
22 | CONF_FORMS = { | |
25 | 'rc': RCConfigurationForm, |
|
23 | 'rc': RCConfigurationForm, | |
26 | 'dds': DDSConfigurationForm, |
|
24 | 'dds': DDSConfigurationForm, | |
27 | 'jars': JARSConfigurationForm, |
|
25 | 'jars': JARSConfigurationForm, | |
28 | 'cgs': CGSConfigurationForm, |
|
26 | 'cgs': CGSConfigurationForm, | |
29 | 'abs': ABSConfigurationForm, |
|
27 | 'abs': ABSConfigurationForm, | |
30 | 'usrp': USRPConfigurationForm, |
|
28 | 'usrp': USRPConfigurationForm, | |
31 | } |
|
29 | } | |
32 |
|
30 | |||
33 | CONF_MODELS = { |
|
31 | CONF_MODELS = { | |
34 | 'rc': RCConfiguration, |
|
32 | 'rc': RCConfiguration, | |
35 | 'dds': DDSConfiguration, |
|
33 | 'dds': DDSConfiguration, | |
36 | 'jars': JARSConfiguration, |
|
34 | 'jars': JARSConfiguration, | |
37 | 'cgs': CGSConfiguration, |
|
35 | 'cgs': CGSConfiguration, | |
38 | 'abs': ABSConfiguration, |
|
36 | 'abs': ABSConfiguration, | |
39 | 'usrp': USRPConfiguration, |
|
37 | 'usrp': USRPConfiguration, | |
40 | } |
|
38 | } | |
41 |
|
39 | |||
42 | def index(request): |
|
40 | def index(request): | |
43 | kwargs = {} |
|
41 | kwargs = {} | |
44 |
|
42 | |||
45 | return render(request, 'index.html', kwargs) |
|
43 | return render(request, 'index.html', kwargs) | |
46 |
|
44 | |||
47 | def locations(request): |
|
45 | def locations(request): | |
48 |
|
46 | |||
49 | locations = Location.objects.all().order_by('name') |
|
47 | locations = Location.objects.all().order_by('name') | |
50 |
|
48 | |||
51 | keys = ['id', 'name', 'description'] |
|
49 | keys = ['id', 'name', 'description'] | |
52 |
|
50 | |||
53 | kwargs = {} |
|
51 | kwargs = {} | |
54 | kwargs['location_keys'] = keys[1:] |
|
52 | kwargs['location_keys'] = keys[1:] | |
55 | kwargs['locations'] = locations |
|
53 | kwargs['locations'] = locations | |
56 | kwargs['title'] = 'Location' |
|
54 | kwargs['title'] = 'Location' | |
57 | kwargs['suptitle'] = 'List' |
|
55 | kwargs['suptitle'] = 'List' | |
58 | kwargs['button'] = 'New Location' |
|
56 | kwargs['button'] = 'New Location' | |
59 |
|
57 | |||
60 | return render(request, 'locations.html', kwargs) |
|
58 | return render(request, 'locations.html', kwargs) | |
61 |
|
59 | |||
62 | def location(request, id_loc): |
|
60 | def location(request, id_loc): | |
63 |
|
61 | |||
64 | location = get_object_or_404(Location, pk=id_loc) |
|
62 | location = get_object_or_404(Location, pk=id_loc) | |
65 |
|
63 | |||
66 | kwargs = {} |
|
64 | kwargs = {} | |
67 | kwargs['location'] = location |
|
65 | kwargs['location'] = location | |
68 | kwargs['location_keys'] = ['name', 'description'] |
|
66 | kwargs['location_keys'] = ['name', 'description'] | |
69 |
|
67 | |||
70 | kwargs['title'] = 'Location' |
|
68 | kwargs['title'] = 'Location' | |
71 | kwargs['suptitle'] = 'Details' |
|
69 | kwargs['suptitle'] = 'Details' | |
72 |
|
70 | |||
73 | return render(request, 'location.html', kwargs) |
|
71 | return render(request, 'location.html', kwargs) | |
74 |
|
72 | |||
75 | def location_new(request): |
|
73 | def location_new(request): | |
76 |
|
74 | |||
77 | if request.method == 'GET': |
|
75 | if request.method == 'GET': | |
78 | form = LocationForm() |
|
76 | form = LocationForm() | |
79 |
|
77 | |||
80 | if request.method == 'POST': |
|
78 | if request.method == 'POST': | |
81 | form = LocationForm(request.POST) |
|
79 | form = LocationForm(request.POST) | |
82 |
|
80 | |||
83 | if form.is_valid(): |
|
81 | if form.is_valid(): | |
84 | form.save() |
|
82 | form.save() | |
85 | return redirect('url_locations') |
|
83 | return redirect('url_locations') | |
86 |
|
84 | |||
87 | kwargs = {} |
|
85 | kwargs = {} | |
88 | kwargs['form'] = form |
|
86 | kwargs['form'] = form | |
89 | kwargs['title'] = 'Location' |
|
87 | kwargs['title'] = 'Location' | |
90 | kwargs['suptitle'] = 'New' |
|
88 | kwargs['suptitle'] = 'New' | |
91 | kwargs['button'] = 'Create' |
|
89 | kwargs['button'] = 'Create' | |
92 |
|
90 | |||
93 | return render(request, 'location_edit.html', kwargs) |
|
91 | return render(request, 'location_edit.html', kwargs) | |
94 |
|
92 | |||
95 | def location_edit(request, id_loc): |
|
93 | def location_edit(request, id_loc): | |
96 |
|
94 | |||
97 | location = get_object_or_404(Location, pk=id_loc) |
|
95 | location = get_object_or_404(Location, pk=id_loc) | |
98 |
|
96 | |||
99 | if request.method=='GET': |
|
97 | if request.method=='GET': | |
100 | form = LocationForm(instance=location) |
|
98 | form = LocationForm(instance=location) | |
101 |
|
99 | |||
102 | if request.method=='POST': |
|
100 | if request.method=='POST': | |
103 | form = LocationForm(request.POST, instance=location) |
|
101 | form = LocationForm(request.POST, instance=location) | |
104 |
|
102 | |||
105 | if form.is_valid(): |
|
103 | if form.is_valid(): | |
106 | form.save() |
|
104 | form.save() | |
107 | return redirect('url_locations') |
|
105 | return redirect('url_locations') | |
108 |
|
106 | |||
109 | kwargs = {} |
|
107 | kwargs = {} | |
110 | kwargs['form'] = form |
|
108 | kwargs['form'] = form | |
111 | kwargs['title'] = 'Location' |
|
109 | kwargs['title'] = 'Location' | |
112 | kwargs['suptitle'] = 'Edit' |
|
110 | kwargs['suptitle'] = 'Edit' | |
113 | kwargs['button'] = 'Update' |
|
111 | kwargs['button'] = 'Update' | |
114 |
|
112 | |||
115 | return render(request, 'location_edit.html', kwargs) |
|
113 | return render(request, 'location_edit.html', kwargs) | |
116 |
|
114 | |||
117 | def location_delete(request, id_loc): |
|
115 | def location_delete(request, id_loc): | |
118 |
|
116 | |||
119 | location = get_object_or_404(Location, pk=id_loc) |
|
117 | location = get_object_or_404(Location, pk=id_loc) | |
120 |
|
118 | |||
121 | if request.method=='POST': |
|
119 | if request.method=='POST': | |
122 |
|
120 | |||
123 | if request.user.is_staff: |
|
121 | if request.user.is_staff: | |
124 | location.delete() |
|
122 | location.delete() | |
125 | return redirect('url_locations') |
|
123 | return redirect('url_locations') | |
126 |
|
124 | |||
127 | return HttpResponse("Not enough permission to delete this object") |
|
125 | return HttpResponse("Not enough permission to delete this object") | |
128 |
|
126 | |||
129 | kwargs = {'object':location, 'loc_active':'active', |
|
127 | kwargs = {'object':location, 'loc_active':'active', | |
130 | 'url_cancel':'url_location', 'id_item':id_loc} |
|
128 | 'url_cancel':'url_location', 'id_item':id_loc} | |
131 |
|
129 | |||
132 | return render(request, 'item_delete.html', kwargs) |
|
130 | return render(request, 'item_delete.html', kwargs) | |
133 |
|
131 | |||
134 | def devices(request): |
|
132 | def devices(request): | |
135 |
|
133 | |||
136 | devices = Device.objects.all().order_by('device_type__name') |
|
134 | devices = Device.objects.all().order_by('device_type__name') | |
137 |
|
135 | |||
138 | # keys = ['id', 'device_type__name', 'name', 'ip_address'] |
|
136 | # keys = ['id', 'device_type__name', 'name', 'ip_address'] | |
139 | keys = ['id', 'name', 'ip_address', 'port_address', 'device_type'] |
|
137 | keys = ['id', 'name', 'ip_address', 'port_address', 'device_type'] | |
140 |
|
138 | |||
141 | kwargs = {} |
|
139 | kwargs = {} | |
142 | kwargs['device_keys'] = keys[1:] |
|
140 | kwargs['device_keys'] = keys[1:] | |
143 | kwargs['devices'] = devices#.values(*keys) |
|
141 | kwargs['devices'] = devices#.values(*keys) | |
144 | kwargs['title'] = 'Device' |
|
142 | kwargs['title'] = 'Device' | |
145 | kwargs['suptitle'] = 'List' |
|
143 | kwargs['suptitle'] = 'List' | |
146 | kwargs['button'] = 'New Device' |
|
144 | kwargs['button'] = 'New Device' | |
147 |
|
145 | |||
148 | return render(request, 'devices.html', kwargs) |
|
146 | return render(request, 'devices.html', kwargs) | |
149 |
|
147 | |||
150 | def device(request, id_dev): |
|
148 | def device(request, id_dev): | |
151 |
|
149 | |||
152 | device = get_object_or_404(Device, pk=id_dev) |
|
150 | device = get_object_or_404(Device, pk=id_dev) | |
153 |
|
151 | |||
154 | kwargs = {} |
|
152 | kwargs = {} | |
155 | kwargs['device'] = device |
|
153 | kwargs['device'] = device | |
156 | kwargs['device_keys'] = ['device_type', 'name', 'ip_address', 'port_address', 'description'] |
|
154 | kwargs['device_keys'] = ['device_type', 'name', 'ip_address', 'port_address', 'description'] | |
157 |
|
155 | |||
158 | kwargs['title'] = 'Device' |
|
156 | kwargs['title'] = 'Device' | |
159 | kwargs['suptitle'] = 'Details' |
|
157 | kwargs['suptitle'] = 'Details' | |
160 |
|
158 | |||
161 | return render(request, 'device.html', kwargs) |
|
159 | return render(request, 'device.html', kwargs) | |
162 |
|
160 | |||
163 | def device_new(request): |
|
161 | def device_new(request): | |
164 |
|
162 | |||
165 | if request.method == 'GET': |
|
163 | if request.method == 'GET': | |
166 | form = DeviceForm() |
|
164 | form = DeviceForm() | |
167 |
|
165 | |||
168 | if request.method == 'POST': |
|
166 | if request.method == 'POST': | |
169 | form = DeviceForm(request.POST) |
|
167 | form = DeviceForm(request.POST) | |
170 |
|
168 | |||
171 | if form.is_valid(): |
|
169 | if form.is_valid(): | |
172 | form.save() |
|
170 | form.save() | |
173 | return redirect('url_devices') |
|
171 | return redirect('url_devices') | |
174 |
|
172 | |||
175 | kwargs = {} |
|
173 | kwargs = {} | |
176 | kwargs['form'] = form |
|
174 | kwargs['form'] = form | |
177 | kwargs['title'] = 'Device' |
|
175 | kwargs['title'] = 'Device' | |
178 | kwargs['suptitle'] = 'New' |
|
176 | kwargs['suptitle'] = 'New' | |
179 | kwargs['button'] = 'Create' |
|
177 | kwargs['button'] = 'Create' | |
180 |
|
178 | |||
181 | return render(request, 'device_edit.html', kwargs) |
|
179 | return render(request, 'device_edit.html', kwargs) | |
182 |
|
180 | |||
183 | def device_edit(request, id_dev): |
|
181 | def device_edit(request, id_dev): | |
184 |
|
182 | |||
185 | device = get_object_or_404(Device, pk=id_dev) |
|
183 | device = get_object_or_404(Device, pk=id_dev) | |
186 |
|
184 | |||
187 | if request.method=='GET': |
|
185 | if request.method=='GET': | |
188 | form = DeviceForm(instance=device) |
|
186 | form = DeviceForm(instance=device) | |
189 |
|
187 | |||
190 | if request.method=='POST': |
|
188 | if request.method=='POST': | |
191 | form = DeviceForm(request.POST, instance=device) |
|
189 | form = DeviceForm(request.POST, instance=device) | |
192 |
|
190 | |||
193 | if form.is_valid(): |
|
191 | if form.is_valid(): | |
194 | form.save() |
|
192 | form.save() | |
195 | return redirect('url_devices') |
|
193 | return redirect('url_devices') | |
196 |
|
194 | |||
197 | kwargs = {} |
|
195 | kwargs = {} | |
198 | kwargs['form'] = form |
|
196 | kwargs['form'] = form | |
199 | kwargs['title'] = 'Device' |
|
197 | kwargs['title'] = 'Device' | |
200 | kwargs['suptitle'] = 'Edit' |
|
198 | kwargs['suptitle'] = 'Edit' | |
201 | kwargs['button'] = 'Update' |
|
199 | kwargs['button'] = 'Update' | |
202 |
|
200 | |||
203 | return render(request, 'device_edit.html', kwargs) |
|
201 | return render(request, 'device_edit.html', kwargs) | |
204 |
|
202 | |||
205 | def device_delete(request, id_dev): |
|
203 | def device_delete(request, id_dev): | |
206 |
|
204 | |||
207 | device = get_object_or_404(Device, pk=id_dev) |
|
205 | device = get_object_or_404(Device, pk=id_dev) | |
208 |
|
206 | |||
209 | if request.method=='POST': |
|
207 | if request.method=='POST': | |
210 |
|
208 | |||
211 | if request.user.is_staff: |
|
209 | if request.user.is_staff: | |
212 | device.delete() |
|
210 | device.delete() | |
213 | return redirect('url_devices') |
|
211 | return redirect('url_devices') | |
214 |
|
212 | |||
215 | return HttpResponse("Not enough permission to delete this object") |
|
213 | return HttpResponse("Not enough permission to delete this object") | |
216 |
|
214 | |||
217 | kwargs = {'object':device, 'dev_active':'active', |
|
215 | kwargs = {'object':device, 'dev_active':'active', | |
218 | 'url_cancel':'url_device', 'id_item':id_dev} |
|
216 | 'url_cancel':'url_device', 'id_item':id_dev} | |
219 |
|
217 | |||
220 | return render(request, 'item_delete.html', kwargs) |
|
218 | return render(request, 'item_delete.html', kwargs) | |
221 |
|
219 | |||
222 | def campaigns(request): |
|
220 | def campaigns(request): | |
223 |
|
221 | |||
224 | campaigns = Campaign.objects.all().order_by('start_date') |
|
222 | campaigns = Campaign.objects.all().order_by('start_date') | |
225 |
|
223 | |||
226 | keys = ['id', 'name', 'start_date', 'end_date'] |
|
224 | keys = ['id', 'name', 'start_date', 'end_date'] | |
227 |
|
225 | |||
228 | kwargs = {} |
|
226 | kwargs = {} | |
229 | kwargs['campaign_keys'] = keys[1:] |
|
227 | kwargs['campaign_keys'] = keys[1:] | |
230 | kwargs['campaigns'] = campaigns#.values(*keys) |
|
228 | kwargs['campaigns'] = campaigns#.values(*keys) | |
231 | kwargs['title'] = 'Campaign' |
|
229 | kwargs['title'] = 'Campaign' | |
232 | kwargs['suptitle'] = 'List' |
|
230 | kwargs['suptitle'] = 'List' | |
233 | kwargs['button'] = 'New Campaign' |
|
231 | kwargs['button'] = 'New Campaign' | |
234 |
|
232 | |||
235 | return render(request, 'campaigns.html', kwargs) |
|
233 | return render(request, 'campaigns.html', kwargs) | |
236 |
|
234 | |||
237 | def campaign(request, id_camp): |
|
235 | def campaign(request, id_camp): | |
238 |
|
236 | |||
239 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
237 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
240 |
|
|
238 | experiments = Experiment.objects.filter(campaign=campaign) | |
|
239 | ||||
241 | form = CampaignForm(instance=campaign) |
|
240 | form = CampaignForm(instance=campaign) | |
242 |
|
241 | |||
243 | kwargs = {} |
|
242 | kwargs = {} | |
244 | kwargs['campaign'] = campaign |
|
243 | kwargs['campaign'] = campaign | |
245 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] |
|
244 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] | |
246 |
|
245 | |||
247 | keys = ['id', 'name', 'start_time', 'end_time'] |
|
246 | keys = ['id', 'name', 'start_time', 'end_time'] | |
248 |
|
247 | |||
249 | kwargs['experiment_keys'] = keys[1:] |
|
248 | kwargs['experiment_keys'] = keys[1:] | |
250 |
|
|
249 | kwargs['experiments'] = experiments.values(*keys) | |
251 |
|
250 | |||
252 | kwargs['title'] = 'Campaign' |
|
251 | kwargs['title'] = 'Campaign' | |
253 | kwargs['suptitle'] = 'Details' |
|
252 | kwargs['suptitle'] = 'Details' | |
254 |
|
253 | |||
255 | kwargs['form'] = form |
|
254 | kwargs['form'] = form | |
256 | kwargs['button'] = 'Add Experiment' |
|
255 | kwargs['button'] = 'Add Experiment' | |
257 |
|
256 | |||
258 | return render(request, 'campaign.html', kwargs) |
|
257 | return render(request, 'campaign.html', kwargs) | |
259 |
|
258 | |||
260 | def campaign_new(request): |
|
259 | def campaign_new(request): | |
261 |
|
260 | |||
262 | if request.method == 'GET': |
|
261 | if request.method == 'GET': | |
263 | form = CampaignForm() |
|
262 | form = CampaignForm() | |
264 |
|
263 | |||
265 | if request.method == 'POST': |
|
264 | if request.method == 'POST': | |
266 | form = CampaignForm(request.POST) |
|
265 | form = CampaignForm(request.POST) | |
267 |
|
266 | |||
268 | if form.is_valid(): |
|
267 | if form.is_valid(): | |
269 | campaign = form.save() |
|
268 | campaign = form.save() | |
270 | return redirect('url_campaign', id_camp=campaign.id) |
|
269 | return redirect('url_campaign', id_camp=campaign.id) | |
271 |
|
270 | |||
272 | kwargs = {} |
|
271 | kwargs = {} | |
273 | kwargs['form'] = form |
|
272 | kwargs['form'] = form | |
274 | kwargs['title'] = 'Campaign' |
|
273 | kwargs['title'] = 'Campaign' | |
275 | kwargs['suptitle'] = 'New' |
|
274 | kwargs['suptitle'] = 'New' | |
276 | kwargs['button'] = 'Create' |
|
275 | kwargs['button'] = 'Create' | |
277 |
|
276 | |||
278 | return render(request, 'campaign_edit.html', kwargs) |
|
277 | return render(request, 'campaign_edit.html', kwargs) | |
279 |
|
278 | |||
280 | def campaign_edit(request, id_camp): |
|
279 | def campaign_edit(request, id_camp): | |
281 |
|
280 | |||
282 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
281 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
283 |
|
282 | |||
284 | if request.method=='GET': |
|
283 | if request.method=='GET': | |
285 | form = CampaignForm(instance=campaign) |
|
284 | form = CampaignForm(instance=campaign) | |
286 |
|
285 | |||
287 | if request.method=='POST': |
|
286 | if request.method=='POST': | |
288 | form = CampaignForm(request.POST, instance=campaign) |
|
287 | form = CampaignForm(request.POST, instance=campaign) | |
289 |
|
288 | |||
290 | if form.is_valid(): |
|
289 | if form.is_valid(): | |
291 | form.save() |
|
290 | form.save() | |
292 | return redirect('url_campaign', id_camp=id_camp) |
|
291 | return redirect('url_campaign', id_camp=id_camp) | |
293 |
|
292 | |||
294 | kwargs = {} |
|
293 | kwargs = {} | |
295 | kwargs['form'] = form |
|
294 | kwargs['form'] = form | |
296 | kwargs['title'] = 'Campaign' |
|
295 | kwargs['title'] = 'Campaign' | |
297 | kwargs['suptitle'] = 'Edit' |
|
296 | kwargs['suptitle'] = 'Edit' | |
298 | kwargs['button'] = 'Update' |
|
297 | kwargs['button'] = 'Update' | |
299 |
|
298 | |||
300 | return render(request, 'campaign_edit.html', kwargs) |
|
299 | return render(request, 'campaign_edit.html', kwargs) | |
301 |
|
300 | |||
302 | def campaign_delete(request, id_camp): |
|
301 | def campaign_delete(request, id_camp): | |
303 |
|
302 | |||
304 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
303 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
305 |
|
304 | |||
306 | if request.method=='POST': |
|
305 | if request.method=='POST': | |
307 | if request.user.is_staff: |
|
306 | if request.user.is_staff: | |
308 | campaign.delete() |
|
307 | campaign.delete() | |
309 | return redirect('url_campaigns') |
|
308 | return redirect('url_campaigns') | |
310 |
|
309 | |||
311 | return HttpResponse("Not enough permission to delete this object") |
|
310 | return HttpResponse("Not enough permission to delete this object") | |
312 |
|
311 | |||
313 | kwargs = {'object':campaign, 'camp_active':'active', |
|
312 | kwargs = {'object':campaign, 'camp_active':'active', | |
314 | 'url_cancel':'url_campaign', 'id_item':id_camp} |
|
313 | 'url_cancel':'url_campaign', 'id_item':id_camp} | |
315 |
|
314 | |||
316 | return render(request, 'item_delete.html', kwargs) |
|
315 | return render(request, 'item_delete.html', kwargs) | |
317 |
|
316 | |||
318 | def experiments(request): |
|
317 | def experiments(request): | |
319 |
|
318 | |||
320 | experiment_list = Experiment.objects.all().order_by('campaign') |
|
319 | experiment_list = Experiment.objects.all().order_by('campaign') | |
321 |
|
320 | |||
322 | keys = ['id', 'name', 'start_time', 'end_time', 'campaign'] |
|
321 | keys = ['id', 'name', 'start_time', 'end_time', 'campaign'] | |
323 |
|
322 | |||
324 | kwargs = {} |
|
323 | kwargs = {} | |
325 |
|
324 | |||
326 | kwargs['experiment_keys'] = keys[1:] |
|
325 | kwargs['experiment_keys'] = keys[1:] | |
327 | kwargs['experiments'] = experiment_list#.values(*keys) |
|
326 | kwargs['experiments'] = experiment_list#.values(*keys) | |
328 |
|
327 | |||
329 | kwargs['title'] = 'Experiment' |
|
328 | kwargs['title'] = 'Experiment' | |
330 | kwargs['suptitle'] = 'List' |
|
329 | kwargs['suptitle'] = 'List' | |
331 | kwargs['button'] = 'New Experiment' |
|
330 | kwargs['button'] = 'New Experiment' | |
332 |
|
331 | |||
333 | return render(request, 'experiments.html', kwargs) |
|
332 | return render(request, 'experiments.html', kwargs) | |
334 |
|
333 | |||
335 | def experiment(request, id_exp): |
|
334 | def experiment(request, id_exp): | |
336 |
|
335 | |||
337 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
336 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
338 |
|
337 | |||
339 | experiments = Experiment.objects.filter(campaign=experiment.campaign) |
|
338 | experiments = Experiment.objects.filter(campaign=experiment.campaign) | |
340 | configurations = Configuration.objects.filter(experiment=experiment, type=0) |
|
339 | configurations = Configuration.objects.filter(experiment=experiment, type=0) | |
341 |
|
340 | |||
342 | kwargs = {} |
|
341 | kwargs = {} | |
343 |
|
342 | |||
344 | exp_keys = ['id', 'campaign', 'name', 'start_time', 'end_time'] |
|
343 | exp_keys = ['id', 'campaign', 'location', 'name', 'start_time', 'end_time'] | |
345 | conf_keys = ['id', 'device__name', 'device__device_type', 'device__ip_address', 'device__port_address'] |
|
344 | conf_keys = ['id', 'device__name', 'device__device_type', 'device__ip_address', 'device__port_address'] | |
346 |
|
345 | |||
347 | conf_labels = ['id', 'device__name', 'device_type', 'ip_address', 'port_address'] |
|
346 | conf_labels = ['id', 'device__name', 'device_type', 'ip_address', 'port_address'] | |
348 |
|
347 | |||
349 | kwargs['experiment_keys'] = exp_keys[1:] |
|
348 | kwargs['experiment_keys'] = exp_keys[1:] | |
350 | kwargs['experiment'] = experiment |
|
349 | kwargs['experiment'] = experiment | |
351 |
|
350 | |||
352 | kwargs['experiments'] = experiments.values(*exp_keys) |
|
351 | kwargs['experiments'] = experiments.values(*exp_keys) | |
353 |
|
352 | |||
354 | kwargs['configuration_labels'] = conf_labels[1:] |
|
353 | kwargs['configuration_labels'] = conf_labels[1:] | |
355 | kwargs['configuration_keys'] = conf_keys[1:] |
|
354 | kwargs['configuration_keys'] = conf_keys[1:] | |
356 | kwargs['configurations'] = configurations #.values(*conf_keys) |
|
355 | kwargs['configurations'] = configurations #.values(*conf_keys) | |
357 |
|
356 | |||
358 | kwargs['title'] = 'Experiment' |
|
357 | kwargs['title'] = 'Experiment' | |
359 | kwargs['suptitle'] = 'Details' |
|
358 | kwargs['suptitle'] = 'Details' | |
360 |
|
359 | |||
361 | kwargs['button'] = 'Add Configuration' |
|
360 | kwargs['button'] = 'Add Configuration' | |
362 |
|
361 | |||
363 | return render(request, 'experiment.html', kwargs) |
|
362 | return render(request, 'experiment.html', kwargs) | |
364 |
|
363 | |||
365 | def experiment_new(request, id_camp=0): |
|
364 | def experiment_new(request, id_camp=0): | |
366 |
|
365 | |||
367 | if request.method == 'GET': |
|
366 | if request.method == 'GET': | |
368 | form = ExperimentForm(initial={'campaign':id_camp}) |
|
367 | form = ExperimentForm(initial={'campaign':id_camp}) | |
369 |
|
368 | |||
370 | if request.method == 'POST': |
|
369 | if request.method == 'POST': | |
371 | form = ExperimentForm(request.POST, initial={'campaign':id_camp}) |
|
370 | form = ExperimentForm(request.POST, initial={'campaign':id_camp}) | |
372 |
|
371 | |||
373 | if form.is_valid(): |
|
372 | if form.is_valid(): | |
374 | experiment = form.save() |
|
373 | experiment = form.save() | |
375 | return redirect('url_experiment', id_exp=experiment.id) |
|
374 | return redirect('url_experiment', id_exp=experiment.id) | |
376 |
|
375 | |||
377 | kwargs = {} |
|
376 | kwargs = {} | |
378 | kwargs['form'] = form |
|
377 | kwargs['form'] = form | |
379 | kwargs['title'] = 'Experiment' |
|
378 | kwargs['title'] = 'Experiment' | |
380 | kwargs['suptitle'] = 'New' |
|
379 | kwargs['suptitle'] = 'New' | |
381 | kwargs['button'] = 'Create' |
|
380 | kwargs['button'] = 'Create' | |
382 |
|
381 | |||
383 | return render(request, 'experiment_edit.html', kwargs) |
|
382 | return render(request, 'experiment_edit.html', kwargs) | |
384 |
|
383 | |||
385 | def experiment_edit(request, id_exp): |
|
384 | def experiment_edit(request, id_exp): | |
386 |
|
385 | |||
387 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
386 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
388 |
|
387 | |||
389 | if request.method == 'GET': |
|
388 | if request.method == 'GET': | |
390 | form = ExperimentForm(instance=experiment) |
|
389 | form = ExperimentForm(instance=experiment) | |
391 |
|
390 | |||
392 | if request.method=='POST': |
|
391 | if request.method=='POST': | |
393 | form = ExperimentForm(request.POST, instance=experiment) |
|
392 | form = ExperimentForm(request.POST, instance=experiment) | |
394 |
|
393 | |||
395 | if form.is_valid(): |
|
394 | if form.is_valid(): | |
396 | experiment = form.save() |
|
395 | experiment = form.save() | |
397 | return redirect('url_experiment', id_exp=experiment.id) |
|
396 | return redirect('url_experiment', id_exp=experiment.id) | |
398 |
|
397 | |||
399 | kwargs = {} |
|
398 | kwargs = {} | |
400 | kwargs['form'] = form |
|
399 | kwargs['form'] = form | |
401 | kwargs['title'] = 'Experiment' |
|
400 | kwargs['title'] = 'Experiment' | |
402 | kwargs['suptitle'] = 'Edit' |
|
401 | kwargs['suptitle'] = 'Edit' | |
403 | kwargs['button'] = 'Update' |
|
402 | kwargs['button'] = 'Update' | |
404 |
|
403 | |||
405 | return render(request, 'experiment_edit.html', kwargs) |
|
404 | return render(request, 'experiment_edit.html', kwargs) | |
406 |
|
405 | |||
407 | def experiment_delete(request, id_exp): |
|
406 | def experiment_delete(request, id_exp): | |
408 |
|
407 | |||
409 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
408 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
410 |
|
409 | |||
411 | if request.method=='POST': |
|
410 | if request.method=='POST': | |
412 | if request.user.is_staff: |
|
411 | if request.user.is_staff: | |
413 | id_camp = experiment.campaign.id |
|
412 | id_camp = experiment.campaign.id | |
414 | experiment.delete() |
|
413 | experiment.delete() | |
415 | return redirect('url_campaign', id_camp=id_camp) |
|
414 | return redirect('url_campaign', id_camp=id_camp) | |
416 |
|
415 | |||
417 | return HttpResponse("Not enough permission to delete this object") |
|
416 | return HttpResponse("Not enough permission to delete this object") | |
418 |
|
417 | |||
419 | kwargs = {'object':experiment, 'exp_active':'active', |
|
418 | kwargs = {'object':experiment, 'exp_active':'active', | |
420 | 'url_cancel':'url_experiment', 'id_item':id_exp} |
|
419 | 'url_cancel':'url_experiment', 'id_item':id_exp} | |
421 |
|
420 | |||
422 | return render(request, 'item_delete.html', kwargs) |
|
421 | return render(request, 'item_delete.html', kwargs) | |
423 |
|
422 | |||
424 | def dev_confs(request): |
|
423 | def dev_confs(request): | |
425 |
|
424 | |||
426 | configurations = Configuration.objects.all().order_by('type', 'device__device_type', 'experiment') |
|
425 | configurations = Configuration.objects.all().order_by('type', 'device__device_type', 'experiment') | |
427 |
|
426 | |||
428 | # keys = ['id', 'device__device_type__name', 'device__name', 'experiment__campaign__name', 'experiment__name'] |
|
427 | # keys = ['id', 'device__device_type__name', 'device__name', 'experiment__campaign__name', 'experiment__name'] | |
429 |
|
428 | |||
430 | keys = ['id', 'device', 'experiment', 'type', 'programmed_date'] |
|
429 | keys = ['id', 'device', 'experiment', 'type', 'programmed_date'] | |
431 |
|
430 | |||
432 | kwargs = {} |
|
431 | kwargs = {} | |
433 |
|
432 | |||
434 | kwargs['configuration_keys'] = keys[1:] |
|
433 | kwargs['configuration_keys'] = keys[1:] | |
435 | kwargs['configurations'] = configurations#.values(*keys) |
|
434 | kwargs['configurations'] = configurations#.values(*keys) | |
436 |
|
435 | |||
437 | kwargs['title'] = 'Configuration' |
|
436 | kwargs['title'] = 'Configuration' | |
438 | kwargs['suptitle'] = 'List' |
|
437 | kwargs['suptitle'] = 'List' | |
439 | kwargs['button'] = 'New Configuration' |
|
438 | kwargs['button'] = 'New Configuration' | |
440 |
|
439 | |||
441 | return render(request, 'dev_confs.html', kwargs) |
|
440 | return render(request, 'dev_confs.html', kwargs) | |
442 |
|
441 | |||
443 | def dev_conf(request, id_conf): |
|
442 | def dev_conf(request, id_conf): | |
444 |
|
443 | |||
445 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
444 | conf = get_object_or_404(Configuration, pk=id_conf) | |
446 |
|
445 | |||
447 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
446 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
448 | dev_conf = DevConfModel.objects.get(pk=id_conf) |
|
447 | dev_conf = DevConfModel.objects.get(pk=id_conf) | |
449 |
|
448 | |||
450 | kwargs = {} |
|
449 | kwargs = {} | |
451 | kwargs['dev_conf'] = dev_conf |
|
450 | kwargs['dev_conf'] = dev_conf | |
452 | kwargs['dev_conf_keys'] = ['name', 'experiment', 'device'] |
|
451 | kwargs['dev_conf_keys'] = ['name', 'experiment', 'device'] | |
453 |
|
452 | |||
454 | kwargs['title'] = 'Configuration' |
|
453 | kwargs['title'] = 'Configuration' | |
455 | kwargs['suptitle'] = 'Details' |
|
454 | kwargs['suptitle'] = 'Details' | |
456 |
|
455 | |||
457 | kwargs['button'] = 'Edit Configuration' |
|
456 | kwargs['button'] = 'Edit Configuration' | |
458 |
|
457 | |||
459 | ###### SIDEBAR ###### |
|
458 | ###### SIDEBAR ###### | |
460 | kwargs.update(sidebar(conf)) |
|
459 | kwargs.update(sidebar(conf)) | |
461 |
|
460 | |||
462 | return render(request, 'dev_conf.html', kwargs) |
|
461 | return render(request, 'dev_conf.html', kwargs) | |
463 |
|
462 | |||
464 | def dev_conf_new(request, id_exp=0): |
|
463 | def dev_conf_new(request, id_exp=0): | |
465 |
|
464 | |||
466 | if request.method == 'GET': |
|
465 | if request.method == 'GET': | |
467 | form = ConfigurationForm(initial={'experiment':id_exp}) |
|
466 | form = ConfigurationForm(initial={'experiment':id_exp}) | |
468 |
|
467 | |||
469 | if request.method == 'POST': |
|
468 | if request.method == 'POST': | |
470 | experiment = Experiment.objects.get(pk=request.POST['experiment']) |
|
469 | experiment = Experiment.objects.get(pk=request.POST['experiment']) | |
471 | device = Device.objects.get(pk=request.POST['device']) |
|
470 | device = Device.objects.get(pk=request.POST['device']) | |
472 |
|
471 | |||
473 | DevConfForm = CONF_FORMS[device.device_type.name] |
|
472 | DevConfForm = CONF_FORMS[device.device_type.name] | |
474 |
|
473 | |||
475 | form = DevConfForm(request.POST, initial={'experiment':experiment.id}) |
|
474 | form = DevConfForm(request.POST, initial={'experiment':experiment.id}) | |
476 |
|
475 | |||
477 | if form.is_valid(): |
|
476 | if form.is_valid(): | |
478 | dev_conf = form.save() |
|
477 | dev_conf = form.save() | |
479 |
|
478 | |||
480 | return redirect('url_experiment', id_exp=experiment.id) |
|
479 | return redirect('url_experiment', id_exp=experiment.id) | |
481 |
|
480 | |||
482 | kwargs = {} |
|
481 | kwargs = {} | |
483 | kwargs['form'] = form |
|
482 | kwargs['form'] = form | |
484 | kwargs['title'] = 'Configuration' |
|
483 | kwargs['title'] = 'Configuration' | |
485 | kwargs['suptitle'] = 'New' |
|
484 | kwargs['suptitle'] = 'New' | |
486 | kwargs['button'] = 'Create' |
|
485 | kwargs['button'] = 'Create' | |
487 |
|
486 | |||
488 | return render(request, 'dev_conf_edit.html', kwargs) |
|
487 | return render(request, 'dev_conf_edit.html', kwargs) | |
489 |
|
488 | |||
490 | def dev_conf_edit(request, id_conf): |
|
489 | def dev_conf_edit(request, id_conf): | |
491 |
|
490 | |||
492 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
491 | conf = get_object_or_404(Configuration, pk=id_conf) | |
493 |
|
492 | |||
494 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
493 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
495 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
494 | DevConfForm = CONF_FORMS[conf.device.device_type.name] | |
496 |
|
495 | |||
497 | dev_conf = DevConfModel.objects.get(pk=id_conf) |
|
496 | dev_conf = DevConfModel.objects.get(pk=id_conf) | |
498 |
|
497 | |||
499 | if request.method=='GET': |
|
498 | if request.method=='GET': | |
500 | form = DevConfForm(instance=dev_conf) |
|
499 | form = DevConfForm(instance=dev_conf) | |
501 |
|
500 | |||
502 | if request.method=='POST': |
|
501 | if request.method=='POST': | |
503 | form = DevConfForm(request.POST, instance=dev_conf) |
|
502 | form = DevConfForm(request.POST, instance=dev_conf) | |
504 |
|
503 | |||
505 | if form.is_valid(): |
|
504 | if form.is_valid(): | |
506 | form.save() |
|
505 | form.save() | |
507 | return redirect('url_dev_conf', id_conf=id_conf) |
|
506 | return redirect('url_dev_conf', id_conf=id_conf) | |
508 |
|
507 | |||
509 | kwargs = {} |
|
508 | kwargs = {} | |
510 | kwargs['form'] = form |
|
509 | kwargs['form'] = form | |
511 | kwargs['title'] = 'Device Configuration' |
|
510 | kwargs['title'] = 'Device Configuration' | |
512 | kwargs['suptitle'] = 'Edit' |
|
511 | kwargs['suptitle'] = 'Edit' | |
513 | kwargs['button'] = 'Update' |
|
512 | kwargs['button'] = 'Update' | |
514 |
|
513 | |||
515 | ###### SIDEBAR ###### |
|
514 | ###### SIDEBAR ###### | |
516 | kwargs.update(sidebar(conf)) |
|
515 | kwargs.update(sidebar(conf)) | |
517 |
|
516 | |||
518 | return render(request, 'dev_conf_edit.html', kwargs) |
|
517 | return render(request, 'dev_conf_edit.html', kwargs) | |
519 |
|
518 | |||
520 |
def dev_conf_ |
|
519 | def dev_conf_start(request, id_conf): | |
|
520 | ||||
|
521 | conf = get_object_or_404(Configuration, pk=id_conf) | |||
|
522 | ||||
|
523 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |||
|
524 | ||||
|
525 | conf = DevConfModel.objects.get(pk=id_conf) | |||
|
526 | ||||
|
527 | if conf.start_device(): | |||
|
528 | messages.success(request, conf.message) | |||
|
529 | else: | |||
|
530 | messages.error(request, conf.message) | |||
|
531 | ||||
|
532 | return redirect(conf.get_absolute_url()) | |||
|
533 | ||||
|
534 | def dev_conf_stop(request, id_conf): | |||
|
535 | ||||
|
536 | conf = get_object_or_404(Configuration, pk=id_conf) | |||
|
537 | ||||
|
538 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |||
|
539 | ||||
|
540 | conf = DevConfModel.objects.get(pk=id_conf) | |||
|
541 | ||||
|
542 | if conf.stop_device(): | |||
|
543 | messages.success(request, conf.message) | |||
|
544 | else: | |||
|
545 | messages.error(request, conf.message) | |||
|
546 | ||||
|
547 | return redirect(conf.get_absolute_url()) | |||
|
548 | ||||
|
549 | def dev_conf_status(request, id_conf): | |||
521 |
|
550 | |||
522 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
551 | conf = get_object_or_404(Configuration, pk=id_conf) | |
523 |
|
552 | |||
524 | messages.error(request, "Read View not implemented yet") |
|
553 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
|
554 | ||||
|
555 | conf = DevConfModel.objects.get(pk=id_conf) | |||
|
556 | ||||
|
557 | if conf.status_device(): | |||
|
558 | messages.success(request, conf.message) | |||
|
559 | else: | |||
|
560 | messages.error(request, conf.message) | |||
|
561 | ||||
|
562 | return redirect(conf.get_absolute_url()) | |||
525 |
|
563 | |||
526 | return redirect('url_dev_conf', id_conf=conf.id) |
|
|||
527 |
|
564 | |||
528 | def dev_conf_write(request, id_conf): |
|
565 | def dev_conf_write(request, id_conf): | |
529 |
|
566 | |||
530 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
567 | conf = get_object_or_404(Configuration, pk=id_conf) | |
531 |
|
568 | |||
532 | messages.error(request, "Write View not implemented yet") |
|
569 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
|
570 | ||||
|
571 | conf = DevConfModel.objects.get(pk=id_conf) | |||
|
572 | ||||
|
573 | answer = conf.write_device() | |||
|
574 | ||||
|
575 | if answer: | |||
|
576 | messages.success(request, conf.message) | |||
|
577 | ||||
|
578 | conf.pk = None | |||
|
579 | conf.id = None | |||
|
580 | conf.type = 1 | |||
|
581 | conf.template = 0 | |||
|
582 | conf.save() | |||
|
583 | ||||
|
584 | else: | |||
|
585 | messages.error(request, conf.message) | |||
|
586 | ||||
|
587 | return redirect(conf.get_absolute_url()) | |||
|
588 | ||||
|
589 | def dev_conf_read(request, id_conf): | |||
|
590 | ||||
|
591 | conf = get_object_or_404(Configuration, pk=id_conf) | |||
|
592 | ||||
|
593 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |||
|
594 | DevConfForm = CONF_FORMS[conf.device.device_type.name] | |||
|
595 | ||||
|
596 | conf = DevConfModel.objects.get(pk=id_conf) | |||
533 |
|
597 | |||
534 | return redirect('url_dev_conf', id_conf=conf.id) |
|
598 | if request.method=='GET': | |
|
599 | ||||
|
600 | parms = conf.read_device() | |||
|
601 | ||||
|
602 | if not parms: | |||
|
603 | messages.error(request, conf.message) | |||
|
604 | return redirect(conf.get_absolute_url()) | |||
|
605 | ||||
|
606 | form = DevConfForm(initial=parms, instance=conf) | |||
|
607 | ||||
|
608 | if request.method=='POST': | |||
|
609 | form = DevConfForm(request.POST, instance=conf) | |||
|
610 | ||||
|
611 | if form.is_valid(): | |||
|
612 | dev_model = form.save(commit=False) | |||
|
613 | ||||
|
614 | if dev_model.save(): | |||
|
615 | return redirect(conf.get_absolute_url()) | |||
|
616 | ||||
|
617 | messages.error(request, "Parameters could not be saved") | |||
|
618 | ||||
|
619 | kwargs = {} | |||
|
620 | kwargs['id_dev'] = conf.id | |||
|
621 | kwargs['form'] = form | |||
|
622 | kwargs['title'] = 'Device Configuration' | |||
|
623 | kwargs['suptitle'] = 'Parameters read from device' | |||
|
624 | kwargs['button'] = 'Save' | |||
|
625 | ||||
|
626 | ###### SIDEBAR ###### | |||
|
627 | kwargs.update(sidebar(conf)) | |||
|
628 | ||||
|
629 | return render(conf.get_absolute_url_edit()) | |||
535 |
|
630 | |||
536 | def dev_conf_import(request, id_conf): |
|
631 | def dev_conf_import(request, id_conf): | |
537 |
|
632 | |||
538 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
633 | conf = get_object_or_404(Configuration, pk=id_conf) | |
539 |
|
634 | |||
540 | messages.error(request, "Import View not implemented yet") |
|
635 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
|
636 | DevConfForm = CONF_FORMS[conf.device.device_type.name] | |||
|
637 | ||||
|
638 | conf = DevConfModel.objects.get(pk=id_conf) | |||
|
639 | ||||
|
640 | if request.method == 'GET': | |||
|
641 | file_form = UploadFileForm() | |||
|
642 | ||||
|
643 | if request.method == 'POST': | |||
|
644 | file_form = UploadFileForm(request.POST, request.FILES) | |||
|
645 | ||||
|
646 | if file_form.is_valid(): | |||
541 |
|
647 | |||
542 | return redirect('url_dev_conf', id_conf=conf.id) |
|
648 | parms = conf.import_from_file(request.FILES['file']) | |
|
649 | ||||
|
650 | if parms: | |||
|
651 | ||||
|
652 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) | |||
|
653 | ||||
|
654 | form = DevConfForm(initial=parms, instance=conf) | |||
|
655 | ||||
|
656 | kwargs = {} | |||
|
657 | kwargs['id_dev'] = conf.id | |||
|
658 | kwargs['form'] = form | |||
|
659 | kwargs['title'] = 'Device Configuration' | |||
|
660 | kwargs['suptitle'] = 'Parameters imported' | |||
|
661 | kwargs['button'] = 'Save' | |||
|
662 | kwargs['action'] = conf.get_absolute_url_edit() | |||
|
663 | kwargs['previous'] = conf.get_absolute_url() | |||
|
664 | ||||
|
665 | ###### SIDEBAR ###### | |||
|
666 | kwargs.update(sidebar(conf)) | |||
|
667 | ||||
|
668 | return render(request, '%s_conf_edit.html' %conf.device.device_type.name, kwargs) | |||
|
669 | ||||
|
670 | messages.error(request, "Could not import parameters from file") | |||
|
671 | ||||
|
672 | kwargs = {} | |||
|
673 | kwargs['id_dev'] = conf.id | |||
|
674 | kwargs['title'] = 'Device Configuration' | |||
|
675 | kwargs['form'] = file_form | |||
|
676 | kwargs['suptitle'] = 'Importing file' | |||
|
677 | kwargs['button'] = 'Import' | |||
|
678 | ||||
|
679 | kwargs.update(sidebar(conf)) | |||
|
680 | ||||
|
681 | return render(request, 'dev_conf_import.html', kwargs) | |||
543 |
|
682 | |||
544 | def dev_conf_export(request, id_conf): |
|
683 | def dev_conf_export(request, id_conf): | |
545 |
|
684 | |||
546 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
685 | conf = get_object_or_404(Configuration, pk=id_conf) | |
547 |
|
686 | |||
548 | messages.error(request, "Export View not implemented yet") |
|
687 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
|
688 | ||||
|
689 | conf = DevConfModel.objects.get(pk=id_conf) | |||
|
690 | ||||
|
691 | if request.method == 'GET': | |||
|
692 | file_form = DownloadFileForm() | |||
|
693 | ||||
|
694 | if request.method == 'POST': | |||
|
695 | file_form = DownloadFileForm(request.POST) | |||
|
696 | ||||
|
697 | if file_form.is_valid(): | |||
|
698 | fields = conf.export_to_file(format = file_form.format) | |||
|
699 | ||||
|
700 | response = HttpResponse(content_type=fields['content_type']) | |||
|
701 | response['Content-Disposition'] = 'attachment; filename="%s"' %fields['filename'] | |||
|
702 | response.write(fields['content']) | |||
549 |
|
703 | |||
550 | return redirect('url_dev_conf', id_conf=conf.id) |
|
704 | return response | |
|
705 | ||||
|
706 | messages.error(request, "Could not export parameters") | |||
|
707 | ||||
|
708 | kwargs = {} | |||
|
709 | kwargs['id_dev'] = conf.id | |||
|
710 | kwargs['title'] = 'Device Configuration' | |||
|
711 | kwargs['form'] = file_form | |||
|
712 | kwargs['suptitle'] = 'Exporting file' | |||
|
713 | kwargs['button'] = 'Export' | |||
|
714 | ||||
|
715 | return render(request, 'dev_conf_export.html', kwargs) | |||
551 |
|
716 | |||
552 | def dev_conf_delete(request, id_conf): |
|
717 | def dev_conf_delete(request, id_conf): | |
553 |
|
718 | |||
554 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
719 | conf = get_object_or_404(Configuration, pk=id_conf) | |
555 |
|
720 | |||
556 | if request.method=='POST': |
|
721 | if request.method=='POST': | |
557 | if request.user.is_staff: |
|
722 | if request.user.is_staff: | |
558 | id_exp = conf.experiment.id |
|
723 | id_exp = conf.experiment.id | |
559 | conf.delete() |
|
724 | conf.delete() | |
560 | return redirect('url_experiment', id_exp=id_exp) |
|
725 | return redirect('url_experiment', id_exp=id_exp) | |
561 |
|
726 | |||
562 | return HttpResponse("Not enough permission to delete this object") |
|
727 | return HttpResponse("Not enough permission to delete this object") | |
563 |
|
728 | |||
564 | kwargs = {'object':conf, 'conf_active':'active', |
|
729 | kwargs = {'object':conf, 'conf_active':'active', | |
565 | 'url_cancel':'url_dev_conf', 'id_item':id_conf} |
|
730 | 'url_cancel':'url_dev_conf', 'id_item':id_conf} | |
566 |
|
731 | |||
567 | ###### SIDEBAR ###### |
|
732 | ###### SIDEBAR ###### | |
568 | kwargs.update(sidebar(conf)) |
|
733 | kwargs.update(sidebar(conf)) | |
569 |
|
734 | |||
570 | return render(request, 'item_delete.html', kwargs) |
|
735 | return render(request, 'item_delete.html', kwargs) | |
571 |
|
736 | |||
572 | def sidebar(conf): |
|
737 | def sidebar(conf): | |
573 |
|
738 | |||
574 | experiments = Experiment.objects.filter(campaign=conf.experiment.campaign) |
|
739 | experiments = Experiment.objects.filter(campaign=conf.experiment.campaign) | |
575 | configurations = Configuration.objects.filter(experiment=conf.experiment, type=0) |
|
740 | configurations = Configuration.objects.filter(experiment=conf.experiment, type=0) | |
576 |
|
741 | |||
577 | exp_keys = ['id', 'campaign', 'name', 'start_time', 'end_time'] |
|
742 | exp_keys = ['id', 'campaign', 'name', 'start_time', 'end_time'] | |
578 | conf_keys = ['id', 'device'] |
|
743 | conf_keys = ['id', 'device'] | |
579 |
|
744 | |||
580 | kwargs = {} |
|
745 | kwargs = {} | |
581 |
|
746 | |||
582 | kwargs['dev_conf'] = conf |
|
747 | kwargs['dev_conf'] = conf | |
583 |
|
748 | |||
584 | kwargs['experiment_keys'] = exp_keys[1:] |
|
749 | kwargs['experiment_keys'] = exp_keys[1:] | |
585 | kwargs['experiments'] = experiments.values(*exp_keys) |
|
750 | kwargs['experiments'] = experiments.values(*exp_keys) | |
586 |
|
751 | |||
587 | kwargs['configuration_keys'] = conf_keys[1:] |
|
752 | kwargs['configuration_keys'] = conf_keys[1:] | |
588 | kwargs['configurations'] = configurations #.values(*conf_keys) |
|
753 | kwargs['configurations'] = configurations #.values(*conf_keys) | |
589 |
|
754 | |||
590 | return kwargs |
|
755 | return kwargs | |
591 |
|
756 | |||
592 |
|
757 | |||
593 | def operation(request, id_camp=None): |
|
758 | def operation(request, id_camp=None): | |
594 |
|
759 | |||
595 | today = datetime.today() |
|
760 | if not id_camp: | |
|
761 | campaigns = Campaign.objects.all().order_by('-start_date') | |||
596 |
|
762 | |||
597 | if id_camp==None: |
|
763 | if not campaigns: | |
598 | id_camp = Campaign.objects.filter(start_date__month=today.month).filter(start_date__year=today.year).order_by('-start_date')[0].id |
|
764 | return render(request, 'operation.html', {}) | |
|
765 | ||||
|
766 | id_camp = campaigns[0].id | |||
599 |
|
|
767 | ||
600 | if request.method=='GET': |
|
|||
601 |
|
|
768 | campaign = get_object_or_404(Campaign, pk = id_camp) | |
602 | campaigns = Campaign.objects.filter(start_date__month=today.month).filter(start_date__year=today.year).order_by('-start_date') |
|
769 | ||
|
770 | if request.method=='GET': | |||
603 | form = OperationForm(initial={'campaign': id_camp}) |
|
771 | form = OperationForm(initial={'campaign': id_camp}) | |
604 |
|
772 | |||
605 |
if request.method=='POST': |
|
773 | if request.method=='POST': | |
606 | campaign = get_object_or_404(Campaign, pk=request.POST['campaign']) |
|
774 | form = OperationForm(request.POST, initial={'campaign':campaign.id}) | |
607 | #id_camp = Campaign.objects.filter(start_date__month=today.month).filter(start_date__year=today.year).order_by('-start_date')[1].id |
|
775 | ||
608 | form = OperationForm(request.POST, initial={'campaign':campaign.name}) |
|
|||
609 | if form.is_valid(): |
|
776 | if form.is_valid(): | |
610 | return redirect('url_operation', id_camp=campaign.id) |
|
777 | return redirect('url_operation', id_camp=campaign.id) | |
611 |
|
778 | |||
612 |
|
|
779 | locations = Location.objects.filter(experiment__campaign = campaign) | |
613 | experiments = [Experiment.objects.filter(radar=radar) for radar in radars] #zip(radars, [Experiment.objects.filter(radar=radar) for radar in radars]) |
|
780 | experiments = Experiment.objects.filter(campaign=campaign) | |
614 |
|
781 | |||
615 | kwargs = {} |
|
782 | kwargs = {} | |
616 | #---Campaign |
|
783 | #---Campaign | |
617 | kwargs['campaign'] = campaign |
|
784 | kwargs['campaign'] = campaign | |
618 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] |
|
785 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] | |
619 | #---Experimet |
|
786 | #---Experimet | |
620 | keys = ['id', 'name', 'start_time', 'end_time'] |
|
787 | keys = ['id', 'name', 'start_time', 'end_time'] | |
621 | kwargs['experiment_keys'] = keys[1:] |
|
788 | kwargs['experiment_keys'] = keys[1:] | |
622 | kwargs['experiments'] = experiments |
|
789 | kwargs['experiments'] = experiments | |
623 | #---Radar |
|
790 | #---Radar | |
624 |
kwargs[' |
|
791 | kwargs['locations'] = locations | |
625 | #---Else |
|
792 | #---Else | |
626 |
kwargs['title'] = ' |
|
793 | kwargs['title'] = 'Campaign' | |
627 | kwargs['suptitle'] = campaign.name |
|
794 | kwargs['suptitle'] = campaign.name | |
628 | kwargs['form'] = form |
|
795 | kwargs['form'] = form | |
629 |
kwargs['button'] = ' |
|
796 | kwargs['button'] = 'Apply' | |
630 |
|
797 | |||
631 | return render(request, 'operation.html', kwargs) No newline at end of file |
|
798 | return render(request, 'operation.html', kwargs) |
General Comments 0
You need to be logged in to leave comments.
Login now