@@ -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,9 +1,5 | |||||
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 | |||
@@ -38,6 +34,7 class CampaignForm(forms.ModelForm): | |||||
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) | |
@@ -67,8 +64,17 class ConfigurationForm(forms.ModelForm): | |||||
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 |
@@ -49,6 +49,18 RADAR_STATES = ( | |||||
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') | |
@@ -62,8 +74,8 class DeviceType(models.Model): | |||||
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') | |
@@ -98,24 +110,27 class Campaign(models.Model): | |||||
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') | |
@@ -124,7 +139,7 class Experiment(models.Model): | |||||
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 | |||
@@ -132,8 +147,8 class Configuration(PolymorphicModel): | |||||
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 | |||
@@ -142,14 +157,94 class Configuration(PolymorphicModel): | |||||
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) | |
|
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 | |||
152 |
|
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 | |||
@@ -157,24 +252,22 class Configuration(PolymorphicModel): | |||||
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): | |
172 |
|
267 | return reverse('url_start_dev_conf', args=[str(self.id)]) | ||
173 | name = models.CharField(max_length = 30) |
|
|||
174 | description = models.TextField(blank=True, null=True) |
|
|||
175 |
|
||||
176 | class Meta: |
|
|||
177 | db_table = 'db_location' |
|
|||
178 |
|
268 | |||
179 |
def |
|
269 | def get_absolute_url_stop(self): | |
180 | return u'%s' % self.name No newline at end of file |
|
270 | return reverse('url_stop_dev_conf', args=[str(self.id)]) | |
|
271 | ||||
|
272 | def get_absolute_url_status(self): | |||
|
273 | return reverse('url_status_dev_conf', args=[str(self.id)]) No newline at end of file |
@@ -10,10 +10,25 | |||||
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 %} | |
@@ -24,13 +39,6 | |||||
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%} |
@@ -23,17 +23,17 | |||||
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> | |
@@ -47,26 +47,25 | |||||
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 | ||||
59 | {% for item in experiments %} |
|
60 | {% for item in experiments %} | |
60 | {% for exs in item %} |
|
61 | {% if location.name in item.location.name %} | |
61 |
<tr class="clickable-row" data-href="{% url 'url_experiment' |
|
62 | <tr class="clickable-row" data-href="{% url 'url_experiment' item.id %}" > | |
62 |
|
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 | {% endfor %} | |
66 | {% endif %} |
|
67 | </tr> | |
67 |
|
|
68 | {% endif %} | |
68 | {% endfor %} |
|
|||
69 | </tr> |
|
|||
70 | {% endfor %} |
|
69 | {% endfor %} | |
71 | </table> |
|
70 | </table> | |
72 | </div> |
|
71 | </div> |
@@ -30,6 +30,14 urlpatterns = ( | |||||
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 | ||||
|
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'), | |||
33 |
|
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'), |
@@ -1,9 +1,7 | |||||
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 | |
@@ -11,7 +9,7 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 | |
@@ -237,7 +235,8 def campaigns(request): | |||||
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 = {} | |
@@ -247,7 +246,7 def campaign(request, id_camp): | |||||
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' | |
@@ -341,7 +340,7 def experiment(request, id_exp): | |||||
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'] | |
@@ -517,37 +516,203 def dev_conf_edit(request, id_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): | |||
521 |
|
535 | |||
522 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
536 | conf = get_object_or_404(Configuration, pk=id_conf) | |
523 |
|
537 | |||
524 | messages.error(request, "Read View not implemented yet") |
|
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): | |||
|
550 | ||||
|
551 | conf = get_object_or_404(Configuration, pk=id_conf) | |||
|
552 | ||||
|
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) | |||
525 |
|
561 | |||
526 | return redirect('url_dev_conf', id_conf=conf.id) |
|
562 | return redirect(conf.get_absolute_url()) | |
|
563 | ||||
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) | |||
533 |
|
586 | |||
534 | return redirect('url_dev_conf', id_conf=conf.id) |
|
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) | |||
|
597 | ||||
|
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] | |||
541 |
|
637 | |||
542 | return redirect('url_dev_conf', id_conf=conf.id) |
|
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(): | |||
|
647 | ||||
|
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']) | |||
|
703 | ||||
|
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' | |||
549 |
|
714 | |||
550 | return redirect('url_dev_conf', id_conf=conf.id) |
|
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 | |||
@@ -592,25 +757,27 def sidebar(conf): | |||||
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: | |
596 |
|
761 | campaigns = Campaign.objects.all().order_by('-start_date') | ||
597 | if id_camp==None: |
|
762 | ||
598 | id_camp = Campaign.objects.filter(start_date__month=today.month).filter(start_date__year=today.year).order_by('-start_date')[0].id |
|
763 | if not campaigns: | |
|
764 | return render(request, 'operation.html', {}) | |||
599 |
|
765 | |||
|
766 | id_camp = campaigns[0].id | |||
|
767 | ||||
|
768 | campaign = get_object_or_404(Campaign, pk = id_camp) | |||
|
769 | ||||
600 | if request.method=='GET': |
|
770 | if request.method=='GET': | |
601 | 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') |
|
|||
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 | |
@@ -621,11 +788,11 def operation(request, id_camp=None): | |||||
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