@@ -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,74 +1,80 | |||
|
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 | |
|
10 | 6 | def add_empty_choice(choices, pos=0, label='-----'): |
|
11 | 7 | if len(choices)>0: |
|
12 | 8 | choices = list(choices) |
|
13 | 9 | choices.insert(0, (0, label)) |
|
14 | 10 | return choices |
|
15 | 11 | else: |
|
16 | 12 | return [(0, label)] |
|
17 | 13 | |
|
18 | 14 | class DatepickerWidget(forms.widgets.TextInput): |
|
19 | 15 | def render(self, name, value, attrs=None): |
|
20 | 16 | input_html = super(DatepickerWidget, self).render(name, value, attrs) |
|
21 | 17 | html = '<div class="input-group date">'+input_html+'<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span></div>' |
|
22 | 18 | return mark_safe(html) |
|
23 | 19 | |
|
24 | 20 | class TimepickerWidget(forms.widgets.TextInput): |
|
25 | 21 | def render(self, name, value, attrs=None): |
|
26 | 22 | input_html = super(TimepickerWidget, self).render(name, value, attrs) |
|
27 | 23 | html = '<div class="input-group time">'+input_html+'<span class="input-group-addon"><i class="glyphicon glyphicon-time"></i></span></div>' |
|
28 | 24 | return mark_safe(html) |
|
29 | 25 | |
|
30 | 26 | class CampaignForm(forms.ModelForm): |
|
31 | 27 | def __init__(self, *args, **kwargs): |
|
32 | 28 | super(CampaignForm, self).__init__(*args, **kwargs) |
|
33 | 29 | self.fields['start_date'].widget = DatepickerWidget(self.fields['start_date'].widget.attrs) |
|
34 | 30 | self.fields['end_date'].widget = DatepickerWidget(self.fields['end_date'].widget.attrs) |
|
35 | 31 | |
|
36 | 32 | class Meta: |
|
37 | 33 | model = Campaign |
|
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) |
|
44 | 41 | self.fields['end_time'].widget = TimepickerWidget(self.fields['end_time'].widget.attrs) |
|
45 | 42 | |
|
46 | 43 | self.fields['campaign'].widget.attrs['readonly'] = True |
|
47 | 44 | |
|
48 | 45 | class Meta: |
|
49 | 46 | model = Experiment |
|
50 | 47 | exclude = [''] |
|
51 | 48 | |
|
52 | 49 | class LocationForm(forms.ModelForm): |
|
53 | 50 | class Meta: |
|
54 | 51 | model = Location |
|
55 | 52 | exclude = [''] |
|
56 | 53 | |
|
57 | 54 | class DeviceForm(forms.ModelForm): |
|
58 | 55 | class Meta: |
|
59 | 56 | model = Device |
|
60 | 57 | exclude = ['status'] |
|
61 | 58 | |
|
62 | 59 | class ConfigurationForm(forms.ModelForm): |
|
63 | 60 | class Meta: |
|
64 | 61 | model = Configuration |
|
65 | 62 | exclude = ['type', 'created_date', 'programmed_date', 'parameters'] |
|
66 | 63 | |
|
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 |
@@ -1,180 +1,273 | |||
|
1 | 1 | from django.db import models |
|
2 | 2 | from polymorphic import PolymorphicModel |
|
3 | 3 | |
|
4 | 4 | from django.core.urlresolvers import reverse |
|
5 | 5 | |
|
6 | 6 | CONF_STATES = ( |
|
7 | 7 | (0, 'Disconnected'), |
|
8 | 8 | (1, 'Connected'), |
|
9 | 9 | (1, 'Running'), |
|
10 | 10 | ) |
|
11 | 11 | |
|
12 | 12 | CONF_TYPES = ( |
|
13 | 13 | (0, 'Active'), |
|
14 | 14 | (1, 'Historical'), |
|
15 | 15 | ) |
|
16 | 16 | |
|
17 | 17 | DEV_STATES = ( |
|
18 | 18 | (0, 'No connected'), |
|
19 | 19 | (1, 'Connected'), |
|
20 | 20 | (2, 'Configured'), |
|
21 | 21 | (3, 'Running'), |
|
22 | 22 | ) |
|
23 | 23 | |
|
24 | 24 | DEV_TYPES = ( |
|
25 | 25 | ('', 'Select a device type'), |
|
26 | 26 | ('rc', 'Radar Controller'), |
|
27 | 27 | ('dds', 'Direct Digital Synthesizer'), |
|
28 | 28 | ('jars', 'Jicamarca Radar Acquisition System'), |
|
29 | 29 | ('usrp', 'Universal Software Radio Peripheral'), |
|
30 | 30 | ('cgs', 'Clock Generator System'), |
|
31 | 31 | ('abs', 'Automatic Beam Switching'), |
|
32 | 32 | ) |
|
33 | 33 | |
|
34 | 34 | DEV_PORTS = { |
|
35 | 35 | 'rc' : 2000, |
|
36 | 36 | 'dds' : 2000, |
|
37 | 37 | 'jars' : 2000, |
|
38 | 38 | 'usrp' : 2000, |
|
39 | 39 | 'cgs' : 8080, |
|
40 | 40 | 'abs' : 8080 |
|
41 | 41 | } |
|
42 | 42 | |
|
43 | 43 | RADAR_STATES = ( |
|
44 | 44 | (0, 'No connected'), |
|
45 | 45 | (1, 'Connnected'), |
|
46 | 46 | (2, 'Configured'), |
|
47 | 47 | (3, 'Running'), |
|
48 | 48 | (4, 'Scheduled'), |
|
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') |
|
55 | 67 | description = models.TextField(blank=True, null=True) |
|
56 | 68 | |
|
57 | 69 | class Meta: |
|
58 | 70 | db_table = 'db_device_types' |
|
59 | 71 | |
|
60 | 72 | def __unicode__(self): |
|
61 | 73 | return u'%s' % self.get_name_display() |
|
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') |
|
70 | 82 | port_address = models.PositiveSmallIntegerField(default=2000) |
|
71 | 83 | description = models.TextField(blank=True, null=True) |
|
72 | 84 | status = models.PositiveSmallIntegerField(default=0, choices=DEV_STATES) |
|
73 | 85 | |
|
74 | 86 | class Meta: |
|
75 | 87 | db_table = 'db_devices' |
|
76 | 88 | |
|
77 | 89 | def __unicode__(self): |
|
78 | 90 | return u'%s | %s' % (self.name, self.ip_address) |
|
79 | 91 | |
|
80 | 92 | def get_status(self): |
|
81 | 93 | |
|
82 | 94 | return self.status |
|
83 | 95 | |
|
84 | 96 | |
|
85 | 97 | class Campaign(models.Model): |
|
86 | 98 | |
|
87 | 99 | template = models.BooleanField(default=False) |
|
88 | 100 | |
|
89 | 101 | name = models.CharField(max_length=40, unique=True) |
|
90 | 102 | start_date = models.DateTimeField(blank=True, null=True) |
|
91 | 103 | end_date = models.DateTimeField(blank=True, null=True) |
|
92 | 104 | tags = models.CharField(max_length=40) |
|
93 | 105 | description = models.TextField(blank=True, null=True) |
|
94 | 106 | |
|
95 | 107 | class Meta: |
|
96 | 108 | db_table = 'db_campaigns' |
|
97 | 109 | |
|
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') |
|
122 | 137 | |
|
123 | 138 | class Meta: |
|
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 | |
|
131 | 146 | template = models.BooleanField(default=False) |
|
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 | |
|
140 | 155 | created_date = models.DateTimeField(auto_now_add=True) |
|
141 | 156 | programmed_date = models.DateTimeField(auto_now=True) |
|
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 | |
|
156 | 251 | def get_absolute_url_edit(self): |
|
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 |
@@ -1,64 +1,72 | |||
|
1 | 1 | {% extends "base.html" %} |
|
2 | 2 | {% load bootstrap3 %} |
|
3 | 3 | {% load static %} |
|
4 | 4 | {% load main_tags %} |
|
5 | 5 | |
|
6 | 6 | {% block conf-active %}active{% endblock %} |
|
7 | 7 | |
|
8 | 8 | {% block content-title %}{{title}}{% endblock %} |
|
9 | 9 | {% block content-suptitle %}{{suptitle}}{% endblock %} |
|
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 %} |
|
20 | 35 | <tr> |
|
21 | 36 | <th>{% get_verbose_field_name dev_conf key %}</th> |
|
22 | 37 | <td>{{dev_conf|attr:key}}</td> |
|
23 | 38 | </tr> |
|
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%} |
|
37 | 45 | {% include "sidebar_devices.html" %} |
|
38 | 46 | {% endblock %} |
|
39 | 47 | |
|
40 | 48 | {% block extra-js%} |
|
41 | 49 | <script type="text/javascript"> |
|
42 | 50 | |
|
43 | 51 | $("#bt_edit").click(function() { |
|
44 | 52 | document.location = "{{ dev_conf.get_absolute_url_edit }}"; |
|
45 | 53 | }); |
|
46 | 54 | |
|
47 | 55 | $("#bt_read").click(function() { |
|
48 | 56 | document.location = "{{ dev_conf.get_absolute_url_read }}"; |
|
49 | 57 | }); |
|
50 | 58 | |
|
51 | 59 | $("#bt_write").click(function() { |
|
52 | 60 | document.location = "{{ dev_conf.get_absolute_url_write }}"; |
|
53 | 61 | }); |
|
54 | 62 | |
|
55 | 63 | $("#bt_import").click(function() { |
|
56 | 64 | document.location = "{{ dev_conf.get_absolute_url_import }}"; |
|
57 | 65 | }); |
|
58 | 66 | |
|
59 | 67 | $("#bt_export").click(function() { |
|
60 | 68 | document.location = "{{ dev_conf.get_absolute_url_export }}"; |
|
61 | 69 | }); |
|
62 | 70 | |
|
63 | 71 | </script> |
|
64 | 72 | {% endblock %} No newline at end of file |
@@ -1,104 +1,103 | |||
|
1 | 1 | {% extends "base.html" %} |
|
2 | 2 | {% load bootstrap3 %} |
|
3 | 3 | {% load static %} |
|
4 | 4 | {% load main_tags %} |
|
5 | 5 | {% block extra-head %} |
|
6 | 6 | <link href="{% static 'css/bootstrap-datetimepicker.min.css' %}" media="screen" rel="stylesheet"> |
|
7 | 7 | {% endblock %} |
|
8 | 8 | |
|
9 | 9 | {% block camp-active %}active{% endblock %} |
|
10 | 10 | |
|
11 | 11 | {% block content-title %}{{title}}{% endblock %} |
|
12 | 12 | {% block content-suptitle %}{{suptitle}}{% endblock %} |
|
13 | 13 | |
|
14 | 14 | {% block content %} |
|
15 | 15 | |
|
16 | 16 | <form class="form" method="post" action=""> |
|
17 | 17 | {% csrf_token %} |
|
18 | 18 | {% bootstrap_form form layout='horizontal' size='medium' %} |
|
19 | 19 | <div style="clear: both;"></div> |
|
20 | 20 | <br> |
|
21 | 21 | <button type="submit" class="btn btn-primary pull-right">{{button}}</button> |
|
22 | 22 | <br> |
|
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> |
|
40 | 40 | <button type="button" class="btn btn-primary pull-right btn-xs" aria-label="Left Align" style="margin-left: 10px"> |
|
41 | 41 | <span class="glyphicon glyphicon-play" aria-hidden="true"></span> |
|
42 | 42 | </button> |
|
43 | 43 | <button type="button" class="btn btn-primary pull-right btn-xs" aria-label="Left Align" style="margin-left: 10px"> |
|
44 | 44 | <span class="glyphicon glyphicon-stop" aria-hidden="true"></span> |
|
45 | 45 | </button> |
|
46 | 46 | |
|
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> |
|
73 | 72 | </div> |
|
74 | 73 | </div> |
|
75 | 74 | {% endfor %} |
|
76 | 75 | </div> |
|
77 | 76 | |
|
78 | 77 | {% endblock %} |
|
79 | 78 | |
|
80 | 79 | |
|
81 | 80 | |
|
82 | 81 | {% block extra-js%} |
|
83 | 82 | <script type="text/javascript"> |
|
84 | 83 | |
|
85 | 84 | //$("#bt_add").click(function() { |
|
86 | 85 | //alert("sometext"); |
|
87 | 86 | // document.location = "{% url 'url_operation' campaign.id %}"; |
|
88 | 87 | //}); |
|
89 | 88 | |
|
90 | 89 | $(".clickable-row").click(function() { |
|
91 | 90 | document.location = $(this).data("href"); |
|
92 | 91 | }); |
|
93 | 92 | |
|
94 | 93 | $(document).ready(function() { |
|
95 | 94 | $("#id_campaign").change(function() { |
|
96 | 95 | var id_camp = document.getElementById("id_campaign").value; |
|
97 | 96 | //alert(id_camp); |
|
98 | 97 | document.location = "{% url 'url_operation'%}"+String(id_camp); |
|
99 | 98 | }); |
|
100 | 99 | }); |
|
101 | 100 | |
|
102 | 101 | |
|
103 | 102 | </script> |
|
104 | 103 | {% endblock %} No newline at end of file |
@@ -1,37 +1,45 | |||
|
1 | 1 | from django.conf.urls import url |
|
2 | 2 | |
|
3 | 3 | urlpatterns = ( |
|
4 | 4 | url(r'^location/new/$', 'apps.main.views.location_new', name='url_add_location'), |
|
5 | 5 | url(r'^location/$', 'apps.main.views.locations', name='url_locations'), |
|
6 | 6 | url(r'^location/(?P<id_loc>-?\d+)/$', 'apps.main.views.location', name='url_location'), |
|
7 | 7 | url(r'^location/(?P<id_loc>-?\d+)/edit/$', 'apps.main.views.location_edit', name='url_edit_location'), |
|
8 | 8 | url(r'^location/(?P<id_loc>-?\d+)/delete/$', 'apps.main.views.location_delete', name='url_delete_location'), |
|
9 | 9 | |
|
10 | 10 | url(r'^device/new/$', 'apps.main.views.device_new', name='url_add_device'), |
|
11 | 11 | url(r'^device/$', 'apps.main.views.devices', name='url_devices'), |
|
12 | 12 | url(r'^device/(?P<id_dev>-?\d+)/$', 'apps.main.views.device', name='url_device'), |
|
13 | 13 | url(r'^device/(?P<id_dev>-?\d+)/edit/$', 'apps.main.views.device_edit', name='url_edit_device'), |
|
14 | 14 | url(r'^device/(?P<id_dev>-?\d+)/delete/$', 'apps.main.views.device_delete', name='url_delete_device'), |
|
15 | 15 | |
|
16 | 16 | url(r'^campaign/new/$', 'apps.main.views.campaign_new', name='url_add_campaign'), |
|
17 | 17 | url(r'^campaign/$', 'apps.main.views.campaigns', name='url_campaigns'), |
|
18 | 18 | url(r'^campaign/(?P<id_camp>-?\d+)/$', 'apps.main.views.campaign', name='url_campaign'), |
|
19 | 19 | url(r'^campaign/(?P<id_camp>-?\d+)/edit/$', 'apps.main.views.campaign_edit', name='url_edit_campaign'), |
|
20 | 20 | url(r'^campaign/(?P<id_camp>-?\d+)/delete/$', 'apps.main.views.campaign_delete', name='url_delete_campaign'), |
|
21 | 21 | |
|
22 | 22 | url(r'^campaign/(?P<id_camp>-?\d+)/new_experiment/$', 'apps.main.views.experiment_new', name='url_add_experiment'), |
|
23 | 23 | url(r'^experiment/$', 'apps.main.views.experiments', name='url_experiments'), |
|
24 | 24 | url(r'^experiment/(?P<id_exp>-?\d+)/$', 'apps.main.views.experiment', name='url_experiment'), |
|
25 | 25 | url(r'^experiment/(?P<id_exp>-?\d+)/edit/$', 'apps.main.views.experiment_edit', name='url_edit_experiment'), |
|
26 | 26 | url(r'^experiment/(?P<id_exp>-?\d+)/delete/$', 'apps.main.views.experiment_delete', name='url_delete_experiment'), |
|
27 | 27 | |
|
28 | 28 | url(r'^experiment/(?P<id_exp>-?\d+)/new_dev_conf/$', 'apps.main.views.dev_conf_new', name='url_add_dev_conf'), |
|
29 | 29 | url(r'^dev_conf/$', 'apps.main.views.dev_confs', name='url_dev_confs'), |
|
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'), |
|
36 | 44 | |
|
37 | 45 | ) |
@@ -1,631 +1,798 | |||
|
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 |
|
10 | 8 | 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 |
|
18 | 16 | from apps.abs.models import ABSConfiguration |
|
19 | 17 | from apps.rc.models import RCConfiguration |
|
20 | 18 | from apps.dds.models import DDSConfiguration |
|
21 | 19 | |
|
22 | 20 | # Create your views here. |
|
23 | 21 | |
|
24 | 22 | CONF_FORMS = { |
|
25 | 23 | 'rc': RCConfigurationForm, |
|
26 | 24 | 'dds': DDSConfigurationForm, |
|
27 | 25 | 'jars': JARSConfigurationForm, |
|
28 | 26 | 'cgs': CGSConfigurationForm, |
|
29 | 27 | 'abs': ABSConfigurationForm, |
|
30 | 28 | 'usrp': USRPConfigurationForm, |
|
31 | 29 | } |
|
32 | 30 | |
|
33 | 31 | CONF_MODELS = { |
|
34 | 32 | 'rc': RCConfiguration, |
|
35 | 33 | 'dds': DDSConfiguration, |
|
36 | 34 | 'jars': JARSConfiguration, |
|
37 | 35 | 'cgs': CGSConfiguration, |
|
38 | 36 | 'abs': ABSConfiguration, |
|
39 | 37 | 'usrp': USRPConfiguration, |
|
40 | 38 | } |
|
41 | 39 | |
|
42 | 40 | def index(request): |
|
43 | 41 | kwargs = {} |
|
44 | 42 | |
|
45 | 43 | return render(request, 'index.html', kwargs) |
|
46 | 44 | |
|
47 | 45 | def locations(request): |
|
48 | 46 | |
|
49 | 47 | locations = Location.objects.all().order_by('name') |
|
50 | 48 | |
|
51 | 49 | keys = ['id', 'name', 'description'] |
|
52 | 50 | |
|
53 | 51 | kwargs = {} |
|
54 | 52 | kwargs['location_keys'] = keys[1:] |
|
55 | 53 | kwargs['locations'] = locations |
|
56 | 54 | kwargs['title'] = 'Location' |
|
57 | 55 | kwargs['suptitle'] = 'List' |
|
58 | 56 | kwargs['button'] = 'New Location' |
|
59 | 57 | |
|
60 | 58 | return render(request, 'locations.html', kwargs) |
|
61 | 59 | |
|
62 | 60 | def location(request, id_loc): |
|
63 | 61 | |
|
64 | 62 | location = get_object_or_404(Location, pk=id_loc) |
|
65 | 63 | |
|
66 | 64 | kwargs = {} |
|
67 | 65 | kwargs['location'] = location |
|
68 | 66 | kwargs['location_keys'] = ['name', 'description'] |
|
69 | 67 | |
|
70 | 68 | kwargs['title'] = 'Location' |
|
71 | 69 | kwargs['suptitle'] = 'Details' |
|
72 | 70 | |
|
73 | 71 | return render(request, 'location.html', kwargs) |
|
74 | 72 | |
|
75 | 73 | def location_new(request): |
|
76 | 74 | |
|
77 | 75 | if request.method == 'GET': |
|
78 | 76 | form = LocationForm() |
|
79 | 77 | |
|
80 | 78 | if request.method == 'POST': |
|
81 | 79 | form = LocationForm(request.POST) |
|
82 | 80 | |
|
83 | 81 | if form.is_valid(): |
|
84 | 82 | form.save() |
|
85 | 83 | return redirect('url_locations') |
|
86 | 84 | |
|
87 | 85 | kwargs = {} |
|
88 | 86 | kwargs['form'] = form |
|
89 | 87 | kwargs['title'] = 'Location' |
|
90 | 88 | kwargs['suptitle'] = 'New' |
|
91 | 89 | kwargs['button'] = 'Create' |
|
92 | 90 | |
|
93 | 91 | return render(request, 'location_edit.html', kwargs) |
|
94 | 92 | |
|
95 | 93 | def location_edit(request, id_loc): |
|
96 | 94 | |
|
97 | 95 | location = get_object_or_404(Location, pk=id_loc) |
|
98 | 96 | |
|
99 | 97 | if request.method=='GET': |
|
100 | 98 | form = LocationForm(instance=location) |
|
101 | 99 | |
|
102 | 100 | if request.method=='POST': |
|
103 | 101 | form = LocationForm(request.POST, instance=location) |
|
104 | 102 | |
|
105 | 103 | if form.is_valid(): |
|
106 | 104 | form.save() |
|
107 | 105 | return redirect('url_locations') |
|
108 | 106 | |
|
109 | 107 | kwargs = {} |
|
110 | 108 | kwargs['form'] = form |
|
111 | 109 | kwargs['title'] = 'Location' |
|
112 | 110 | kwargs['suptitle'] = 'Edit' |
|
113 | 111 | kwargs['button'] = 'Update' |
|
114 | 112 | |
|
115 | 113 | return render(request, 'location_edit.html', kwargs) |
|
116 | 114 | |
|
117 | 115 | def location_delete(request, id_loc): |
|
118 | 116 | |
|
119 | 117 | location = get_object_or_404(Location, pk=id_loc) |
|
120 | 118 | |
|
121 | 119 | if request.method=='POST': |
|
122 | 120 | |
|
123 | 121 | if request.user.is_staff: |
|
124 | 122 | location.delete() |
|
125 | 123 | return redirect('url_locations') |
|
126 | 124 | |
|
127 | 125 | return HttpResponse("Not enough permission to delete this object") |
|
128 | 126 | |
|
129 | 127 | kwargs = {'object':location, 'loc_active':'active', |
|
130 | 128 | 'url_cancel':'url_location', 'id_item':id_loc} |
|
131 | 129 | |
|
132 | 130 | return render(request, 'item_delete.html', kwargs) |
|
133 | 131 | |
|
134 | 132 | def devices(request): |
|
135 | 133 | |
|
136 | 134 | devices = Device.objects.all().order_by('device_type__name') |
|
137 | 135 | |
|
138 | 136 | # keys = ['id', 'device_type__name', 'name', 'ip_address'] |
|
139 | 137 | keys = ['id', 'name', 'ip_address', 'port_address', 'device_type'] |
|
140 | 138 | |
|
141 | 139 | kwargs = {} |
|
142 | 140 | kwargs['device_keys'] = keys[1:] |
|
143 | 141 | kwargs['devices'] = devices#.values(*keys) |
|
144 | 142 | kwargs['title'] = 'Device' |
|
145 | 143 | kwargs['suptitle'] = 'List' |
|
146 | 144 | kwargs['button'] = 'New Device' |
|
147 | 145 | |
|
148 | 146 | return render(request, 'devices.html', kwargs) |
|
149 | 147 | |
|
150 | 148 | def device(request, id_dev): |
|
151 | 149 | |
|
152 | 150 | device = get_object_or_404(Device, pk=id_dev) |
|
153 | 151 | |
|
154 | 152 | kwargs = {} |
|
155 | 153 | kwargs['device'] = device |
|
156 | 154 | kwargs['device_keys'] = ['device_type', 'name', 'ip_address', 'port_address', 'description'] |
|
157 | 155 | |
|
158 | 156 | kwargs['title'] = 'Device' |
|
159 | 157 | kwargs['suptitle'] = 'Details' |
|
160 | 158 | |
|
161 | 159 | return render(request, 'device.html', kwargs) |
|
162 | 160 | |
|
163 | 161 | def device_new(request): |
|
164 | 162 | |
|
165 | 163 | if request.method == 'GET': |
|
166 | 164 | form = DeviceForm() |
|
167 | 165 | |
|
168 | 166 | if request.method == 'POST': |
|
169 | 167 | form = DeviceForm(request.POST) |
|
170 | 168 | |
|
171 | 169 | if form.is_valid(): |
|
172 | 170 | form.save() |
|
173 | 171 | return redirect('url_devices') |
|
174 | 172 | |
|
175 | 173 | kwargs = {} |
|
176 | 174 | kwargs['form'] = form |
|
177 | 175 | kwargs['title'] = 'Device' |
|
178 | 176 | kwargs['suptitle'] = 'New' |
|
179 | 177 | kwargs['button'] = 'Create' |
|
180 | 178 | |
|
181 | 179 | return render(request, 'device_edit.html', kwargs) |
|
182 | 180 | |
|
183 | 181 | def device_edit(request, id_dev): |
|
184 | 182 | |
|
185 | 183 | device = get_object_or_404(Device, pk=id_dev) |
|
186 | 184 | |
|
187 | 185 | if request.method=='GET': |
|
188 | 186 | form = DeviceForm(instance=device) |
|
189 | 187 | |
|
190 | 188 | if request.method=='POST': |
|
191 | 189 | form = DeviceForm(request.POST, instance=device) |
|
192 | 190 | |
|
193 | 191 | if form.is_valid(): |
|
194 | 192 | form.save() |
|
195 | 193 | return redirect('url_devices') |
|
196 | 194 | |
|
197 | 195 | kwargs = {} |
|
198 | 196 | kwargs['form'] = form |
|
199 | 197 | kwargs['title'] = 'Device' |
|
200 | 198 | kwargs['suptitle'] = 'Edit' |
|
201 | 199 | kwargs['button'] = 'Update' |
|
202 | 200 | |
|
203 | 201 | return render(request, 'device_edit.html', kwargs) |
|
204 | 202 | |
|
205 | 203 | def device_delete(request, id_dev): |
|
206 | 204 | |
|
207 | 205 | device = get_object_or_404(Device, pk=id_dev) |
|
208 | 206 | |
|
209 | 207 | if request.method=='POST': |
|
210 | 208 | |
|
211 | 209 | if request.user.is_staff: |
|
212 | 210 | device.delete() |
|
213 | 211 | return redirect('url_devices') |
|
214 | 212 | |
|
215 | 213 | return HttpResponse("Not enough permission to delete this object") |
|
216 | 214 | |
|
217 | 215 | kwargs = {'object':device, 'dev_active':'active', |
|
218 | 216 | 'url_cancel':'url_device', 'id_item':id_dev} |
|
219 | 217 | |
|
220 | 218 | return render(request, 'item_delete.html', kwargs) |
|
221 | 219 | |
|
222 | 220 | def campaigns(request): |
|
223 | 221 | |
|
224 | 222 | campaigns = Campaign.objects.all().order_by('start_date') |
|
225 | 223 | |
|
226 | 224 | keys = ['id', 'name', 'start_date', 'end_date'] |
|
227 | 225 | |
|
228 | 226 | kwargs = {} |
|
229 | 227 | kwargs['campaign_keys'] = keys[1:] |
|
230 | 228 | kwargs['campaigns'] = campaigns#.values(*keys) |
|
231 | 229 | kwargs['title'] = 'Campaign' |
|
232 | 230 | kwargs['suptitle'] = 'List' |
|
233 | 231 | kwargs['button'] = 'New Campaign' |
|
234 | 232 | |
|
235 | 233 | return render(request, 'campaigns.html', kwargs) |
|
236 | 234 | |
|
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 = {} |
|
244 | 243 | kwargs['campaign'] = campaign |
|
245 | 244 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] |
|
246 | 245 | |
|
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' |
|
254 | 253 | |
|
255 | 254 | kwargs['form'] = form |
|
256 | 255 | kwargs['button'] = 'Add Experiment' |
|
257 | 256 | |
|
258 | 257 | return render(request, 'campaign.html', kwargs) |
|
259 | 258 | |
|
260 | 259 | def campaign_new(request): |
|
261 | 260 | |
|
262 | 261 | if request.method == 'GET': |
|
263 | 262 | form = CampaignForm() |
|
264 | 263 | |
|
265 | 264 | if request.method == 'POST': |
|
266 | 265 | form = CampaignForm(request.POST) |
|
267 | 266 | |
|
268 | 267 | if form.is_valid(): |
|
269 | 268 | campaign = form.save() |
|
270 | 269 | return redirect('url_campaign', id_camp=campaign.id) |
|
271 | 270 | |
|
272 | 271 | kwargs = {} |
|
273 | 272 | kwargs['form'] = form |
|
274 | 273 | kwargs['title'] = 'Campaign' |
|
275 | 274 | kwargs['suptitle'] = 'New' |
|
276 | 275 | kwargs['button'] = 'Create' |
|
277 | 276 | |
|
278 | 277 | return render(request, 'campaign_edit.html', kwargs) |
|
279 | 278 | |
|
280 | 279 | def campaign_edit(request, id_camp): |
|
281 | 280 | |
|
282 | 281 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
283 | 282 | |
|
284 | 283 | if request.method=='GET': |
|
285 | 284 | form = CampaignForm(instance=campaign) |
|
286 | 285 | |
|
287 | 286 | if request.method=='POST': |
|
288 | 287 | form = CampaignForm(request.POST, instance=campaign) |
|
289 | 288 | |
|
290 | 289 | if form.is_valid(): |
|
291 | 290 | form.save() |
|
292 | 291 | return redirect('url_campaign', id_camp=id_camp) |
|
293 | 292 | |
|
294 | 293 | kwargs = {} |
|
295 | 294 | kwargs['form'] = form |
|
296 | 295 | kwargs['title'] = 'Campaign' |
|
297 | 296 | kwargs['suptitle'] = 'Edit' |
|
298 | 297 | kwargs['button'] = 'Update' |
|
299 | 298 | |
|
300 | 299 | return render(request, 'campaign_edit.html', kwargs) |
|
301 | 300 | |
|
302 | 301 | def campaign_delete(request, id_camp): |
|
303 | 302 | |
|
304 | 303 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
305 | 304 | |
|
306 | 305 | if request.method=='POST': |
|
307 | 306 | if request.user.is_staff: |
|
308 | 307 | campaign.delete() |
|
309 | 308 | return redirect('url_campaigns') |
|
310 | 309 | |
|
311 | 310 | return HttpResponse("Not enough permission to delete this object") |
|
312 | 311 | |
|
313 | 312 | kwargs = {'object':campaign, 'camp_active':'active', |
|
314 | 313 | 'url_cancel':'url_campaign', 'id_item':id_camp} |
|
315 | 314 | |
|
316 | 315 | return render(request, 'item_delete.html', kwargs) |
|
317 | 316 | |
|
318 | 317 | def experiments(request): |
|
319 | 318 | |
|
320 | 319 | experiment_list = Experiment.objects.all().order_by('campaign') |
|
321 | 320 | |
|
322 | 321 | keys = ['id', 'name', 'start_time', 'end_time', 'campaign'] |
|
323 | 322 | |
|
324 | 323 | kwargs = {} |
|
325 | 324 | |
|
326 | 325 | kwargs['experiment_keys'] = keys[1:] |
|
327 | 326 | kwargs['experiments'] = experiment_list#.values(*keys) |
|
328 | 327 | |
|
329 | 328 | kwargs['title'] = 'Experiment' |
|
330 | 329 | kwargs['suptitle'] = 'List' |
|
331 | 330 | kwargs['button'] = 'New Experiment' |
|
332 | 331 | |
|
333 | 332 | return render(request, 'experiments.html', kwargs) |
|
334 | 333 | |
|
335 | 334 | def experiment(request, id_exp): |
|
336 | 335 | |
|
337 | 336 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
338 | 337 | |
|
339 | 338 | experiments = Experiment.objects.filter(campaign=experiment.campaign) |
|
340 | 339 | configurations = Configuration.objects.filter(experiment=experiment, type=0) |
|
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'] |
|
348 | 347 | |
|
349 | 348 | kwargs['experiment_keys'] = exp_keys[1:] |
|
350 | 349 | kwargs['experiment'] = experiment |
|
351 | 350 | |
|
352 | 351 | kwargs['experiments'] = experiments.values(*exp_keys) |
|
353 | 352 | |
|
354 | 353 | kwargs['configuration_labels'] = conf_labels[1:] |
|
355 | 354 | kwargs['configuration_keys'] = conf_keys[1:] |
|
356 | 355 | kwargs['configurations'] = configurations #.values(*conf_keys) |
|
357 | 356 | |
|
358 | 357 | kwargs['title'] = 'Experiment' |
|
359 | 358 | kwargs['suptitle'] = 'Details' |
|
360 | 359 | |
|
361 | 360 | kwargs['button'] = 'Add Configuration' |
|
362 | 361 | |
|
363 | 362 | return render(request, 'experiment.html', kwargs) |
|
364 | 363 | |
|
365 | 364 | def experiment_new(request, id_camp=0): |
|
366 | 365 | |
|
367 | 366 | if request.method == 'GET': |
|
368 | 367 | form = ExperimentForm(initial={'campaign':id_camp}) |
|
369 | 368 | |
|
370 | 369 | if request.method == 'POST': |
|
371 | 370 | form = ExperimentForm(request.POST, initial={'campaign':id_camp}) |
|
372 | 371 | |
|
373 | 372 | if form.is_valid(): |
|
374 | 373 | experiment = form.save() |
|
375 | 374 | return redirect('url_experiment', id_exp=experiment.id) |
|
376 | 375 | |
|
377 | 376 | kwargs = {} |
|
378 | 377 | kwargs['form'] = form |
|
379 | 378 | kwargs['title'] = 'Experiment' |
|
380 | 379 | kwargs['suptitle'] = 'New' |
|
381 | 380 | kwargs['button'] = 'Create' |
|
382 | 381 | |
|
383 | 382 | return render(request, 'experiment_edit.html', kwargs) |
|
384 | 383 | |
|
385 | 384 | def experiment_edit(request, id_exp): |
|
386 | 385 | |
|
387 | 386 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
388 | 387 | |
|
389 | 388 | if request.method == 'GET': |
|
390 | 389 | form = ExperimentForm(instance=experiment) |
|
391 | 390 | |
|
392 | 391 | if request.method=='POST': |
|
393 | 392 | form = ExperimentForm(request.POST, instance=experiment) |
|
394 | 393 | |
|
395 | 394 | if form.is_valid(): |
|
396 | 395 | experiment = form.save() |
|
397 | 396 | return redirect('url_experiment', id_exp=experiment.id) |
|
398 | 397 | |
|
399 | 398 | kwargs = {} |
|
400 | 399 | kwargs['form'] = form |
|
401 | 400 | kwargs['title'] = 'Experiment' |
|
402 | 401 | kwargs['suptitle'] = 'Edit' |
|
403 | 402 | kwargs['button'] = 'Update' |
|
404 | 403 | |
|
405 | 404 | return render(request, 'experiment_edit.html', kwargs) |
|
406 | 405 | |
|
407 | 406 | def experiment_delete(request, id_exp): |
|
408 | 407 | |
|
409 | 408 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
410 | 409 | |
|
411 | 410 | if request.method=='POST': |
|
412 | 411 | if request.user.is_staff: |
|
413 | 412 | id_camp = experiment.campaign.id |
|
414 | 413 | experiment.delete() |
|
415 | 414 | return redirect('url_campaign', id_camp=id_camp) |
|
416 | 415 | |
|
417 | 416 | return HttpResponse("Not enough permission to delete this object") |
|
418 | 417 | |
|
419 | 418 | kwargs = {'object':experiment, 'exp_active':'active', |
|
420 | 419 | 'url_cancel':'url_experiment', 'id_item':id_exp} |
|
421 | 420 | |
|
422 | 421 | return render(request, 'item_delete.html', kwargs) |
|
423 | 422 | |
|
424 | 423 | def dev_confs(request): |
|
425 | 424 | |
|
426 | 425 | configurations = Configuration.objects.all().order_by('type', 'device__device_type', 'experiment') |
|
427 | 426 | |
|
428 | 427 | # keys = ['id', 'device__device_type__name', 'device__name', 'experiment__campaign__name', 'experiment__name'] |
|
429 | 428 | |
|
430 | 429 | keys = ['id', 'device', 'experiment', 'type', 'programmed_date'] |
|
431 | 430 | |
|
432 | 431 | kwargs = {} |
|
433 | 432 | |
|
434 | 433 | kwargs['configuration_keys'] = keys[1:] |
|
435 | 434 | kwargs['configurations'] = configurations#.values(*keys) |
|
436 | 435 | |
|
437 | 436 | kwargs['title'] = 'Configuration' |
|
438 | 437 | kwargs['suptitle'] = 'List' |
|
439 | 438 | kwargs['button'] = 'New Configuration' |
|
440 | 439 | |
|
441 | 440 | return render(request, 'dev_confs.html', kwargs) |
|
442 | 441 | |
|
443 | 442 | def dev_conf(request, id_conf): |
|
444 | 443 | |
|
445 | 444 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
446 | 445 | |
|
447 | 446 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
448 | 447 | dev_conf = DevConfModel.objects.get(pk=id_conf) |
|
449 | 448 | |
|
450 | 449 | kwargs = {} |
|
451 | 450 | kwargs['dev_conf'] = dev_conf |
|
452 | 451 | kwargs['dev_conf_keys'] = ['name', 'experiment', 'device'] |
|
453 | 452 | |
|
454 | 453 | kwargs['title'] = 'Configuration' |
|
455 | 454 | kwargs['suptitle'] = 'Details' |
|
456 | 455 | |
|
457 | 456 | kwargs['button'] = 'Edit Configuration' |
|
458 | 457 | |
|
459 | 458 | ###### SIDEBAR ###### |
|
460 | 459 | kwargs.update(sidebar(conf)) |
|
461 | 460 | |
|
462 | 461 | return render(request, 'dev_conf.html', kwargs) |
|
463 | 462 | |
|
464 | 463 | def dev_conf_new(request, id_exp=0): |
|
465 | 464 | |
|
466 | 465 | if request.method == 'GET': |
|
467 | 466 | form = ConfigurationForm(initial={'experiment':id_exp}) |
|
468 | 467 | |
|
469 | 468 | if request.method == 'POST': |
|
470 | 469 | experiment = Experiment.objects.get(pk=request.POST['experiment']) |
|
471 | 470 | device = Device.objects.get(pk=request.POST['device']) |
|
472 | 471 | |
|
473 | 472 | DevConfForm = CONF_FORMS[device.device_type.name] |
|
474 | 473 | |
|
475 | 474 | form = DevConfForm(request.POST, initial={'experiment':experiment.id}) |
|
476 | 475 | |
|
477 | 476 | if form.is_valid(): |
|
478 | 477 | dev_conf = form.save() |
|
479 | 478 | |
|
480 | 479 | return redirect('url_experiment', id_exp=experiment.id) |
|
481 | 480 | |
|
482 | 481 | kwargs = {} |
|
483 | 482 | kwargs['form'] = form |
|
484 | 483 | kwargs['title'] = 'Configuration' |
|
485 | 484 | kwargs['suptitle'] = 'New' |
|
486 | 485 | kwargs['button'] = 'Create' |
|
487 | 486 | |
|
488 | 487 | return render(request, 'dev_conf_edit.html', kwargs) |
|
489 | 488 | |
|
490 | 489 | def dev_conf_edit(request, id_conf): |
|
491 | 490 | |
|
492 | 491 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
493 | 492 | |
|
494 | 493 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
495 | 494 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
496 | 495 | |
|
497 | 496 | dev_conf = DevConfModel.objects.get(pk=id_conf) |
|
498 | 497 | |
|
499 | 498 | if request.method=='GET': |
|
500 | 499 | form = DevConfForm(instance=dev_conf) |
|
501 | 500 | |
|
502 | 501 | if request.method=='POST': |
|
503 | 502 | form = DevConfForm(request.POST, instance=dev_conf) |
|
504 | 503 | |
|
505 | 504 | if form.is_valid(): |
|
506 | 505 | form.save() |
|
507 | 506 | return redirect('url_dev_conf', id_conf=id_conf) |
|
508 | 507 | |
|
509 | 508 | kwargs = {} |
|
510 | 509 | kwargs['form'] = form |
|
511 | 510 | kwargs['title'] = 'Device Configuration' |
|
512 | 511 | kwargs['suptitle'] = 'Edit' |
|
513 | 512 | kwargs['button'] = 'Update' |
|
514 | 513 | |
|
515 | 514 | ###### SIDEBAR ###### |
|
516 | 515 | kwargs.update(sidebar(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 | |
|
554 | 719 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
555 | 720 | |
|
556 | 721 | if request.method=='POST': |
|
557 | 722 | if request.user.is_staff: |
|
558 | 723 | id_exp = conf.experiment.id |
|
559 | 724 | conf.delete() |
|
560 | 725 | return redirect('url_experiment', id_exp=id_exp) |
|
561 | 726 | |
|
562 | 727 | return HttpResponse("Not enough permission to delete this object") |
|
563 | 728 | |
|
564 | 729 | kwargs = {'object':conf, 'conf_active':'active', |
|
565 | 730 | 'url_cancel':'url_dev_conf', 'id_item':id_conf} |
|
566 | 731 | |
|
567 | 732 | ###### SIDEBAR ###### |
|
568 | 733 | kwargs.update(sidebar(conf)) |
|
569 | 734 | |
|
570 | 735 | return render(request, 'item_delete.html', kwargs) |
|
571 | 736 | |
|
572 | 737 | def sidebar(conf): |
|
573 | 738 | |
|
574 | 739 | experiments = Experiment.objects.filter(campaign=conf.experiment.campaign) |
|
575 | 740 | configurations = Configuration.objects.filter(experiment=conf.experiment, type=0) |
|
576 | 741 | |
|
577 | 742 | exp_keys = ['id', 'campaign', 'name', 'start_time', 'end_time'] |
|
578 | 743 | conf_keys = ['id', 'device'] |
|
579 | 744 | |
|
580 | 745 | kwargs = {} |
|
581 | 746 | |
|
582 | 747 | kwargs['dev_conf'] = conf |
|
583 | 748 | |
|
584 | 749 | kwargs['experiment_keys'] = exp_keys[1:] |
|
585 | 750 | kwargs['experiments'] = experiments.values(*exp_keys) |
|
586 | 751 | |
|
587 | 752 | kwargs['configuration_keys'] = conf_keys[1:] |
|
588 | 753 | kwargs['configurations'] = configurations #.values(*conf_keys) |
|
589 | 754 | |
|
590 | 755 | return kwargs |
|
591 | 756 | |
|
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 |
|
617 | 784 | kwargs['campaign'] = campaign |
|
618 | 785 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] |
|
619 | 786 | #---Experimet |
|
620 | 787 | keys = ['id', 'name', 'start_time', 'end_time'] |
|
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