@@ -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 | 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 | 4 | # Register your models here. |
|
5 | 5 | admin.site.register(Campaign) |
|
6 | 6 | admin.site.register(Experiment) |
|
7 | 7 | admin.site.register(Device) |
|
8 | 8 | admin.site.register(DeviceType) |
|
9 |
admin.site.register(Location) |
|
|
10 | admin.site.register(Radar) No newline at end of file | |
|
9 | admin.site.register(Location) No newline at end of file |
@@ -1,9 +1,5 | |||
|
1 | 1 | from django import forms |
|
2 | 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 | 4 | from .models import DeviceType, Device, Experiment, Campaign, Configuration, Location |
|
9 | 5 | |
@@ -38,6 +34,7 class CampaignForm(forms.ModelForm): | |||
|
38 | 34 | exclude = [''] |
|
39 | 35 | |
|
40 | 36 | class ExperimentForm(forms.ModelForm): |
|
37 | ||
|
41 | 38 | def __init__(self, *args, **kwargs): |
|
42 | 39 | super(ExperimentForm, self).__init__(*args, **kwargs) |
|
43 | 40 | self.fields['start_time'].widget = TimepickerWidget(self.fields['start_time'].widget.attrs) |
@@ -67,8 +64,17 class ConfigurationForm(forms.ModelForm): | |||
|
67 | 64 | class DeviceTypeForm(forms.Form): |
|
68 | 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 | 76 | class OperationForm(forms.Form): |
|
71 | today = datetime.today() | |
|
77 | # today = datetime.today() | |
|
72 | 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 | 80 | No newline at end of file |
@@ -49,6 +49,18 RADAR_STATES = ( | |||
|
49 | 49 | ) |
|
50 | 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 | 64 | class DeviceType(models.Model): |
|
53 | 65 | |
|
54 | 66 | name = models.CharField(max_length = 10, choices = DEV_TYPES, default = 'rc') |
@@ -62,8 +74,8 class DeviceType(models.Model): | |||
|
62 | 74 | |
|
63 | 75 | class Device(models.Model): |
|
64 | 76 | |
|
65 | device_type = models.ForeignKey(DeviceType) | |
|
66 |
|
|
|
77 | device_type = models.ForeignKey(DeviceType, on_delete=models.CASCADE) | |
|
78 | location = models.ForeignKey(Location, on_delete=models.CASCADE) | |
|
67 | 79 | |
|
68 | 80 | name = models.CharField(max_length=40, default='') |
|
69 | 81 | ip_address = models.GenericIPAddressField(protocol='IPv4', default='0.0.0.0') |
@@ -98,24 +110,27 class Campaign(models.Model): | |||
|
98 | 110 | def __unicode__(self): |
|
99 | 111 | return u'%s' % (self.name) |
|
100 | 112 | |
|
101 | class Radar(models.Model): | |
|
102 | ||
|
103 | name = models.CharField(max_length = 30) | |
|
104 | campaign = models.ForeignKey(Campaign) | |
|
105 | status = models.PositiveSmallIntegerField(default=0, choices=RADAR_STATES) | |
|
106 | ||
|
107 | class Meta: | |
|
108 | db_table = 'db_radar' | |
|
109 | ||
|
110 | def __unicode__(self): | |
|
111 | return u'%s' % self.name | |
|
113 | # class Radar(models.Model): | |
|
114 | # | |
|
115 | # # name = models.CharField(max_length = 30) | |
|
116 | # experiment = models.ForeignKey('Experiment', on_delete=models.CASCADE) | |
|
117 | # location = models.OneToOneField('Location', on_delete=models.CASCADE) | |
|
118 | # status = models.PositiveSmallIntegerField(default=0, choices=RADAR_STATES) | |
|
119 | # | |
|
120 | # class Meta: | |
|
121 | # db_table = 'db_radar' | |
|
122 | # | |
|
123 | # def __unicode__(self): | |
|
124 | # return u'%s' % self.location | |
|
112 | 125 | |
|
113 | 126 | |
|
114 | 127 | class Experiment(models.Model): |
|
115 | 128 | |
|
116 | 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 | 134 | name = models.CharField(max_length=40, default='') |
|
120 | 135 | start_time = models.TimeField(default='00:00:00') |
|
121 | 136 | end_time = models.TimeField(default='23:59:59') |
@@ -124,7 +139,7 class Experiment(models.Model): | |||
|
124 | 139 | db_table = 'db_experiments' |
|
125 | 140 | |
|
126 | 141 | def __unicode__(self): |
|
127 |
return u' |
|
|
142 | return u'%s' % (self.name) | |
|
128 | 143 | |
|
129 | 144 | class Configuration(PolymorphicModel): |
|
130 | 145 | |
@@ -132,8 +147,8 class Configuration(PolymorphicModel): | |||
|
132 | 147 | |
|
133 | 148 | name = models.CharField(verbose_name="Configuration Name", max_length=40, default='') |
|
134 | 149 | |
|
135 | experiment = models.ForeignKey(Experiment) | |
|
136 | device = models.ForeignKey(Device) | |
|
150 | experiment = models.ForeignKey('Experiment', null=True, blank=True, on_delete=models.CASCADE) | |
|
151 | device = models.ForeignKey(Device, on_delete=models.CASCADE) | |
|
137 | 152 | |
|
138 | 153 | type = models.PositiveSmallIntegerField(default=0, choices=CONF_TYPES) |
|
139 | 154 | |
@@ -142,14 +157,94 class Configuration(PolymorphicModel): | |||
|
142 | 157 | |
|
143 | 158 | parameters = models.TextField(default='{}') |
|
144 | 159 | |
|
160 | message = "" | |
|
161 | ||
|
145 | 162 | class Meta: |
|
146 | 163 | db_table = 'db_configurations' |
|
147 | 164 | |
|
148 | 165 | def __unicode__(self): |
|
149 |
return u'[%s - %s]: %s' % (self.experiment. |
|
|
166 | return u'[%s - %s]: %s' % (self.experiment.name, | |
|
150 | 167 | self.experiment.name, |
|
151 | 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 | 248 | def get_absolute_url(self): |
|
154 | 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 | 252 | return reverse('url_edit_%s_conf' % self.device.device_type.name, args=[str(self.id)]) |
|
158 | 253 | |
|
159 | 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 | 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 | 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 | 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): | |
|
172 | ||
|
173 | name = models.CharField(max_length = 30) | |
|
174 | description = models.TextField(blank=True, null=True) | |
|
175 | ||
|
176 | class Meta: | |
|
177 | db_table = 'db_location' | |
|
266 | def get_absolute_url_start(self): | |
|
267 | return reverse('url_start_dev_conf', args=[str(self.id)]) | |
|
178 | 268 | |
|
179 |
def |
|
|
180 | return u'%s' % self.name No newline at end of file | |
|
269 | def get_absolute_url_stop(self): | |
|
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 | 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 | 28 | <table class="table table-bordered"> |
|
14 | 29 | <tr> |
|
15 | 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 | 32 | </tr> |
|
18 | 33 | |
|
19 | 34 | {% for key in dev_conf_keys %} |
@@ -24,13 +39,6 | |||
|
24 | 39 | {% endfor %} |
|
25 | 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 | 42 | {% endblock %} |
|
35 | 43 | |
|
36 | 44 | {% block sidebar%} |
@@ -23,17 +23,17 | |||
|
23 | 23 | <br> |
|
24 | 24 | </form> |
|
25 | 25 | <br> |
|
26 | <br> | |
|
26 | 27 | |
|
27 | 28 | <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true" > |
|
28 | 29 | |
|
29 |
{% for |
|
|
30 | {% for location in locations %} | |
|
30 | 31 | |
|
31 | 32 | <div class="panel panel-default"> |
|
32 | 33 | <div class="panel-heading" role="tab" id="headingTwo"> |
|
33 | 34 | <h4 class="panel-title"> |
|
34 | ||
|
35 | <a class="collapsed" role="button" data-toggle="collapse" href="#collapseTwo-{{ radar.id }}" aria-expanded="false" aria-controls="collapseTwo"> | |
|
36 | {{radar.name}}: Experiment List | |
|
35 | <a class="collapsed" role="button" data-toggle="collapse" href="#collapseTwo-{{ location.id }}" aria-expanded="false" aria-controls="collapseTwo"> | |
|
36 | {{location.name}}: Experiment List | |
|
37 | 37 | <span> |
|
38 | 38 | </span> |
|
39 | 39 | </a> |
@@ -47,26 +47,25 | |||
|
47 | 47 | </h4> |
|
48 | 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 | 51 | <div class="panel-body"> |
|
52 | 52 | <table class="table table-hover"> |
|
53 | 53 | <tr> |
|
54 | ||
|
54 | <th>#</th> | |
|
55 | 55 | {% for header in experiment_keys %} |
|
56 | 56 | <th>{{ header|title }}</th> |
|
57 | 57 | {% endfor%} |
|
58 | 58 | </tr> |
|
59 | ||
|
59 | 60 | {% for item in experiments %} |
|
60 | {% for exs in item %} | |
|
61 |
<tr class="clickable-row" data-href="{% url 'url_experiment' |
|
|
62 | ||
|
63 | {% for key in experiment_keys %} | |
|
64 | {% if radar.name in exs.radar.name %} | |
|
65 | <td>{{ exs|attr:key }}</td> | |
|
66 | {% endif %} | |
|
67 |
|
|
|
68 | {% endfor %} | |
|
69 | </tr> | |
|
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> | |
|
64 | {% for key in experiment_keys %} | |
|
65 | <td>{{ item|value:key }}</td> | |
|
66 | {% endfor %} | |
|
67 | </tr> | |
|
68 | {% endif %} | |
|
70 | 69 | {% endfor %} |
|
71 | 70 | </table> |
|
72 | 71 | </div> |
@@ -30,6 +30,14 urlpatterns = ( | |||
|
30 | 30 | url(r'^dev_conf/(?P<id_conf>-?\d+)/$', 'apps.main.views.dev_conf', name='url_dev_conf'), |
|
31 | 31 | url(r'^dev_conf/(?P<id_conf>-?\d+)/edit/$', 'apps.main.views.dev_conf_edit', name='url_edit_dev_conf'), |
|
32 | 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 | 42 | url(r'^operation/$', 'apps.main.views.operation', name='url_operation'), |
|
35 | 43 | url(r'^operation/(?P<id_camp>-?\d+)/$', 'apps.main.views.operation', name='url_operation'), |
@@ -1,9 +1,7 | |||
|
1 | 1 | from django.shortcuts import render, redirect, get_object_or_404, HttpResponse |
|
2 | 2 | from django.contrib import messages |
|
3 | 3 | |
|
4 | from datetime import datetime | |
|
5 | ||
|
6 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm, OperationForm | |
|
4 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm, UploadFileForm, DownloadFileForm, OperationForm | |
|
7 | 5 | from apps.cgs.forms import CGSConfigurationForm |
|
8 | 6 | from apps.jars.forms import JARSConfigurationForm |
|
9 | 7 | from apps.usrp.forms import USRPConfigurationForm |
@@ -11,7 +9,7 from apps.abs.forms import ABSConfigurationForm | |||
|
11 | 9 | from apps.rc.forms import RCConfigurationForm |
|
12 | 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 | 13 | from apps.cgs.models import CGSConfiguration |
|
16 | 14 | from apps.jars.models import JARSConfiguration |
|
17 | 15 | from apps.usrp.models import USRPConfiguration |
@@ -237,7 +235,8 def campaigns(request): | |||
|
237 | 235 | def campaign(request, id_camp): |
|
238 | 236 | |
|
239 | 237 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
240 |
|
|
|
238 | experiments = Experiment.objects.filter(campaign=campaign) | |
|
239 | ||
|
241 | 240 | form = CampaignForm(instance=campaign) |
|
242 | 241 | |
|
243 | 242 | kwargs = {} |
@@ -247,7 +246,7 def campaign(request, id_camp): | |||
|
247 | 246 | keys = ['id', 'name', 'start_time', 'end_time'] |
|
248 | 247 | |
|
249 | 248 | kwargs['experiment_keys'] = keys[1:] |
|
250 |
|
|
|
249 | kwargs['experiments'] = experiments.values(*keys) | |
|
251 | 250 | |
|
252 | 251 | kwargs['title'] = 'Campaign' |
|
253 | 252 | kwargs['suptitle'] = 'Details' |
@@ -341,7 +340,7 def experiment(request, id_exp): | |||
|
341 | 340 | |
|
342 | 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 | 344 | conf_keys = ['id', 'device__name', 'device__device_type', 'device__ip_address', 'device__port_address'] |
|
346 | 345 | |
|
347 | 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 | 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 | 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 | 565 | def dev_conf_write(request, id_conf): |
|
529 | 566 | |
|
530 | 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 | 631 | def dev_conf_import(request, id_conf): |
|
537 | 632 | |
|
538 | 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 | 683 | def dev_conf_export(request, id_conf): |
|
545 | 684 | |
|
546 | 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 | 717 | def dev_conf_delete(request, id_conf): |
|
553 | 718 | |
@@ -592,25 +757,27 def sidebar(conf): | |||
|
592 | 757 | |
|
593 | 758 | def operation(request, id_camp=None): |
|
594 | 759 | |
|
595 | today = datetime.today() | |
|
596 | ||
|
597 | if id_camp==None: | |
|
598 | id_camp = Campaign.objects.filter(start_date__month=today.month).filter(start_date__year=today.year).order_by('-start_date')[0].id | |
|
760 | if not id_camp: | |
|
761 | campaigns = Campaign.objects.all().order_by('-start_date') | |
|
762 | ||
|
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 | 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 | 771 | form = OperationForm(initial={'campaign': id_camp}) |
|
604 | 772 | |
|
605 |
if request.method=='POST': |
|
|
606 | campaign = get_object_or_404(Campaign, pk=request.POST['campaign']) | |
|
607 | #id_camp = Campaign.objects.filter(start_date__month=today.month).filter(start_date__year=today.year).order_by('-start_date')[1].id | |
|
608 | form = OperationForm(request.POST, initial={'campaign':campaign.name}) | |
|
773 | if request.method=='POST': | |
|
774 | form = OperationForm(request.POST, initial={'campaign':campaign.id}) | |
|
775 | ||
|
609 | 776 | if form.is_valid(): |
|
610 | 777 | return redirect('url_operation', id_camp=campaign.id) |
|
611 | 778 | |
|
612 |
|
|
|
613 | experiments = [Experiment.objects.filter(radar=radar) for radar in radars] #zip(radars, [Experiment.objects.filter(radar=radar) for radar in radars]) | |
|
779 | locations = Location.objects.filter(experiment__campaign = campaign) | |
|
780 | experiments = Experiment.objects.filter(campaign=campaign) | |
|
614 | 781 | |
|
615 | 782 | kwargs = {} |
|
616 | 783 | #---Campaign |
@@ -621,11 +788,11 def operation(request, id_camp=None): | |||
|
621 | 788 | kwargs['experiment_keys'] = keys[1:] |
|
622 | 789 | kwargs['experiments'] = experiments |
|
623 | 790 | #---Radar |
|
624 |
kwargs[' |
|
|
791 | kwargs['locations'] = locations | |
|
625 | 792 | #---Else |
|
626 |
kwargs['title'] = ' |
|
|
793 | kwargs['title'] = 'Campaign' | |
|
627 | 794 | kwargs['suptitle'] = campaign.name |
|
628 | 795 | kwargs['form'] = form |
|
629 |
kwargs['button'] = ' |
|
|
796 | kwargs['button'] = 'Apply' | |
|
630 | 797 | |
|
631 | 798 | return render(request, 'operation.html', kwargs) No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now