@@ -1,154 +1,155 | |||||
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 |
|
3 | |||
4 | from .models import DeviceType, Device, Experiment, Campaign, Configuration, Location |
|
4 | from .models import DeviceType, Device, Experiment, Campaign, Configuration, Location | |
5 |
|
5 | |||
6 | FILE_FORMAT = ( |
|
6 | FILE_FORMAT = ( | |
7 | ('json', 'json'), |
|
7 | ('json', 'json'), | |
8 | ) |
|
8 | ) | |
9 |
|
9 | |||
10 | DDS_FILE_FORMAT = ( |
|
10 | DDS_FILE_FORMAT = ( | |
11 | ('json', 'json'), |
|
11 | ('json', 'json'), | |
12 | ('text', 'dds') |
|
12 | ('text', 'dds') | |
13 | ) |
|
13 | ) | |
14 |
|
14 | |||
15 | RC_FILE_FORMAT = ( |
|
15 | RC_FILE_FORMAT = ( | |
16 | ('json', 'json'), |
|
16 | ('json', 'json'), | |
17 | ('text', 'racp'), |
|
17 | ('text', 'racp'), | |
18 | ('binary', 'dat'), |
|
18 | ('binary', 'dat'), | |
19 | ) |
|
19 | ) | |
20 |
|
20 | |||
21 | def add_empty_choice(choices, pos=0, label='-----'): |
|
21 | def add_empty_choice(choices, pos=0, label='-----'): | |
22 | if len(choices)>0: |
|
22 | if len(choices)>0: | |
23 | choices = list(choices) |
|
23 | choices = list(choices) | |
24 | choices.insert(0, (0, label)) |
|
24 | choices.insert(0, (0, label)) | |
25 | return choices |
|
25 | return choices | |
26 | else: |
|
26 | else: | |
27 | return [(0, label)] |
|
27 | return [(0, label)] | |
28 |
|
28 | |||
29 | class DatepickerWidget(forms.widgets.TextInput): |
|
29 | class DatepickerWidget(forms.widgets.TextInput): | |
30 | def render(self, name, value, attrs=None): |
|
30 | def render(self, name, value, attrs=None): | |
31 | input_html = super(DatepickerWidget, self).render(name, value, attrs) |
|
31 | input_html = super(DatepickerWidget, self).render(name, value, attrs) | |
32 | html = '<div class="input-group date">'+input_html+'<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span></div>' |
|
32 | html = '<div class="input-group date">'+input_html+'<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span></div>' | |
33 | return mark_safe(html) |
|
33 | return mark_safe(html) | |
34 |
|
34 | |||
35 | class TimepickerWidget(forms.widgets.TextInput): |
|
35 | class TimepickerWidget(forms.widgets.TextInput): | |
36 | def render(self, name, value, attrs=None): |
|
36 | def render(self, name, value, attrs=None): | |
37 | input_html = super(TimepickerWidget, self).render(name, value, attrs) |
|
37 | input_html = super(TimepickerWidget, self).render(name, value, attrs) | |
38 | html = '<div class="input-group time">'+input_html+'<span class="input-group-addon"><i class="glyphicon glyphicon-time"></i></span></div>' |
|
38 | html = '<div class="input-group time">'+input_html+'<span class="input-group-addon"><i class="glyphicon glyphicon-time"></i></span></div>' | |
39 | return mark_safe(html) |
|
39 | return mark_safe(html) | |
40 |
|
40 | |||
41 | class CampaignForm(forms.ModelForm): |
|
41 | class CampaignForm(forms.ModelForm): | |
42 |
|
42 | |||
43 | experiments = forms.ModelMultipleChoiceField(widget=forms.CheckboxSelectMultiple(), |
|
43 | experiments = forms.ModelMultipleChoiceField(widget=forms.CheckboxSelectMultiple(), | |
44 | queryset=Experiment.objects.filter(template=True), |
|
44 | queryset=Experiment.objects.filter(template=True), | |
45 | required=False) |
|
45 | required=False) | |
46 |
|
46 | |||
47 | def __init__(self, *args, **kwargs): |
|
47 | def __init__(self, *args, **kwargs): | |
48 | super(CampaignForm, self).__init__(*args, **kwargs) |
|
48 | super(CampaignForm, self).__init__(*args, **kwargs) | |
49 | self.fields['start_date'].widget = DatepickerWidget(self.fields['start_date'].widget.attrs) |
|
49 | self.fields['start_date'].widget = DatepickerWidget(self.fields['start_date'].widget.attrs) | |
50 | self.fields['end_date'].widget = DatepickerWidget(self.fields['end_date'].widget.attrs) |
|
50 | self.fields['end_date'].widget = DatepickerWidget(self.fields['end_date'].widget.attrs) | |
51 | self.fields['description'].widget.attrs = {'rows': 2} |
|
51 | self.fields['description'].widget.attrs = {'rows': 2} | |
52 |
|
52 | |||
53 | if self.instance: |
|
53 | if self.instance.pk: | |
54 | self.fields['experiments'].queryset |= self.instance.experiments.all() |
|
54 | self.fields['experiments'].queryset |= self.instance.experiments.all() | |
55 |
|
55 | |||
56 | class Meta: |
|
56 | class Meta: | |
57 | model = Campaign |
|
57 | model = Campaign | |
58 | exclude = [''] |
|
58 | exclude = [''] | |
|
59 | ||||
59 |
|
60 | |||
60 | class ExperimentForm(forms.ModelForm): |
|
61 | class ExperimentForm(forms.ModelForm): | |
61 |
|
62 | |||
62 | def __init__(self, *args, **kwargs): |
|
63 | def __init__(self, *args, **kwargs): | |
63 | super(ExperimentForm, self).__init__(*args, **kwargs) |
|
64 | super(ExperimentForm, self).__init__(*args, **kwargs) | |
64 | self.fields['start_time'].widget = TimepickerWidget(self.fields['start_time'].widget.attrs) |
|
65 | self.fields['start_time'].widget = TimepickerWidget(self.fields['start_time'].widget.attrs) | |
65 | self.fields['end_time'].widget = TimepickerWidget(self.fields['end_time'].widget.attrs) |
|
66 | self.fields['end_time'].widget = TimepickerWidget(self.fields['end_time'].widget.attrs) | |
66 |
|
67 | |||
67 | class Meta: |
|
68 | class Meta: | |
68 | model = Experiment |
|
69 | model = Experiment | |
69 | exclude = ['status'] |
|
70 | exclude = ['status'] | |
70 |
|
71 | |||
71 | class LocationForm(forms.ModelForm): |
|
72 | class LocationForm(forms.ModelForm): | |
72 | class Meta: |
|
73 | class Meta: | |
73 | model = Location |
|
74 | model = Location | |
74 | exclude = [''] |
|
75 | exclude = [''] | |
75 |
|
76 | |||
76 | class DeviceForm(forms.ModelForm): |
|
77 | class DeviceForm(forms.ModelForm): | |
77 | class Meta: |
|
78 | class Meta: | |
78 | model = Device |
|
79 | model = Device | |
79 | exclude = ['status'] |
|
80 | exclude = ['status'] | |
80 |
|
81 | |||
81 | class ConfigurationForm(forms.ModelForm): |
|
82 | class ConfigurationForm(forms.ModelForm): | |
82 |
|
83 | |||
83 | def __init__(self, *args, **kwargs): |
|
84 | def __init__(self, *args, **kwargs): | |
84 | super(ConfigurationForm, self).__init__(*args, **kwargs) |
|
85 | super(ConfigurationForm, self).__init__(*args, **kwargs) | |
85 |
|
86 | |||
86 | if 'initial' in kwargs and 'experiment' in kwargs['initial'] and kwargs['initial']['experiment'] not in (0, '0'): |
|
87 | if 'initial' in kwargs and 'experiment' in kwargs['initial'] and kwargs['initial']['experiment'] not in (0, '0'): | |
87 | self.fields['experiment'].widget.attrs['disabled'] = 'disabled' |
|
88 | self.fields['experiment'].widget.attrs['disabled'] = 'disabled' | |
88 |
|
89 | |||
89 | class Meta: |
|
90 | class Meta: | |
90 | model = Configuration |
|
91 | model = Configuration | |
91 | exclude = ['type', 'created_date', 'programmed_date', 'parameters'] |
|
92 | exclude = ['type', 'created_date', 'programmed_date', 'parameters'] | |
92 |
|
93 | |||
93 | class DeviceTypeForm(forms.Form): |
|
94 | class DeviceTypeForm(forms.Form): | |
94 | device_type = forms.ChoiceField(choices=add_empty_choice(DeviceType.objects.all().order_by('name').values_list('id', 'name'))) |
|
95 | device_type = forms.ChoiceField(choices=add_empty_choice(DeviceType.objects.all().order_by('name').values_list('id', 'name'))) | |
95 |
|
96 | |||
96 |
|
97 | |||
97 | class UploadFileForm(forms.Form): |
|
98 | class UploadFileForm(forms.Form): | |
98 |
|
99 | |||
99 | file = forms.FileField() |
|
100 | file = forms.FileField() | |
100 |
|
101 | |||
101 | class DownloadFileForm(forms.Form): |
|
102 | class DownloadFileForm(forms.Form): | |
102 |
|
103 | |||
103 | format = forms.ChoiceField(choices= ((0, 'json'),) ) |
|
104 | format = forms.ChoiceField(choices= ((0, 'json'),) ) | |
104 |
|
105 | |||
105 | def __init__(self, device_type, *args, **kwargs): |
|
106 | def __init__(self, device_type, *args, **kwargs): | |
106 |
|
107 | |||
107 | super(DownloadFileForm, self).__init__(*args, **kwargs) |
|
108 | super(DownloadFileForm, self).__init__(*args, **kwargs) | |
108 |
|
109 | |||
109 | self.fields['format'].choices = FILE_FORMAT |
|
110 | self.fields['format'].choices = FILE_FORMAT | |
110 |
|
111 | |||
111 | if device_type == 'dds': |
|
112 | if device_type == 'dds': | |
112 | self.fields['format'].choices = DDS_FILE_FORMAT |
|
113 | self.fields['format'].choices = DDS_FILE_FORMAT | |
113 |
|
114 | |||
114 | if device_type == 'rc': |
|
115 | if device_type == 'rc': | |
115 | self.fields['format'].choices = RC_FILE_FORMAT |
|
116 | self.fields['format'].choices = RC_FILE_FORMAT | |
116 |
|
117 | |||
117 | class OperationForm(forms.Form): |
|
118 | class OperationForm(forms.Form): | |
118 | # today = datetime.today() |
|
119 | # today = datetime.today() | |
119 | # -----Campaigns from this month------[:5] |
|
120 | # -----Campaigns from this month------[:5] | |
120 | campaign = forms.ChoiceField(label="Campaign") |
|
121 | campaign = forms.ChoiceField(label="Campaign") | |
121 |
|
122 | |||
122 | def __init__(self, *args, **kwargs): |
|
123 | def __init__(self, *args, **kwargs): | |
123 |
|
124 | |||
124 | if 'length' not in kwargs.keys(): |
|
125 | if 'length' not in kwargs.keys(): | |
125 | length = None |
|
126 | length = None | |
126 | else: |
|
127 | else: | |
127 | length = kwargs['length'] |
|
128 | length = kwargs['length'] | |
128 |
|
129 | |||
129 | kwargs.pop('length') |
|
130 | kwargs.pop('length') | |
130 |
|
131 | |||
131 | super(OperationForm, self).__init__(*args, **kwargs) |
|
132 | super(OperationForm, self).__init__(*args, **kwargs) | |
132 | self.fields['campaign'].choices=Campaign.objects.all().order_by('-start_date').values_list('id', 'name')[:length] |
|
133 | self.fields['campaign'].choices=Campaign.objects.all().order_by('-start_date').values_list('id', 'name')[:length] | |
133 |
|
134 | |||
134 | class OperationSearchForm(forms.Form): |
|
135 | class OperationSearchForm(forms.Form): | |
135 | # -----ALL Campaigns------ |
|
136 | # -----ALL Campaigns------ | |
136 | campaign = forms.ChoiceField(label="Campaign") |
|
137 | campaign = forms.ChoiceField(label="Campaign") | |
137 |
|
138 | |||
138 | def __init__(self, *args, **kwargs): |
|
139 | def __init__(self, *args, **kwargs): | |
139 | super(OperationSearchForm, self).__init__(*args, **kwargs) |
|
140 | super(OperationSearchForm, self).__init__(*args, **kwargs) | |
140 | self.fields['campaign'].choices=Campaign.objects.all().order_by('-start_date').values_list('id', 'name') |
|
141 | self.fields['campaign'].choices=Campaign.objects.all().order_by('-start_date').values_list('id', 'name') | |
141 |
|
142 | |||
142 | class NewForm(forms.Form): |
|
143 | class NewForm(forms.Form): | |
143 |
|
144 | |||
144 | create_from = forms.ChoiceField(choices=((0, '-----'), |
|
145 | create_from = forms.ChoiceField(choices=((0, '-----'), | |
145 | (1, 'Empty (blank)'), |
|
146 | (1, 'Empty (blank)'), | |
146 | (2, 'Template'))) |
|
147 | (2, 'Template'))) | |
147 | choose_template = forms.ChoiceField() |
|
148 | choose_template = forms.ChoiceField() | |
148 |
|
149 | |||
149 | def __init__(self, *args, **kwargs): |
|
150 | def __init__(self, *args, **kwargs): | |
150 |
|
151 | |||
151 | template_choices = kwargs.pop('template_choices', []) |
|
152 | template_choices = kwargs.pop('template_choices', []) | |
152 | super(NewForm, self).__init__(*args, **kwargs) |
|
153 | super(NewForm, self).__init__(*args, **kwargs) | |
153 | self.fields['choose_template'].choices = add_empty_choice(template_choices) |
|
154 | self.fields['choose_template'].choices = add_empty_choice(template_choices) | |
154 | No newline at end of file |
|
155 |
@@ -1,452 +1,449 | |||||
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 datetime import datetime |
|
2 | from datetime import datetime | |
3 |
|
3 | |||
4 | from django.db import models |
|
4 | from django.db import models | |
5 | from polymorphic import PolymorphicModel |
|
5 | from polymorphic import PolymorphicModel | |
6 |
|
6 | |||
7 | from django.core.urlresolvers import reverse |
|
7 | from django.core.urlresolvers import reverse | |
8 |
|
8 | |||
9 | CONF_STATES = ( |
|
9 | CONF_STATES = ( | |
10 | (0, 'Disconnected'), |
|
10 | (0, 'Disconnected'), | |
11 | (1, 'Connected'), |
|
11 | (1, 'Connected'), | |
12 | (2, 'Running'), |
|
12 | (2, 'Running'), | |
13 | ) |
|
13 | ) | |
14 |
|
14 | |||
15 | EXP_STATES = ( |
|
15 | EXP_STATES = ( | |
16 | (0,'Error'), #RED |
|
16 | (0,'Error'), #RED | |
17 | (1,'Configurated'), #BLUE |
|
17 | (1,'Configurated'), #BLUE | |
18 | (2,'Running'), #GREEN |
|
18 | (2,'Running'), #GREEN | |
19 | (3,'Waiting'), #YELLOW |
|
19 | (3,'Waiting'), #YELLOW | |
20 | (4,'Not Configured'), #WHITE |
|
20 | (4,'Not Configured'), #WHITE | |
21 | ) |
|
21 | ) | |
22 |
|
22 | |||
23 | CONF_TYPES = ( |
|
23 | CONF_TYPES = ( | |
24 | (0, 'Active'), |
|
24 | (0, 'Active'), | |
25 | (1, 'Historical'), |
|
25 | (1, 'Historical'), | |
26 | ) |
|
26 | ) | |
27 |
|
27 | |||
28 | DEV_STATES = ( |
|
28 | DEV_STATES = ( | |
29 | (0, 'No connected'), |
|
29 | (0, 'No connected'), | |
30 | (1, 'Connected'), |
|
30 | (1, 'Connected'), | |
31 | (2, 'Configured'), |
|
31 | (2, 'Configured'), | |
32 | (3, 'Running'), |
|
32 | (3, 'Running'), | |
33 | ) |
|
33 | ) | |
34 |
|
34 | |||
35 | DEV_TYPES = ( |
|
35 | DEV_TYPES = ( | |
36 | ('', 'Select a device type'), |
|
36 | ('', 'Select a device type'), | |
37 | ('rc', 'Radar Controller'), |
|
37 | ('rc', 'Radar Controller'), | |
|
38 | ('rc_mix', 'Radar Controller (Mix)'), | |||
38 | ('dds', 'Direct Digital Synthesizer'), |
|
39 | ('dds', 'Direct Digital Synthesizer'), | |
39 | ('jars', 'Jicamarca Radar Acquisition System'), |
|
40 | ('jars', 'Jicamarca Radar Acquisition System'), | |
40 | ('usrp', 'Universal Software Radio Peripheral'), |
|
41 | ('usrp', 'Universal Software Radio Peripheral'), | |
41 | ('cgs', 'Clock Generator System'), |
|
42 | ('cgs', 'Clock Generator System'), | |
42 | ('abs', 'Automatic Beam Switching'), |
|
43 | ('abs', 'Automatic Beam Switching'), | |
43 | ) |
|
44 | ) | |
44 |
|
45 | |||
45 | DEV_PORTS = { |
|
46 | DEV_PORTS = { | |
46 | 'rc' : 2000, |
|
47 | 'rc' : 2000, | |
|
48 | 'rc_mix': 2000, | |||
47 | 'dds' : 2000, |
|
49 | 'dds' : 2000, | |
48 | 'jars' : 2000, |
|
50 | 'jars' : 2000, | |
49 | 'usrp' : 2000, |
|
51 | 'usrp' : 2000, | |
50 | 'cgs' : 8080, |
|
52 | 'cgs' : 8080, | |
51 | 'abs' : 8080 |
|
53 | 'abs' : 8080 | |
52 | } |
|
54 | } | |
53 |
|
55 | |||
54 | RADAR_STATES = ( |
|
56 | RADAR_STATES = ( | |
55 | (0, 'No connected'), |
|
57 | (0, 'No connected'), | |
56 | (1, 'Connected'), |
|
58 | (1, 'Connected'), | |
57 | (2, 'Configured'), |
|
59 | (2, 'Configured'), | |
58 | (3, 'Running'), |
|
60 | (3, 'Running'), | |
59 | (4, 'Scheduled'), |
|
61 | (4, 'Scheduled'), | |
60 | ) |
|
62 | ) | |
61 | # Create your models here. |
|
63 | # Create your models here. | |
62 |
|
64 | |||
63 | class Location(models.Model): |
|
65 | class Location(models.Model): | |
64 |
|
66 | |||
65 | name = models.CharField(max_length = 30) |
|
67 | name = models.CharField(max_length = 30) | |
66 | description = models.TextField(blank=True, null=True) |
|
68 | description = models.TextField(blank=True, null=True) | |
67 |
|
69 | |||
68 | class Meta: |
|
70 | class Meta: | |
69 | db_table = 'db_location' |
|
71 | db_table = 'db_location' | |
70 |
|
72 | |||
71 | def __unicode__(self): |
|
73 | def __unicode__(self): | |
72 | return u'%s' % self.name |
|
74 | return u'%s' % self.name | |
73 |
|
75 | |||
74 | def get_absolute_url(self): |
|
76 | def get_absolute_url(self): | |
75 | return reverse('url_device', args=[str(self.id)]) |
|
77 | return reverse('url_device', args=[str(self.id)]) | |
76 |
|
78 | |||
77 |
|
79 | |||
78 | class DeviceType(models.Model): |
|
80 | class DeviceType(models.Model): | |
79 |
|
81 | |||
80 | name = models.CharField(max_length = 10, choices = DEV_TYPES, default = 'rc') |
|
82 | name = models.CharField(max_length = 10, choices = DEV_TYPES, default = 'rc') | |
81 | description = models.TextField(blank=True, null=True) |
|
83 | description = models.TextField(blank=True, null=True) | |
82 |
|
84 | |||
83 | class Meta: |
|
85 | class Meta: | |
84 | db_table = 'db_device_types' |
|
86 | db_table = 'db_device_types' | |
85 |
|
87 | |||
86 | def __unicode__(self): |
|
88 | def __unicode__(self): | |
87 | return u'%s' % self.get_name_display() |
|
89 | return u'%s' % self.get_name_display() | |
88 |
|
90 | |||
89 | class Device(models.Model): |
|
91 | class Device(models.Model): | |
90 |
|
92 | |||
91 | device_type = models.ForeignKey(DeviceType, on_delete=models.CASCADE) |
|
93 | device_type = models.ForeignKey(DeviceType, on_delete=models.CASCADE) | |
92 | location = models.ForeignKey(Location, on_delete=models.CASCADE) |
|
94 | location = models.ForeignKey(Location, on_delete=models.CASCADE) | |
93 |
|
95 | |||
94 | name = models.CharField(max_length=40, default='') |
|
96 | name = models.CharField(max_length=40, default='') | |
95 | ip_address = models.GenericIPAddressField(protocol='IPv4', default='0.0.0.0') |
|
97 | ip_address = models.GenericIPAddressField(protocol='IPv4', default='0.0.0.0') | |
96 | port_address = models.PositiveSmallIntegerField(default=2000) |
|
98 | port_address = models.PositiveSmallIntegerField(default=2000) | |
97 | description = models.TextField(blank=True, null=True) |
|
99 | description = models.TextField(blank=True, null=True) | |
98 | status = models.PositiveSmallIntegerField(default=0, choices=DEV_STATES) |
|
100 | status = models.PositiveSmallIntegerField(default=0, choices=DEV_STATES) | |
99 |
|
101 | |||
100 | class Meta: |
|
102 | class Meta: | |
101 | db_table = 'db_devices' |
|
103 | db_table = 'db_devices' | |
102 |
|
104 | |||
103 | def __unicode__(self): |
|
105 | def __unicode__(self): | |
104 | return u'%s | %s' % (self.name, self.ip_address) |
|
106 | return u'%s | %s' % (self.name, self.ip_address) | |
105 |
|
107 | |||
106 | def get_status(self): |
|
108 | def get_status(self): | |
107 | return self.status |
|
109 | return self.status | |
108 |
|
110 | |||
109 | def get_absolute_url(self): |
|
111 | def get_absolute_url(self): | |
110 | return reverse('url_device', args=[str(self.id)]) |
|
112 | return reverse('url_device', args=[str(self.id)]) | |
111 |
|
113 | |||
112 |
|
114 | |||
113 | class Campaign(models.Model): |
|
115 | class Campaign(models.Model): | |
114 |
|
116 | |||
115 | template = models.BooleanField(default=False) |
|
117 | template = models.BooleanField(default=False) | |
116 | name = models.CharField(max_length=60, unique=True) |
|
118 | name = models.CharField(max_length=60, unique=True) | |
117 | start_date = models.DateTimeField(blank=True, null=True) |
|
119 | start_date = models.DateTimeField(blank=True, null=True) | |
118 | end_date = models.DateTimeField(blank=True, null=True) |
|
120 | end_date = models.DateTimeField(blank=True, null=True) | |
119 | tags = models.CharField(max_length=40) |
|
121 | tags = models.CharField(max_length=40) | |
120 | description = models.TextField(blank=True, null=True) |
|
122 | description = models.TextField(blank=True, null=True) | |
121 | experiments = models.ManyToManyField('Experiment', blank=True) |
|
123 | experiments = models.ManyToManyField('Experiment', blank=True) | |
122 |
|
124 | |||
123 | class Meta: |
|
125 | class Meta: | |
124 | db_table = 'db_campaigns' |
|
126 | db_table = 'db_campaigns' | |
125 | ordering = ('name',) |
|
127 | ordering = ('name',) | |
126 |
|
128 | |||
127 | def __unicode__(self): |
|
129 | def __unicode__(self): | |
128 | return u'%s' % (self.name) |
|
130 | return u'%s' % (self.name) | |
129 |
|
131 | |||
130 | def get_absolute_url(self): |
|
132 | def get_absolute_url(self): | |
131 | return reverse('url_campaign', args=[str(self.id)]) |
|
133 | return reverse('url_campaign', args=[str(self.id)]) | |
132 |
|
134 | |||
133 | def parms_to_dict(self): |
|
135 | def parms_to_dict(self): | |
134 |
|
136 | |||
135 | import json |
|
137 | import json | |
136 |
|
138 | |||
137 | parameters = {} |
|
139 | parameters = {} | |
138 | exp_parameters = {} |
|
140 | exp_parameters = {} | |
139 | experiments = Experiment.objects.filter(campaign = self) |
|
141 | experiments = Experiment.objects.filter(campaign = self) | |
140 |
|
142 | |||
141 | i=1 |
|
143 | i=1 | |
142 | for experiment in experiments: |
|
144 | for experiment in experiments: | |
143 | exp_parameters['experiment-'+str(i)] = json.loads(experiment.parms_to_dict()) |
|
145 | exp_parameters['experiment-'+str(i)] = json.loads(experiment.parms_to_dict()) | |
144 | i += 1 |
|
146 | i += 1 | |
145 |
|
147 | |||
146 |
|
148 | |||
147 | parameters['experimets'] =exp_parameters |
|
149 | parameters['experimets'] =exp_parameters | |
148 | parameters['end_date'] = self.end_date.strftime("%Y-%m-%d") |
|
150 | parameters['end_date'] = self.end_date.strftime("%Y-%m-%d") | |
149 | parameters['start_date'] = self.start_date.strftime("%Y-%m-%d") |
|
151 | parameters['start_date'] = self.start_date.strftime("%Y-%m-%d") | |
150 | parameters['campaign'] = self.__unicode__() |
|
152 | parameters['campaign'] = self.__unicode__() | |
151 |
|
153 | |||
152 | parameters = json.dumps(parameters, indent=2, sort_keys=False) |
|
154 | parameters = json.dumps(parameters, indent=2, sort_keys=False) | |
153 |
|
155 | |||
154 | return parameters |
|
156 | return parameters | |
155 |
|
157 | |||
156 | def get_absolute_url_export(self): |
|
158 | def get_absolute_url_export(self): | |
157 | return reverse('url_export_campaign', args=[str(self.id)]) |
|
159 | return reverse('url_export_campaign', args=[str(self.id)]) | |
158 |
|
160 | |||
159 |
|
161 | |||
160 |
|
162 | |||
161 | class RunningExperiment(models.Model): |
|
163 | class RunningExperiment(models.Model): | |
162 | radar = models.OneToOneField('Location', on_delete=models.CASCADE) |
|
164 | radar = models.OneToOneField('Location', on_delete=models.CASCADE) | |
163 | running_experiment = models.ManyToManyField('Experiment', blank = True) |
|
165 | running_experiment = models.ManyToManyField('Experiment', blank = True) | |
164 | status = models.PositiveSmallIntegerField(default=0, choices=RADAR_STATES) |
|
166 | status = models.PositiveSmallIntegerField(default=0, choices=RADAR_STATES) | |
165 |
|
167 | |||
166 |
|
168 | |||
167 | class Experiment(models.Model): |
|
169 | class Experiment(models.Model): | |
168 |
|
170 | |||
169 | template = models.BooleanField(default=False) |
|
171 | template = models.BooleanField(default=False) | |
170 | location = models.ForeignKey('Location', null=True, blank=True, on_delete=models.CASCADE) |
|
172 | location = models.ForeignKey('Location', null=True, blank=True, on_delete=models.CASCADE) | |
171 | name = models.CharField(max_length=40, default='', unique=True) |
|
173 | name = models.CharField(max_length=40, default='', unique=True) | |
172 | location = models.ForeignKey('Location', null=True, blank=True, on_delete=models.CASCADE) |
|
174 | location = models.ForeignKey('Location', null=True, blank=True, on_delete=models.CASCADE) | |
173 | start_time = models.TimeField(default='00:00:00') |
|
175 | start_time = models.TimeField(default='00:00:00') | |
174 | end_time = models.TimeField(default='23:59:59') |
|
176 | end_time = models.TimeField(default='23:59:59') | |
175 | status = models.PositiveSmallIntegerField(default=0, choices=EXP_STATES) |
|
177 | status = models.PositiveSmallIntegerField(default=0, choices=EXP_STATES) | |
176 |
|
178 | |||
177 | class Meta: |
|
179 | class Meta: | |
178 | db_table = 'db_experiments' |
|
180 | db_table = 'db_experiments' | |
179 | ordering = ('template', 'name') |
|
181 | ordering = ('template', 'name') | |
180 |
|
182 | |||
181 | def __unicode__(self): |
|
183 | def __unicode__(self): | |
182 | if self.template: |
|
184 | if self.template: | |
183 | return u'%s (template)' % (self.name) |
|
185 | return u'%s (template)' % (self.name) | |
184 | else: |
|
186 | else: | |
185 | return u'%s' % (self.name) |
|
187 | return u'%s' % (self.name) | |
186 |
|
188 | |||
187 | @property |
|
189 | @property | |
188 | def radar(self): |
|
190 | def radar(self): | |
189 | return self.location |
|
191 | return self.location | |
190 |
|
192 | |||
191 | def clone(self, **kwargs): |
|
193 | def clone(self, **kwargs): | |
192 |
|
194 | |||
193 | confs = Configuration.objects.filter(experiment=self, type=0) |
|
195 | confs = Configuration.objects.filter(experiment=self, type=0) | |
194 | self.pk = None |
|
196 | self.pk = None | |
195 | self.name = '{} [{:%Y/%m/%d}]'.format(self.name, datetime.now()) |
|
197 | self.name = '{} [{:%Y/%m/%d}]'.format(self.name, datetime.now()) | |
196 | for attr, value in kwargs.items(): |
|
198 | for attr, value in kwargs.items(): | |
197 | setattr(self, attr, value) |
|
199 | setattr(self, attr, value) | |
198 |
|
200 | |||
199 | self.save() |
|
201 | self.save() | |
200 |
|
202 | |||
201 | for conf in confs: |
|
203 | for conf in confs: | |
202 | conf.clone(experiment=self, template=False) |
|
204 | conf.clone(experiment=self, template=False) | |
203 |
|
205 | |||
204 | return self |
|
206 | return self | |
205 |
|
207 | |||
206 | def get_status(self): |
|
208 | def get_status(self): | |
207 | configurations = Configuration.objects.filter(experiment=self) |
|
209 | configurations = Configuration.objects.filter(experiment=self) | |
208 | exp_status=[] |
|
210 | exp_status=[] | |
209 | for conf in configurations: |
|
211 | for conf in configurations: | |
210 | print conf.status_device() |
|
212 | print conf.status_device() | |
211 | exp_status.append(conf.status_device()) |
|
213 | exp_status.append(conf.status_device()) | |
212 |
|
214 | |||
213 | if not exp_status: #No Configuration |
|
215 | if not exp_status: #No Configuration | |
214 | self.status = 4 |
|
216 | self.status = 4 | |
215 | self.save() |
|
217 | self.save() | |
216 | return |
|
218 | return | |
217 |
|
219 | |||
218 | total = 1 |
|
220 | total = 1 | |
219 | for e_s in exp_status: |
|
221 | for e_s in exp_status: | |
220 | total = total*e_s |
|
222 | total = total*e_s | |
221 |
|
223 | |||
222 | if total == 0: #Error |
|
224 | if total == 0: #Error | |
223 | status = 0 |
|
225 | status = 0 | |
224 | elif total == (3**len(exp_status)): #Running |
|
226 | elif total == (3**len(exp_status)): #Running | |
225 | status = 2 |
|
227 | status = 2 | |
226 | else: |
|
228 | else: | |
227 | status = 1 #Configurated |
|
229 | status = 1 #Configurated | |
228 |
|
230 | |||
229 | self.status = status |
|
231 | self.status = status | |
230 | self.save() |
|
232 | self.save() | |
231 |
|
233 | |||
232 | def status_color(self): |
|
234 | def status_color(self): | |
233 | color = 'danger' |
|
235 | color = 'danger' | |
234 | if self.status == 0: |
|
236 | if self.status == 0: | |
235 | color = "danger" |
|
237 | color = "danger" | |
236 | elif self.status == 1: |
|
238 | elif self.status == 1: | |
237 | color = "info" |
|
239 | color = "info" | |
238 | elif self.status == 2: |
|
240 | elif self.status == 2: | |
239 | color = "success" |
|
241 | color = "success" | |
240 | elif self.status == 3: |
|
242 | elif self.status == 3: | |
241 | color = "warning" |
|
243 | color = "warning" | |
242 | else: |
|
244 | else: | |
243 | color = "muted" |
|
245 | color = "muted" | |
244 |
|
246 | |||
245 | return color |
|
247 | return color | |
246 |
|
248 | |||
247 | def get_absolute_url(self): |
|
249 | def get_absolute_url(self): | |
248 | return reverse('url_experiment', args=[str(self.id)]) |
|
250 | return reverse('url_experiment', args=[str(self.id)]) | |
249 |
|
251 | |||
250 | def parms_to_dict(self): |
|
252 | def parms_to_dict(self): | |
251 |
|
253 | |||
252 | import json |
|
254 | import json | |
253 |
|
255 | |||
254 | configurations = Configuration.objects.filter(experiment=self) |
|
256 | configurations = Configuration.objects.filter(experiment=self) | |
255 | conf_parameters = {} |
|
257 | conf_parameters = {} | |
256 | parameters={} |
|
258 | parameters={} | |
257 |
|
259 | |||
258 | for configuration in configurations: |
|
260 | for configuration in configurations: | |
259 | if 'cgs' in configuration.device.device_type.name: |
|
261 | if 'cgs' in configuration.device.device_type.name: | |
260 | conf_parameters['cgs'] = configuration.parms_to_dict() |
|
262 | conf_parameters['cgs'] = configuration.parms_to_dict() | |
261 | if 'dds' in configuration.device.device_type.name: |
|
263 | if 'dds' in configuration.device.device_type.name: | |
262 | conf_parameters['dds'] = configuration.parms_to_dict() |
|
264 | conf_parameters['dds'] = configuration.parms_to_dict() | |
263 | if 'rc' in configuration.device.device_type.name: |
|
265 | if 'rc' in configuration.device.device_type.name: | |
264 | conf_parameters['rc'] = configuration.parms_to_dict() |
|
266 | conf_parameters['rc'] = configuration.parms_to_dict() | |
265 | if 'jars' in configuration.device.device_type.name: |
|
267 | if 'jars' in configuration.device.device_type.name: | |
266 | conf_parameters['jars'] = configuration.parms_to_dict() |
|
268 | conf_parameters['jars'] = configuration.parms_to_dict() | |
267 | if 'usrp' in configuration.device.device_type.name: |
|
269 | if 'usrp' in configuration.device.device_type.name: | |
268 | conf_parameters['usrp'] = configuration.parms_to_dict() |
|
270 | conf_parameters['usrp'] = configuration.parms_to_dict() | |
269 | if 'abs' in configuration.device.device_type.name: |
|
271 | if 'abs' in configuration.device.device_type.name: | |
270 | conf_parameters['abs'] = configuration.parms_to_dict() |
|
272 | conf_parameters['abs'] = configuration.parms_to_dict() | |
271 |
|
273 | |||
272 | parameters['configurations'] = conf_parameters |
|
274 | parameters['configurations'] = conf_parameters | |
273 | parameters['end_time'] = self.end_time.strftime("%Y-%m-%d") |
|
275 | parameters['end_time'] = self.end_time.strftime("%Y-%m-%d") | |
274 | parameters['start_time'] = self.start_time.strftime("%Y-%m-%d") |
|
276 | parameters['start_time'] = self.start_time.strftime("%Y-%m-%d") | |
275 | parameters['radar'] = self.radar.name |
|
277 | parameters['radar'] = self.radar.name | |
276 | parameters['experiment'] = self.name |
|
278 | parameters['experiment'] = self.name | |
277 | parameters = json.dumps(parameters, indent=2) |
|
279 | parameters = json.dumps(parameters, indent=2) | |
278 | #parameters = json.dumps(parameters) |
|
280 | #parameters = json.dumps(parameters) | |
279 |
|
281 | |||
280 | return parameters |
|
282 | return parameters | |
281 |
|
283 | |||
282 | def get_absolute_url_export(self): |
|
284 | def get_absolute_url_export(self): | |
283 | return reverse('url_export_experiment', args=[str(self.id)]) |
|
285 | return reverse('url_export_experiment', args=[str(self.id)]) | |
284 |
|
286 | |||
285 |
|
287 | |||
286 | class Configuration(PolymorphicModel): |
|
288 | class Configuration(PolymorphicModel): | |
287 |
|
289 | |||
288 | template = models.BooleanField(default=False) |
|
290 | template = models.BooleanField(default=False) | |
289 |
|
291 | |||
290 | name = models.CharField(verbose_name="Configuration Name", max_length=40, default='') |
|
292 | name = models.CharField(verbose_name="Configuration Name", max_length=40, default='') | |
291 |
|
293 | |||
292 | experiment = models.ForeignKey('Experiment', null=True, blank=True, on_delete=models.CASCADE) |
|
294 | experiment = models.ForeignKey('Experiment', null=True, blank=True, on_delete=models.CASCADE) | |
293 | device = models.ForeignKey(Device, on_delete=models.CASCADE) |
|
295 | device = models.ForeignKey(Device, null=True, on_delete=models.CASCADE) | |
294 |
|
296 | |||
295 | type = models.PositiveSmallIntegerField(default=0, choices=CONF_TYPES) |
|
297 | type = models.PositiveSmallIntegerField(default=0, choices=CONF_TYPES) | |
296 |
|
298 | |||
297 | created_date = models.DateTimeField(auto_now_add=True) |
|
299 | created_date = models.DateTimeField(auto_now_add=True) | |
298 | programmed_date = models.DateTimeField(auto_now=True) |
|
300 | programmed_date = models.DateTimeField(auto_now=True) | |
299 |
|
301 | |||
300 | parameters = models.TextField(default='{}') |
|
302 | parameters = models.TextField(default='{}') | |
301 |
|
303 | |||
302 | message = "" |
|
304 | message = "" | |
303 |
|
305 | |||
304 | class Meta: |
|
306 | class Meta: | |
305 | db_table = 'db_configurations' |
|
307 | db_table = 'db_configurations' | |
306 |
|
308 | |||
307 | def __unicode__(self): |
|
309 | def __unicode__(self): | |
308 |
|
310 | |||
309 | if self.experiment: |
|
311 | return u'[%s]: %s' % (self.device.name, self.name) | |
310 | return u'[%s, %s]: %s' % (self.experiment.name, |
|
|||
311 | self.device.name, |
|
|||
312 | self.name) |
|
|||
313 | else: |
|
|||
314 | return u'%s' % self.device.name |
|
|||
315 |
|
312 | |||
316 | def clone(self, **kwargs): |
|
313 | def clone(self, **kwargs): | |
317 |
|
314 | |||
318 | self.pk = None |
|
315 | self.pk = None | |
319 | self.id = None |
|
316 | self.id = None | |
320 | for attr, value in kwargs.items(): |
|
317 | for attr, value in kwargs.items(): | |
321 | setattr(self, attr, value) |
|
318 | setattr(self, attr, value) | |
322 |
|
319 | |||
323 | self.save() |
|
320 | self.save() | |
324 |
|
321 | |||
325 | return self |
|
322 | return self | |
326 |
|
323 | |||
327 | def parms_to_dict(self): |
|
324 | def parms_to_dict(self): | |
328 |
|
325 | |||
329 | parameters = {} |
|
326 | parameters = {} | |
330 |
|
327 | |||
331 | for key in self.__dict__.keys(): |
|
328 | for key in self.__dict__.keys(): | |
332 | parameters[key] = getattr(self, key) |
|
329 | parameters[key] = getattr(self, key) | |
333 |
|
330 | |||
334 | return parameters |
|
331 | return parameters | |
335 |
|
332 | |||
336 | def parms_to_text(self): |
|
333 | def parms_to_text(self): | |
337 |
|
334 | |||
338 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
335 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() | |
339 |
|
336 | |||
340 | return '' |
|
337 | return '' | |
341 |
|
338 | |||
342 | def parms_to_binary(self): |
|
339 | def parms_to_binary(self): | |
343 |
|
340 | |||
344 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
341 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() | |
345 |
|
342 | |||
346 | return '' |
|
343 | return '' | |
347 |
|
344 | |||
348 | def dict_to_parms(self, parameters): |
|
345 | def dict_to_parms(self, parameters): | |
349 |
|
346 | |||
350 | if type(parameters) != type({}): |
|
347 | if type(parameters) != type({}): | |
351 | return |
|
348 | return | |
352 |
|
349 | |||
353 | for key in parameters.keys(): |
|
350 | for key in parameters.keys(): | |
354 | setattr(self, key, parameters[key]) |
|
351 | setattr(self, key, parameters[key]) | |
355 |
|
352 | |||
356 | def export_to_file(self, format="json"): |
|
353 | def export_to_file(self, format="json"): | |
357 |
|
354 | |||
358 | import json |
|
355 | import json | |
359 |
|
356 | |||
360 | content_type = '' |
|
357 | content_type = '' | |
361 |
|
358 | |||
362 | if format == 'text': |
|
359 | if format == 'text': | |
363 | content_type = 'text/plain' |
|
360 | content_type = 'text/plain' | |
364 | filename = '%s_%s.%s' %(self.device.device_type.name, self.name, self.device.device_type.name) |
|
361 | filename = '%s_%s.%s' %(self.device.device_type.name, self.name, self.device.device_type.name) | |
365 | content = self.parms_to_text() |
|
362 | content = self.parms_to_text() | |
366 |
|
363 | |||
367 | if format == 'binary': |
|
364 | if format == 'binary': | |
368 | content_type = 'application/octet-stream' |
|
365 | content_type = 'application/octet-stream' | |
369 | filename = '%s_%s.bin' %(self.device.device_type.name, self.name) |
|
366 | filename = '%s_%s.bin' %(self.device.device_type.name, self.name) | |
370 | content = self.parms_to_binary() |
|
367 | content = self.parms_to_binary() | |
371 |
|
368 | |||
372 | if not content_type: |
|
369 | if not content_type: | |
373 | content_type = 'application/json' |
|
370 | content_type = 'application/json' | |
374 | filename = '%s_%s.json' %(self.device.device_type.name, self.name) |
|
371 | filename = '%s_%s.json' %(self.device.device_type.name, self.name) | |
375 | content = json.dumps(self.parms_to_dict(), indent=2) |
|
372 | content = json.dumps(self.parms_to_dict(), indent=2) | |
376 |
|
373 | |||
377 | fields = {'content_type':content_type, |
|
374 | fields = {'content_type':content_type, | |
378 | 'filename':filename, |
|
375 | 'filename':filename, | |
379 | 'content':content |
|
376 | 'content':content | |
380 | } |
|
377 | } | |
381 |
|
378 | |||
382 | return fields |
|
379 | return fields | |
383 |
|
380 | |||
384 | def import_from_file(self, fp): |
|
381 | def import_from_file(self, fp): | |
385 |
|
382 | |||
386 | import os, json |
|
383 | import os, json | |
387 |
|
384 | |||
388 | parms = {} |
|
385 | parms = {} | |
389 |
|
386 | |||
390 | path, ext = os.path.splitext(fp.name) |
|
387 | path, ext = os.path.splitext(fp.name) | |
391 |
|
388 | |||
392 | if ext == '.json': |
|
389 | if ext == '.json': | |
393 | parms = json.load(fp) |
|
390 | parms = json.load(fp) | |
394 |
|
391 | |||
395 | return parms |
|
392 | return parms | |
396 |
|
393 | |||
397 | def status_device(self): |
|
394 | def status_device(self): | |
398 |
|
395 | |||
399 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
396 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() | |
400 |
|
397 | |||
401 | return None |
|
398 | return None | |
402 |
|
399 | |||
403 | def stop_device(self): |
|
400 | def stop_device(self): | |
404 |
|
401 | |||
405 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
402 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() | |
406 |
|
403 | |||
407 | return None |
|
404 | return None | |
408 |
|
405 | |||
409 | def start_device(self): |
|
406 | def start_device(self): | |
410 |
|
407 | |||
411 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
408 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() | |
412 |
|
409 | |||
413 | return None |
|
410 | return None | |
414 |
|
411 | |||
415 | def write_device(self, parms): |
|
412 | def write_device(self, parms): | |
416 |
|
413 | |||
417 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
414 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() | |
418 |
|
415 | |||
419 | return None |
|
416 | return None | |
420 |
|
417 | |||
421 | def read_device(self): |
|
418 | def read_device(self): | |
422 |
|
419 | |||
423 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
420 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() | |
424 |
|
421 | |||
425 | return None |
|
422 | return None | |
426 |
|
423 | |||
427 | def get_absolute_url(self): |
|
424 | def get_absolute_url(self): | |
428 | return reverse('url_%s_conf' % self.device.device_type.name, args=[str(self.id)]) |
|
425 | return reverse('url_%s_conf' % self.device.device_type.name, args=[str(self.id)]) | |
429 |
|
426 | |||
430 | def get_absolute_url_edit(self): |
|
427 | def get_absolute_url_edit(self): | |
431 | return reverse('url_edit_%s_conf' % self.device.device_type.name, args=[str(self.id)]) |
|
428 | return reverse('url_edit_%s_conf' % self.device.device_type.name, args=[str(self.id)]) | |
432 |
|
429 | |||
433 | def get_absolute_url_import(self): |
|
430 | def get_absolute_url_import(self): | |
434 | return reverse('url_import_dev_conf', args=[str(self.id)]) |
|
431 | return reverse('url_import_dev_conf', args=[str(self.id)]) | |
435 |
|
432 | |||
436 | def get_absolute_url_export(self): |
|
433 | def get_absolute_url_export(self): | |
437 | return reverse('url_export_dev_conf', args=[str(self.id)]) |
|
434 | return reverse('url_export_dev_conf', args=[str(self.id)]) | |
438 |
|
435 | |||
439 | def get_absolute_url_write(self): |
|
436 | def get_absolute_url_write(self): | |
440 | return reverse('url_write_dev_conf', args=[str(self.id)]) |
|
437 | return reverse('url_write_dev_conf', args=[str(self.id)]) | |
441 |
|
438 | |||
442 | def get_absolute_url_read(self): |
|
439 | def get_absolute_url_read(self): | |
443 | return reverse('url_read_dev_conf', args=[str(self.id)]) |
|
440 | return reverse('url_read_dev_conf', args=[str(self.id)]) | |
444 |
|
441 | |||
445 | def get_absolute_url_start(self): |
|
442 | def get_absolute_url_start(self): | |
446 | return reverse('url_start_dev_conf', args=[str(self.id)]) |
|
443 | return reverse('url_start_dev_conf', args=[str(self.id)]) | |
447 |
|
444 | |||
448 | def get_absolute_url_stop(self): |
|
445 | def get_absolute_url_stop(self): | |
449 | return reverse('url_stop_dev_conf', args=[str(self.id)]) |
|
446 | return reverse('url_stop_dev_conf', args=[str(self.id)]) | |
450 |
|
447 | |||
451 | def get_absolute_url_status(self): |
|
448 | def get_absolute_url_status(self): | |
452 | return reverse('url_status_dev_conf', args=[str(self.id)]) No newline at end of file |
|
449 | return reverse('url_status_dev_conf', args=[str(self.id)]) |
@@ -1,108 +1,107 | |||||
1 | {% extends "base.html" %} |
|
1 | {% extends "base.html" %} | |
2 | {% load bootstrap3 %} |
|
2 | {% load bootstrap3 %} | |
3 | {% load static %} |
|
3 | {% load static %} | |
4 | {% load main_tags %} |
|
4 | {% load main_tags %} | |
5 | {% block extra-head %} |
|
5 | {% block extra-head %} | |
6 | <link href="{% static 'css/bootstrap-datetimepicker.min.css' %}" media="screen" rel="stylesheet"> |
|
6 | <link href="{% static 'css/bootstrap-datetimepicker.min.css' %}" media="screen" rel="stylesheet"> | |
7 | {% endblock %} |
|
7 | {% endblock %} | |
8 |
|
8 | |||
9 | {% block camp-active %}active{% endblock %} |
|
9 | {% block camp-active %}active{% endblock %} | |
10 |
|
10 | |||
11 | {% block content-title %}{{title}}{% endblock %} |
|
11 | {% block content-title %}{{title}}{% endblock %} | |
12 | {% block content-suptitle %}{{suptitle}}{% endblock %} |
|
12 | {% block content-suptitle %}{{suptitle}}{% endblock %} | |
13 |
|
13 | |||
14 | {% block content %} |
|
14 | {% block content %} | |
15 |
|
15 | |||
16 | {% block menu-actions %} |
|
16 | {% block menu-actions %} | |
17 | <span class=" dropdown pull-right"> |
|
17 | <span class=" dropdown pull-right"> | |
18 | <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-menu-hamburger gi-2x" aria-hidden="true"></span></a> |
|
18 | <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-menu-hamburger gi-2x" aria-hidden="true"></span></a> | |
19 | <ul class="dropdown-menu" role="menu"> |
|
19 | <ul class="dropdown-menu" role="menu"> | |
20 | <li><a href="{% url 'url_edit_campaign' campaign.id %}"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit</a></li> |
|
20 | <li><a href="{% url 'url_edit_campaign' campaign.id %}"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit</a></li> | |
21 |
<li><a href="{% url 'url_delete_campaign' campaign.id %}"><span class="glyphicon glyphicon-remove |
|
21 | <li><a href="{% url 'url_delete_campaign' campaign.id %}"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Delete</a></li> | |
22 | <li><a href="{{ dev_conf.get_absolute_url_import }}"><span class="glyphicon glyphicon-import" aria-hidden="true"></span> Import </a></li> |
|
22 | <li><a href="{{ dev_conf.get_absolute_url_import }}"><span class="glyphicon glyphicon-import" aria-hidden="true"></span> Import </a></li> | |
23 | <li><a href="{{ campaign.get_absolute_url_export }}"><span class="glyphicon glyphicon-export" aria-hidden="true"></span> Export </a></li> |
|
23 | <li><a href="{{ campaign.get_absolute_url_export }}"><span class="glyphicon glyphicon-export" aria-hidden="true"></span> Export </a></li> | |
24 | {% block extra-menu-actions %} |
|
24 | {% block extra-menu-actions %} | |
25 | {% endblock %} |
|
25 | {% endblock %} | |
26 | <li><a>----------------</a></li> |
|
26 | <li><a>----------------</a></li> | |
27 | <li><a href="#"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> Mix Experiments</a></li> |
|
|||
28 | <!--<li><a href="{{ dev_conf.get_absolute_url_status }}"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> Status</a></li> |
|
27 | <!--<li><a href="{{ dev_conf.get_absolute_url_status }}"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> Status</a></li> | |
29 | {% if not no_play %} |
|
28 | {% if not no_play %} | |
30 | <li><a href="{{ dev_conf.get_absolute_url_start}}"><span class="glyphicon glyphicon-play" aria-hidden="true"></span> Start</a></li> |
|
29 | <li><a href="{{ dev_conf.get_absolute_url_start}}"><span class="glyphicon glyphicon-play" aria-hidden="true"></span> Start</a></li> | |
31 | <li><a href="{{ dev_conf.get_absolute_url_stop }}"><span class="glyphicon glyphicon-stop" aria-hidden="true"></span> Stop</a></li> |
|
30 | <li><a href="{{ dev_conf.get_absolute_url_stop }}"><span class="glyphicon glyphicon-stop" aria-hidden="true"></span> Stop</a></li> | |
32 | {% endif %} |
|
31 | {% endif %} | |
33 | <li><a href="{{ dev_conf.get_absolute_url_write }}"><span class="glyphicon glyphicon-download" aria-hidden="true"></span> Write</a></li> |
|
32 | <li><a href="{{ dev_conf.get_absolute_url_write }}"><span class="glyphicon glyphicon-download" aria-hidden="true"></span> Write</a></li> | |
34 | <li><a href="{{ dev_conf.get_absolute_url_read }}"><span class="glyphicon glyphicon-upload" aria-hidden="true"></span> Read</a></li>--> |
|
33 | <li><a href="{{ dev_conf.get_absolute_url_read }}"><span class="glyphicon glyphicon-upload" aria-hidden="true"></span> Read</a></li>--> | |
35 | </ul> |
|
34 | </ul> | |
36 | </span> |
|
35 | </span> | |
37 | {% endblock %} |
|
36 | {% endblock %} | |
38 |
|
37 | |||
39 | <table class="table table-bordered"> |
|
38 | <table class="table table-bordered"> | |
40 | {% for key in campaign_keys %} |
|
39 | {% for key in campaign_keys %} | |
41 | <tr><th>{{key|title}}</th><td>{{campaign|attr:key}}</td></tr> |
|
40 | <tr><th>{{key|title}}</th><td>{{campaign|attr:key}}</td></tr> | |
42 | {% endfor %} |
|
41 | {% endfor %} | |
43 | </table> |
|
42 | </table> | |
44 |
|
43 | |||
45 | <!--<button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_export">Export</button>--> |
|
44 | <!--<button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_export">Export</button>--> | |
46 | <!--<button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_edit">Edit</button>--> |
|
45 | <!--<button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_edit">Edit</button>--> | |
47 |
|
46 | |||
48 | <br></br> |
|
47 | <br></br> | |
49 | <br></br> |
|
48 | <br></br> | |
50 |
|
49 | |||
51 | <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> |
|
50 | <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> | |
52 |
|
51 | |||
53 | <div class="panel panel-default"> |
|
52 | <div class="panel panel-default"> | |
54 | <div class="panel-heading" role="tab" id="headingTwo"> |
|
53 | <div class="panel-heading" role="tab" id="headingTwo"> | |
55 | <h4 class="panel-title"> |
|
54 | <h4 class="panel-title"> | |
56 | <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo"> |
|
55 | <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo"> | |
57 | Experiment List |
|
56 | Experiment List | |
58 | </a> |
|
57 | </a> | |
59 | </h4> |
|
58 | </h4> | |
60 | </div> |
|
59 | </div> | |
61 |
|
60 | |||
62 | <div id="collapseTwo" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo"> |
|
61 | <div id="collapseTwo" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo"> | |
63 | <div class="panel-body"> |
|
62 | <div class="panel-body"> | |
64 | <table class="table table-hover"> |
|
63 | <table class="table table-hover"> | |
65 | <tr> |
|
64 | <tr> | |
66 | <th>#</th> |
|
65 | <th>#</th> | |
67 | {% for header in experiment_keys %} |
|
66 | {% for header in experiment_keys %} | |
68 | <th>{{ header|title }}</th> |
|
67 | <th>{{ header|title }}</th> | |
69 | {% endfor%} |
|
68 | {% endfor%} | |
70 | </tr> |
|
69 | </tr> | |
71 | {% for item in experiments %} |
|
70 | {% for item in experiments %} | |
72 | <tr class="clickable-row" data-href="{% url 'url_experiment' item.id %}"> |
|
71 | <tr class="clickable-row" data-href="{% url 'url_experiment' item.id %}"> | |
73 | <td>{{ forloop.counter }}</td> |
|
72 | <td>{{ forloop.counter }}</td> | |
74 | {% for key in experiment_keys %} |
|
73 | {% for key in experiment_keys %} | |
75 | <td>{{ item|attr:key }}</td> |
|
74 | <td>{{ item|attr:key }}</td> | |
76 | {% endfor %} |
|
75 | {% endfor %} | |
77 | </tr> |
|
76 | </tr> | |
78 | {% endfor %} |
|
77 | {% endfor %} | |
79 | </table> |
|
78 | </table> | |
80 | </div> |
|
79 | </div> | |
81 | </div> |
|
80 | </div> | |
82 | </div> |
|
81 | </div> | |
83 | </div> |
|
82 | </div> | |
84 | <br> |
|
83 | <br> | |
85 | <!--<button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_mix">Mix Experiments</button>--> |
|
84 | <!--<button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_mix">Mix Experiments</button>--> | |
86 | {% endblock %} |
|
85 | {% endblock %} | |
87 |
|
86 | |||
88 | {% block sidebar%} |
|
87 | {% block sidebar%} | |
89 | {% include "sidebar_devices.html" %} |
|
88 | {% include "sidebar_devices.html" %} | |
90 | {% endblock %} |
|
89 | {% endblock %} | |
91 |
|
90 | |||
92 | {% block extra-js%} |
|
91 | {% block extra-js%} | |
93 | <script type="text/javascript"> |
|
92 | <script type="text/javascript"> | |
94 |
|
93 | |||
95 | $(".clickable-row").click(function() { |
|
94 | $(".clickable-row").click(function() { | |
96 | document.location = $(this).data("href"); |
|
95 | document.location = $(this).data("href"); | |
97 | }); |
|
96 | }); | |
98 |
|
97 | |||
99 | // $("#bt_edit").click(function() { |
|
98 | // $("#bt_edit").click(function() { | |
100 | // document.location = "{% url 'url_edit_campaign' campaign.id %}"; |
|
99 | // document.location = "{% url 'url_edit_campaign' campaign.id %}"; | |
101 | // }); |
|
100 | // }); | |
102 |
|
101 | |||
103 | $("#bt_mix").click(function() { |
|
102 | $("#bt_mix").click(function() { | |
104 |
|
103 | |||
105 | }); |
|
104 | }); | |
106 |
|
105 | |||
107 | </script> |
|
106 | </script> | |
108 | {% endblock %} No newline at end of file |
|
107 | {% endblock %} |
@@ -1,81 +1,82 | |||||
1 | {% extends "base.html" %} |
|
1 | {% extends "base.html" %} | |
2 | {% load bootstrap3 %} |
|
2 | {% load bootstrap3 %} | |
3 | {% load static %} |
|
3 | {% load static %} | |
4 | {% load main_tags %} |
|
4 | {% load main_tags %} | |
5 |
|
5 | |||
6 | {% block search-active %}active{% endblock %} |
|
6 | {% block search-active %}active{% endblock %} | |
7 |
|
7 | |||
8 | {% block content-title %}{{title}}{% endblock %} |
|
8 | {% block content-title %}{{title}}{% endblock %} | |
9 | {% block content-suptitle %}{{suptitle}}{% endblock %} |
|
9 | {% block content-suptitle %}{{suptitle}}{% endblock %} | |
10 |
|
10 | |||
11 | {% block content %} |
|
11 | {% block content %} | |
12 |
|
12 | |||
13 | {% block menu-actions %} |
|
13 | {% block menu-actions %} | |
14 | <span class=" dropdown pull-right"> |
|
14 | <span class=" dropdown pull-right"> | |
15 | <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-menu-hamburger gi-2x" aria-hidden="true"></span></a> |
|
15 | <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-menu-hamburger gi-2x" aria-hidden="true"></span></a> | |
16 | <ul class="dropdown-menu" role="menu"> |
|
16 | <ul class="dropdown-menu" role="menu"> | |
17 | <li><a href="{{ dev_conf.get_absolute_url_edit }}"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit</a></li> |
|
17 | <li><a href="{{ dev_conf.get_absolute_url_edit }}"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit</a></li> | |
|
18 | <li><a href="{% url 'url_delete_dev_conf' dev_conf.id %}"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Delete</a></li> | |||
18 | <li><a href="{{ dev_conf.get_absolute_url_import }}"><span class="glyphicon glyphicon-import" aria-hidden="true"></span> Import </a></li> |
|
19 | <li><a href="{{ dev_conf.get_absolute_url_import }}"><span class="glyphicon glyphicon-import" aria-hidden="true"></span> Import </a></li> | |
19 | <li><a href="{{ dev_conf.get_absolute_url_export }}"><span class="glyphicon glyphicon-export" aria-hidden="true"></span> Export </a></li> |
|
20 | <li><a href="{{ dev_conf.get_absolute_url_export }}"><span class="glyphicon glyphicon-export" aria-hidden="true"></span> Export </a></li> | |
20 | {% block extra-menu-actions %} |
|
21 | {% block extra-menu-actions %} | |
21 | {% endblock %} |
|
22 | {% endblock %} | |
22 | <li><a>----------------</a></li> |
|
23 | <li><a>----------------</a></li> | |
23 | <li><a href="{{ dev_conf.get_absolute_url_status }}"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> Status</a></li> |
|
24 | <li><a href="{{ dev_conf.get_absolute_url_status }}"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> Status</a></li> | |
24 | {% if not no_play %} |
|
25 | {% if not no_play %} | |
25 | <li><a href="{{ dev_conf.get_absolute_url_start}}"><span class="glyphicon glyphicon-play" aria-hidden="true"></span> Start</a></li> |
|
26 | <li><a href="{{ dev_conf.get_absolute_url_start}}"><span class="glyphicon glyphicon-play" aria-hidden="true"></span> Start</a></li> | |
26 | <li><a href="{{ dev_conf.get_absolute_url_stop }}"><span class="glyphicon glyphicon-stop" aria-hidden="true"></span> Stop</a></li> |
|
27 | <li><a href="{{ dev_conf.get_absolute_url_stop }}"><span class="glyphicon glyphicon-stop" aria-hidden="true"></span> Stop</a></li> | |
27 | {% endif %} |
|
28 | {% endif %} | |
28 | <li><a href="{{ dev_conf.get_absolute_url_write }}"><span class="glyphicon glyphicon-download" aria-hidden="true"></span> Write</a></li> |
|
29 | <li><a href="{{ dev_conf.get_absolute_url_write }}"><span class="glyphicon glyphicon-download" aria-hidden="true"></span> Write</a></li> | |
29 | <li><a href="{{ dev_conf.get_absolute_url_read }}"><span class="glyphicon glyphicon-upload" aria-hidden="true"></span> Read</a></li> |
|
30 | <li><a href="{{ dev_conf.get_absolute_url_read }}"><span class="glyphicon glyphicon-upload" aria-hidden="true"></span> Read</a></li> | |
30 | </ul> |
|
31 | </ul> | |
31 | </span> |
|
32 | </span> | |
32 | {% endblock %} |
|
33 | {% endblock %} | |
33 |
|
34 | |||
34 | <table class="table table-bordered"> |
|
35 | <table class="table table-bordered"> | |
35 | <tr> |
|
36 | <tr> | |
36 | <th>Status</th> |
|
37 | <th>Status</th> | |
37 | <td>{%if status != "No connected" %} <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> {{status}} {% endif %}</td> |
|
38 | <td>{%if status != "No connected" %} <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> {{status}} {% endif %}</td> | |
38 | </tr> |
|
39 | </tr> | |
39 |
|
40 | |||
40 | {% for key in dev_conf_keys %} |
|
41 | {% for key in dev_conf_keys %} | |
41 | <tr> |
|
42 | <tr> | |
42 | <th>{% get_verbose_field_name dev_conf key %}</th> |
|
43 | <th>{% get_verbose_field_name dev_conf key %}</th> | |
43 | <td>{{dev_conf|attr:key}}</td> |
|
44 | <td>{{dev_conf|attr:key}}</td> | |
44 | </tr> |
|
45 | </tr> | |
45 | {% endfor %} |
|
46 | {% endfor %} | |
46 | </table> |
|
47 | </table> | |
47 |
|
48 | |||
48 | {% block extra-content %} |
|
49 | {% block extra-content %} | |
49 | {% endblock %} |
|
50 | {% endblock %} | |
50 |
|
51 | |||
51 | {% endblock %} |
|
52 | {% endblock %} | |
52 |
|
53 | |||
53 | {% block sidebar%} |
|
54 | {% block sidebar%} | |
54 | {% include "sidebar_devices.html" %} |
|
55 | {% include "sidebar_devices.html" %} | |
55 | {% endblock %} |
|
56 | {% endblock %} | |
56 |
|
57 | |||
57 | {% block extra-js%} |
|
58 | {% block extra-js%} | |
58 | <script type="text/javascript"> |
|
59 | <script type="text/javascript"> | |
59 |
|
60 | |||
60 | $("#bt_edit").click(function() { |
|
61 | $("#bt_edit").click(function() { | |
61 | document.location = "{{ dev_conf.get_absolute_url_edit }}"; |
|
62 | document.location = "{{ dev_conf.get_absolute_url_edit }}"; | |
62 | }); |
|
63 | }); | |
63 |
|
64 | |||
64 | $("#bt_read").click(function() { |
|
65 | $("#bt_read").click(function() { | |
65 | document.location = "{{ dev_conf.get_absolute_url_read }}"; |
|
66 | document.location = "{{ dev_conf.get_absolute_url_read }}"; | |
66 | }); |
|
67 | }); | |
67 |
|
68 | |||
68 | $("#bt_write").click(function() { |
|
69 | $("#bt_write").click(function() { | |
69 | document.location = "{{ dev_conf.get_absolute_url_write }}"; |
|
70 | document.location = "{{ dev_conf.get_absolute_url_write }}"; | |
70 | }); |
|
71 | }); | |
71 |
|
72 | |||
72 | $("#bt_import").click(function() { |
|
73 | $("#bt_import").click(function() { | |
73 | document.location = "{{ dev_conf.get_absolute_url_import }}"; |
|
74 | document.location = "{{ dev_conf.get_absolute_url_import }}"; | |
74 | }); |
|
75 | }); | |
75 |
|
76 | |||
76 | $("#bt_export").click(function() { |
|
77 | $("#bt_export").click(function() { | |
77 | document.location = "{{ dev_conf.get_absolute_url_export }}"; |
|
78 | document.location = "{{ dev_conf.get_absolute_url_export }}"; | |
78 | }); |
|
79 | }); | |
79 |
|
80 | |||
80 | </script> |
|
81 | </script> | |
81 | {% endblock %} No newline at end of file |
|
82 | {% endblock %} |
@@ -1,95 +1,95 | |||||
1 | {% extends "base.html" %} |
|
1 | {% extends "base.html" %} | |
2 | {% load bootstrap3 %} |
|
2 | {% load bootstrap3 %} | |
3 | {% load static %} |
|
3 | {% load static %} | |
4 | {% load main_tags %} |
|
4 | {% load main_tags %} | |
5 | {% block extra-head %} |
|
5 | {% block extra-head %} | |
6 | <link href="{% static 'css/bootstrap-datetimepicker.min.css' %}" media="screen" rel="stylesheet"> |
|
6 | <link href="{% static 'css/bootstrap-datetimepicker.min.css' %}" media="screen" rel="stylesheet"> | |
7 | {% endblock %} |
|
7 | {% endblock %} | |
8 |
|
8 | |||
9 | {% block exp-active %}active{% endblock %} |
|
9 | {% block exp-active %}active{% endblock %} | |
10 |
|
10 | |||
11 | {% block content-title %}{{title}}{% endblock %} |
|
11 | {% block content-title %}{{title}}{% endblock %} | |
12 | {% block content-suptitle %}{{suptitle}}{% endblock %} |
|
12 | {% block content-suptitle %}{{suptitle}}{% endblock %} | |
13 |
|
13 | |||
14 | {% block content %} |
|
14 | {% block content %} | |
15 |
|
15 | |||
16 | {% block menu-actions %} |
|
16 | {% block menu-actions %} | |
17 | <span class=" dropdown pull-right"> |
|
17 | <span class=" dropdown pull-right"> | |
18 | <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-menu-hamburger gi-2x" aria-hidden="true"></span></a> |
|
18 | <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-menu-hamburger gi-2x" aria-hidden="true"></span></a> | |
19 | <ul class="dropdown-menu" role="menu"> |
|
19 | <ul class="dropdown-menu" role="menu"> | |
20 | <li><a href="{% url 'url_edit_experiment' experiment.id %}"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit</a></li> |
|
20 | <li><a href="{% url 'url_edit_experiment' experiment.id %}"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit</a></li> | |
21 |
<li><a href="{% url 'url_delete_experiment' experiment.id %}"><span class="glyphicon glyphicon-remove |
|
21 | <li><a href="{% url 'url_delete_experiment' experiment.id %}"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Delete</a></li> | |
22 | <li><a href="{{ dev_conf.get_absolute_url_import }}"><span class="glyphicon glyphicon-import" aria-hidden="true"></span> Import </a></li> |
|
22 | <li><a href="{{ dev_conf.get_absolute_url_import }}"><span class="glyphicon glyphicon-import" aria-hidden="true"></span> Import </a></li> | |
23 | <li><a href="{{ experiment.get_absolute_url_export }}"><span class="glyphicon glyphicon-export" aria-hidden="true"></span> Export </a></li> |
|
23 | <li><a href="{{ experiment.get_absolute_url_export }}"><span class="glyphicon glyphicon-export" aria-hidden="true"></span> Export </a></li> | |
24 | {% block extra-menu-actions %} |
|
24 | {% block extra-menu-actions %} | |
25 | {% endblock %} |
|
25 | {% endblock %} | |
26 | <li><a>----------------</a></li> |
|
26 | <li><a>----------------</a></li> | |
27 |
<li><a href=" |
|
27 | <li><a href="{% url 'url_mix_experiment' experiment.id %}"><span class="glyphicon glyphicon-random" aria-hidden="true"></span> Mix RC Configurations </a></li> | |
|
28 | <li><a href="{% url 'url_add_dev_conf' experiment.id %}"><span class="glyphicon glyphicon-plus-sign" aria-hidden="true"></span> Add Configuration</a></li> | |||
28 | </ul> |
|
29 | </ul> | |
29 | </span> |
|
30 | </span> | |
30 | {% endblock %} |
|
31 | {% endblock %} | |
31 |
|
32 | |||
32 | <table class="table table-bordered"> |
|
33 | <table class="table table-bordered"> | |
33 | {% for key in experiment_keys %} |
|
34 | {% for key in experiment_keys %} | |
34 | <tr><th>{{key|title}}</th><td>{{experiment|attr:key}}</td></tr> |
|
35 | <tr><th>{{key|title}}</th><td>{{experiment|attr:key}}</td></tr> | |
35 | {% endfor %} |
|
36 | {% endfor %} | |
36 | </table> |
|
37 | </table> | |
37 | <br></br> |
|
38 | <br></br> | |
38 | <br></br> |
|
39 | <br></br> | |
39 |
|
40 | |||
40 | <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> |
|
41 | <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> | |
41 |
|
42 | |||
42 | <div class="panel panel-default"> |
|
43 | <div class="panel panel-default"> | |
43 | <div class="panel-heading" role="tab" id="headingTwo"> |
|
44 | <div class="panel-heading" role="tab" id="headingTwo"> | |
44 | <h4 class="panel-title"> |
|
45 | <h4 class="panel-title"> | |
45 | <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseThree"> |
|
46 | <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseThree"> | |
46 | Device Configurations |
|
47 | Device Configurations | |
47 | </a> |
|
48 | </a> | |
48 | </h4> |
|
49 | </h4> | |
49 | </div> |
|
50 | </div> | |
50 | <div id="collapseTwo" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo"> |
|
51 | <div id="collapseTwo" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo"> | |
51 | <div class="panel-body"> |
|
52 | <div class="panel-body"> | |
52 | <table class="table table-hover"> |
|
53 | <table class="table table-hover"> | |
53 | <tr> |
|
54 | <tr> | |
54 | <th>#</th> |
|
55 | <th>#</th> | |
55 | {% for key in configuration_keys %} |
|
56 | {% for key in configuration_keys %} | |
56 | <th>{{ key|title }}</th> |
|
57 | <th>{{ key|title }}</th> | |
57 | {% endfor%} |
|
58 | {% endfor%} | |
58 | </tr> |
|
59 | </tr> | |
59 | {% for item in configurations %} |
|
60 | {% for item in configurations %} | |
60 | <tr class="clickable-row" data-href="{{item.get_absolute_url}}"> |
|
61 | <tr class="clickable-row" data-href="{{item.get_absolute_url}}"> | |
61 | <td>{{ forloop.counter }}</td> |
|
62 | <td>{{ forloop.counter }}</td> | |
62 | {% for key in configuration_keys %} |
|
63 | {% for key in configuration_keys %} | |
63 | <td>{{ item|value:key }}</td> |
|
64 | <td>{{ item|value:key }}</td> | |
64 | {% endfor %} |
|
65 | {% endfor %} | |
65 | </tr> |
|
66 | </tr> | |
66 | {% endfor %} |
|
67 | {% endfor %} | |
67 |
</table> |
|
68 | </table> | |
68 | <button class="btn btn-primary pull-right" id="bt_add_conf">{{button}}</button> |
|
|||
69 | </div> |
|
69 | </div> | |
70 | </div> |
|
70 | </div> | |
71 | </div> |
|
71 | </div> | |
72 | </div> |
|
72 | </div> | |
73 | {% endblock %} |
|
73 | {% endblock %} | |
74 |
|
74 | |||
75 | {% block sidebar%} |
|
75 | {% block sidebar%} | |
76 | {% include "sidebar_devices.html" %} |
|
76 | {% include "sidebar_devices.html" %} | |
77 | {% endblock %} |
|
77 | {% endblock %} | |
78 |
|
78 | |||
79 | {% block extra-js%} |
|
79 | {% block extra-js%} | |
80 | <script type="text/javascript"> |
|
80 | <script type="text/javascript"> | |
81 |
|
81 | |||
82 | $(".clickable-row").click(function() { |
|
82 | $(".clickable-row").click(function() { | |
83 | document.location = $(this).data("href"); |
|
83 | document.location = $(this).data("href"); | |
84 | }); |
|
84 | }); | |
85 |
|
85 | |||
86 | $("#bt_edit").click(function() { |
|
86 | $("#bt_edit").click(function() { | |
87 | document.location = "{% url 'url_edit_experiment' experiment.id%}"; |
|
87 | document.location = "{% url 'url_edit_experiment' experiment.id%}"; | |
88 | }); |
|
88 | }); | |
89 |
|
89 | |||
90 | $("#bt_add_conf").click(function() { |
|
90 | $("#bt_add_conf").click(function() { | |
91 | document.location = "{% url 'url_add_dev_conf' experiment.id %}"; |
|
91 | document.location = "{% url 'url_add_dev_conf' experiment.id %}"; | |
92 | }); |
|
92 | }); | |
93 |
|
93 | |||
94 | </script> |
|
94 | </script> | |
95 | {% endblock %} No newline at end of file |
|
95 | {% endblock %} |
@@ -1,14 +1,26 | |||||
1 | {% extends "base_edit.html" %} |
|
1 | {% extends "base_edit.html" %} | |
2 | {% load bootstrap3 %} |
|
2 | {% load bootstrap3 %} | |
3 | {% load static %} |
|
3 | {% load static %} | |
4 | {% load main_tags %} |
|
4 | {% load main_tags %} | |
5 | {% block extra-head %} |
|
5 | {% block extra-head %} | |
6 | <link href="{% static 'css/bootstrap-datetimepicker.min.css' %}" media="screen" rel="stylesheet"> |
|
6 | <link href="{% static 'css/bootstrap-datetimepicker.min.css' %}" media="screen" rel="stylesheet"> | |
|
7 | <style type="text/css"> | |||
|
8 | .tabuled {font-family: Courier New} | |||
|
9 | .check-inline {display: inline} | |||
|
10 | </style> | |||
7 | {% endblock %} |
|
11 | {% endblock %} | |
8 |
|
12 | |||
9 | {% block extra-js%} |
|
13 | {% block extra-js%} | |
10 | <script src="{% static 'js/moment.min.js' %}"></script> |
|
14 | <script src="{% static 'js/moment.min.js' %}"></script> | |
11 | <script src="{% static 'js/bootstrap-datetimepicker.min.js' %}"></script> |
|
15 | <script src="{% static 'js/bootstrap-datetimepicker.min.js' %}"></script> | |
12 | <script src="{% static 'js/cr.js' %}"></script> |
|
16 | <script src="{% static 'js/cr.js' %}"></script> | |
13 |
|
17 | |||
|
18 | <script type="text/javascript"> | |||
|
19 | ||||
|
20 | $("#bt_Delete").click(function() { | |||
|
21 | document.location = "{% url 'url_delete_mix_experiment' id_exp %}"; | |||
|
22 | }); | |||
|
23 | ||||
|
24 | </script> | |||
|
25 | ||||
14 | {% endblock %} No newline at end of file |
|
26 | {% endblock %} |
@@ -1,36 +1,38 | |||||
1 | from django.template.defaulttags import register |
|
1 | from django.template.defaulttags import register | |
2 | from django.utils.safestring import mark_safe |
|
2 | from django.utils.safestring import mark_safe | |
3 |
|
3 | |||
4 | @register.filter |
|
4 | @register.filter | |
5 | def attr(instance, key): |
|
5 | def attr(instance, key): | |
6 |
|
6 | |||
7 | display_key = "get_" + key + "_display" |
|
7 | display_key = "get_" + key + "_display" | |
8 |
|
8 | |||
9 | if hasattr(instance, display_key): |
|
9 | if hasattr(instance, display_key): | |
10 | return getattr(instance, display_key)() |
|
10 | return getattr(instance, display_key)() | |
11 |
|
11 | |||
12 | if hasattr(instance, key): |
|
12 | if hasattr(instance, key): | |
13 | return getattr(instance, key) |
|
13 | return getattr(instance, key) | |
14 |
|
14 | |||
15 | return instance.get(key) |
|
15 | return instance.get(key) | |
16 |
|
16 | |||
17 | @register.filter |
|
17 | @register.filter | |
18 | def title(s): |
|
18 | def title(s): | |
19 | return s.split('__')[-1].replace('_', ' ').title() |
|
19 | return s.split('__')[-1].replace('_', ' ').title() | |
20 |
|
20 | |||
21 | @register.filter |
|
21 | @register.filter | |
22 | def value(instance, key): |
|
22 | def value(instance, key): | |
23 |
|
23 | |||
24 | item = instance |
|
24 | item = instance | |
|
25 | if key=='name': | |||
|
26 | return '%s' % item | |||
25 | for my_key in key.split("__"): |
|
27 | for my_key in key.split("__"): | |
26 | item = attr(item, my_key) |
|
28 | item = attr(item, my_key) | |
27 |
|
29 | |||
28 | return item |
|
30 | return item | |
29 |
|
31 | |||
30 | @register.simple_tag |
|
32 | @register.simple_tag | |
31 | def get_verbose_field_name(instance, field_name): |
|
33 | def get_verbose_field_name(instance, field_name): | |
32 | """ |
|
34 | """ | |
33 | Returns verbose_name for a field. |
|
35 | Returns verbose_name for a field. | |
34 | """ |
|
36 | """ | |
35 |
|
37 | |||
36 | return mark_safe(instance._meta.get_field(field_name).verbose_name) No newline at end of file |
|
38 | return mark_safe(instance._meta.get_field(field_name).verbose_name) |
@@ -1,53 +1,55 | |||||
1 | from django.conf.urls import url |
|
1 | from django.conf.urls import url | |
2 |
|
2 | |||
3 | urlpatterns = ( |
|
3 | urlpatterns = ( | |
4 | url(r'^location/new/$', 'apps.main.views.location_new', name='url_add_location'), |
|
4 | url(r'^location/new/$', 'apps.main.views.location_new', name='url_add_location'), | |
5 | url(r'^location/$', 'apps.main.views.locations', name='url_locations'), |
|
5 | url(r'^location/$', 'apps.main.views.locations', name='url_locations'), | |
6 | url(r'^location/(?P<id_loc>-?\d+)/$', 'apps.main.views.location', name='url_location'), |
|
6 | url(r'^location/(?P<id_loc>-?\d+)/$', 'apps.main.views.location', name='url_location'), | |
7 | url(r'^location/(?P<id_loc>-?\d+)/edit/$', 'apps.main.views.location_edit', name='url_edit_location'), |
|
7 | url(r'^location/(?P<id_loc>-?\d+)/edit/$', 'apps.main.views.location_edit', name='url_edit_location'), | |
8 | url(r'^location/(?P<id_loc>-?\d+)/delete/$', 'apps.main.views.location_delete', name='url_delete_location'), |
|
8 | url(r'^location/(?P<id_loc>-?\d+)/delete/$', 'apps.main.views.location_delete', name='url_delete_location'), | |
9 |
|
9 | |||
10 | url(r'^device/new/$', 'apps.main.views.device_new', name='url_add_device'), |
|
10 | url(r'^device/new/$', 'apps.main.views.device_new', name='url_add_device'), | |
11 | url(r'^device/$', 'apps.main.views.devices', name='url_devices'), |
|
11 | url(r'^device/$', 'apps.main.views.devices', name='url_devices'), | |
12 | url(r'^device/(?P<id_dev>-?\d+)/$', 'apps.main.views.device', name='url_device'), |
|
12 | url(r'^device/(?P<id_dev>-?\d+)/$', 'apps.main.views.device', name='url_device'), | |
13 | url(r'^device/(?P<id_dev>-?\d+)/edit/$', 'apps.main.views.device_edit', name='url_edit_device'), |
|
13 | url(r'^device/(?P<id_dev>-?\d+)/edit/$', 'apps.main.views.device_edit', name='url_edit_device'), | |
14 | url(r'^device/(?P<id_dev>-?\d+)/delete/$', 'apps.main.views.device_delete', name='url_delete_device'), |
|
14 | url(r'^device/(?P<id_dev>-?\d+)/delete/$', 'apps.main.views.device_delete', name='url_delete_device'), | |
15 |
|
15 | |||
16 | url(r'^campaign/new/$', 'apps.main.views.campaign_new', name='url_add_campaign'), |
|
16 | url(r'^campaign/new/$', 'apps.main.views.campaign_new', name='url_add_campaign'), | |
17 | url(r'^campaign/$', 'apps.main.views.campaigns', name='url_campaigns'), |
|
17 | url(r'^campaign/$', 'apps.main.views.campaigns', name='url_campaigns'), | |
18 | url(r'^campaign/(?P<id_camp>-?\d+)/$', 'apps.main.views.campaign', name='url_campaign'), |
|
18 | url(r'^campaign/(?P<id_camp>-?\d+)/$', 'apps.main.views.campaign', name='url_campaign'), | |
19 | url(r'^campaign/(?P<id_camp>-?\d+)/edit/$', 'apps.main.views.campaign_edit', name='url_edit_campaign'), |
|
19 | url(r'^campaign/(?P<id_camp>-?\d+)/edit/$', 'apps.main.views.campaign_edit', name='url_edit_campaign'), | |
20 | url(r'^campaign/(?P<id_camp>-?\d+)/delete/$', 'apps.main.views.campaign_delete', name='url_delete_campaign'), |
|
20 | url(r'^campaign/(?P<id_camp>-?\d+)/delete/$', 'apps.main.views.campaign_delete', name='url_delete_campaign'), | |
21 | url(r'^campaign/(?P<id_camp>-?\d+)/export/$', 'apps.main.views.campaign_export', name='url_export_campaign'), |
|
21 | url(r'^campaign/(?P<id_camp>-?\d+)/export/$', 'apps.main.views.campaign_export', name='url_export_campaign'), | |
22 |
|
22 | |||
23 | url(r'^experiment/new/$', 'apps.main.views.experiment_new', name='url_add_experiment'), |
|
23 | url(r'^experiment/new/$', 'apps.main.views.experiment_new', name='url_add_experiment'), | |
24 | url(r'^experiment/$', 'apps.main.views.experiments', name='url_experiments'), |
|
24 | url(r'^experiment/$', 'apps.main.views.experiments', name='url_experiments'), | |
25 | url(r'^experiment/(?P<id_exp>-?\d+)/$', 'apps.main.views.experiment', name='url_experiment'), |
|
25 | url(r'^experiment/(?P<id_exp>-?\d+)/$', 'apps.main.views.experiment', name='url_experiment'), | |
26 | url(r'^experiment/(?P<id_exp>-?\d+)/edit/$', 'apps.main.views.experiment_edit', name='url_edit_experiment'), |
|
26 | url(r'^experiment/(?P<id_exp>-?\d+)/edit/$', 'apps.main.views.experiment_edit', name='url_edit_experiment'), | |
27 | url(r'^experiment/(?P<id_exp>-?\d+)/delete/$', 'apps.main.views.experiment_delete', name='url_delete_experiment'), |
|
27 | url(r'^experiment/(?P<id_exp>-?\d+)/delete/$', 'apps.main.views.experiment_delete', name='url_delete_experiment'), | |
28 | url(r'^experiment/(?P<id_exp>-?\d+)/export/$', 'apps.main.views.experiment_export', name='url_export_experiment'), |
|
28 | url(r'^experiment/(?P<id_exp>-?\d+)/export/$', 'apps.main.views.experiment_export', name='url_export_experiment'), | |
|
29 | url(r'^experiment/(?P<id_exp>-?\d+)/mix/$', 'apps.main.views.experiment_mix', name='url_mix_experiment'), | |||
|
30 | url(r'^experiment/(?P<id_exp>-?\d+)/mix/delete/$', 'apps.main.views.experiment_mix_delete', name='url_delete_mix_experiment'), | |||
29 |
|
31 | |||
30 | url(r'^experiment/(?P<id_exp>-?\d+)/new_dev_conf/$', 'apps.main.views.dev_conf_new', name='url_add_dev_conf'), |
|
32 | url(r'^experiment/(?P<id_exp>-?\d+)/new_dev_conf/$', 'apps.main.views.dev_conf_new', name='url_add_dev_conf'), | |
31 | url(r'^experiment/(?P<id_exp>-?\d+)/new_dev_conf/(?P<id_dev>-?\d+)/$', 'apps.main.views.dev_conf_new', name='url_add_dev_conf'), |
|
33 | url(r'^experiment/(?P<id_exp>-?\d+)/new_dev_conf/(?P<id_dev>-?\d+)/$', 'apps.main.views.dev_conf_new', name='url_add_dev_conf'), | |
32 | url(r'^dev_conf/$', 'apps.main.views.dev_confs', name='url_dev_confs'), |
|
34 | url(r'^dev_conf/$', 'apps.main.views.dev_confs', name='url_dev_confs'), | |
33 | url(r'^dev_conf/(?P<id_conf>-?\d+)/$', 'apps.main.views.dev_conf', name='url_dev_conf'), |
|
35 | url(r'^dev_conf/(?P<id_conf>-?\d+)/$', 'apps.main.views.dev_conf', name='url_dev_conf'), | |
34 | url(r'^dev_conf/(?P<id_conf>-?\d+)/edit/$', 'apps.main.views.dev_conf_edit', name='url_edit_dev_conf'), |
|
36 | url(r'^dev_conf/(?P<id_conf>-?\d+)/edit/$', 'apps.main.views.dev_conf_edit', name='url_edit_dev_conf'), | |
35 | url(r'^dev_conf/(?P<id_conf>-?\d+)/delete/$', 'apps.main.views.dev_conf_delete', name='url_delete_dev_conf'), |
|
37 | url(r'^dev_conf/(?P<id_conf>-?\d+)/delete/$', 'apps.main.views.dev_conf_delete', name='url_delete_dev_conf'), | |
36 |
|
38 | |||
37 | url(r'^dev_conf/(?P<id_conf>-?\d+)/write/$', 'apps.main.views.dev_conf_write', name='url_write_dev_conf'), |
|
39 | url(r'^dev_conf/(?P<id_conf>-?\d+)/write/$', 'apps.main.views.dev_conf_write', name='url_write_dev_conf'), | |
38 | url(r'^dev_conf/(?P<id_conf>-?\d+)/read/$', 'apps.main.views.dev_conf_read', name='url_read_dev_conf'), |
|
40 | url(r'^dev_conf/(?P<id_conf>-?\d+)/read/$', 'apps.main.views.dev_conf_read', name='url_read_dev_conf'), | |
39 | url(r'^dev_conf/(?P<id_conf>-?\d+)/import/$', 'apps.main.views.dev_conf_import', name='url_import_dev_conf'), |
|
41 | url(r'^dev_conf/(?P<id_conf>-?\d+)/import/$', 'apps.main.views.dev_conf_import', name='url_import_dev_conf'), | |
40 | url(r'^dev_conf/(?P<id_conf>-?\d+)/export/$', 'apps.main.views.dev_conf_export', name='url_export_dev_conf'), |
|
42 | url(r'^dev_conf/(?P<id_conf>-?\d+)/export/$', 'apps.main.views.dev_conf_export', name='url_export_dev_conf'), | |
41 | url(r'^dev_conf/(?P<id_conf>-?\d+)/start/$', 'apps.main.views.dev_conf_start', name='url_start_dev_conf'), |
|
43 | url(r'^dev_conf/(?P<id_conf>-?\d+)/start/$', 'apps.main.views.dev_conf_start', name='url_start_dev_conf'), | |
42 | url(r'^dev_conf/(?P<id_conf>-?\d+)/stop/$', 'apps.main.views.dev_conf_stop', name='url_stop_dev_conf'), |
|
44 | url(r'^dev_conf/(?P<id_conf>-?\d+)/stop/$', 'apps.main.views.dev_conf_stop', name='url_stop_dev_conf'), | |
43 | url(r'^dev_conf/(?P<id_conf>-?\d+)/status/$', 'apps.main.views.dev_conf_status', name='url_status_dev_conf'), |
|
45 | url(r'^dev_conf/(?P<id_conf>-?\d+)/status/$', 'apps.main.views.dev_conf_status', name='url_status_dev_conf'), | |
44 |
|
46 | |||
45 | url(r'^operation/$', 'apps.main.views.operation', name='url_operation'), |
|
47 | url(r'^operation/$', 'apps.main.views.operation', name='url_operation'), | |
46 | url(r'^operation/(?P<id_camp>-?\d+)/$', 'apps.main.views.operation', name='url_operation'), |
|
48 | url(r'^operation/(?P<id_camp>-?\d+)/$', 'apps.main.views.operation', name='url_operation'), | |
47 | url(r'^operation/search/$', 'apps.main.views.operation_search', name='url_operation_search'), |
|
49 | url(r'^operation/search/$', 'apps.main.views.operation_search', name='url_operation_search'), | |
48 | url(r'^operation/search/(?P<id_camp>-?\d+)/$', 'apps.main.views.operation_search', name='url_operation_search'), |
|
50 | url(r'^operation/search/(?P<id_camp>-?\d+)/$', 'apps.main.views.operation_search', name='url_operation_search'), | |
49 | url(r'^operation/(?P<id_camp>-?\d+)/radar/(?P<id_radar>-?\d+)/play/$', 'apps.main.views.radar_play', name='url_radar_play'), |
|
51 | url(r'^operation/(?P<id_camp>-?\d+)/radar/(?P<id_radar>-?\d+)/play/$', 'apps.main.views.radar_play', name='url_radar_play'), | |
50 | url(r'^operation/(?P<id_camp>-?\d+)/radar/(?P<id_radar>-?\d+)/stop/$', 'apps.main.views.radar_stop', name='url_radar_stop'), |
|
52 | url(r'^operation/(?P<id_camp>-?\d+)/radar/(?P<id_radar>-?\d+)/stop/$', 'apps.main.views.radar_stop', name='url_radar_stop'), | |
51 | url(r'^operation/(?P<id_camp>-?\d+)/radar/(?P<id_radar>-?\d+)/refresh/$', 'apps.main.views.radar_refresh', name='url_radar_refresh'), |
|
53 | url(r'^operation/(?P<id_camp>-?\d+)/radar/(?P<id_radar>-?\d+)/refresh/$', 'apps.main.views.radar_refresh', name='url_radar_refresh'), | |
52 |
|
54 | |||
53 | ) |
|
55 | ) |
@@ -1,1125 +1,1294 | |||||
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.utils.safestring import mark_safe | |||
2 | from django.http import HttpResponseRedirect |
|
3 | from django.http import HttpResponseRedirect | |
3 | from django.core.urlresolvers import reverse |
|
4 | from django.core.urlresolvers import reverse | |
4 | from django.contrib import messages |
|
5 | from django.contrib import messages | |
5 | from datetime import datetime |
|
6 | from datetime import datetime | |
6 |
|
7 | |||
7 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm, UploadFileForm, DownloadFileForm, OperationForm, NewForm |
|
8 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm, UploadFileForm, DownloadFileForm, OperationForm, NewForm | |
8 | from .forms import OperationSearchForm |
|
9 | from .forms import OperationSearchForm | |
9 | from apps.cgs.forms import CGSConfigurationForm |
|
10 | from apps.cgs.forms import CGSConfigurationForm | |
10 | from apps.jars.forms import JARSConfigurationForm |
|
11 | from apps.jars.forms import JARSConfigurationForm | |
11 | from apps.usrp.forms import USRPConfigurationForm |
|
12 | from apps.usrp.forms import USRPConfigurationForm | |
12 | from apps.abs.forms import ABSConfigurationForm |
|
13 | from apps.abs.forms import ABSConfigurationForm | |
13 | from apps.rc.forms import RCConfigurationForm |
|
14 | from apps.rc.forms import RCConfigurationForm, RCMixConfigurationForm | |
14 | from apps.dds.forms import DDSConfigurationForm |
|
15 | from apps.dds.forms import DDSConfigurationForm | |
15 |
|
16 | |||
16 | from .models import Campaign, Experiment, Device, Configuration, Location, RunningExperiment |
|
17 | from .models import Campaign, Experiment, Device, Configuration, Location, RunningExperiment | |
17 | from apps.cgs.models import CGSConfiguration |
|
18 | from apps.cgs.models import CGSConfiguration | |
18 | from apps.jars.models import JARSConfiguration |
|
19 | from apps.jars.models import JARSConfiguration | |
19 | from apps.usrp.models import USRPConfiguration |
|
20 | from apps.usrp.models import USRPConfiguration | |
20 | from apps.abs.models import ABSConfiguration |
|
21 | from apps.abs.models import ABSConfiguration | |
21 | from apps.rc.models import RCConfiguration |
|
22 | from apps.rc.models import RCConfiguration, RCLine, RCLineType | |
22 | from apps.dds.models import DDSConfiguration |
|
23 | from apps.dds.models import DDSConfiguration | |
23 |
|
24 | |||
24 | # Create your views here. |
|
25 | # Create your views here. | |
25 |
|
26 | |||
26 | CONF_FORMS = { |
|
27 | CONF_FORMS = { | |
27 | 'rc': RCConfigurationForm, |
|
28 | 'rc': RCConfigurationForm, | |
|
29 | 'rc_mix': RCMixConfigurationForm, | |||
28 | 'dds': DDSConfigurationForm, |
|
30 | 'dds': DDSConfigurationForm, | |
29 | 'jars': JARSConfigurationForm, |
|
31 | 'jars': JARSConfigurationForm, | |
30 | 'cgs': CGSConfigurationForm, |
|
32 | 'cgs': CGSConfigurationForm, | |
31 | 'abs': ABSConfigurationForm, |
|
33 | 'abs': ABSConfigurationForm, | |
32 | 'usrp': USRPConfigurationForm, |
|
34 | 'usrp': USRPConfigurationForm, | |
33 | } |
|
35 | } | |
34 |
|
36 | |||
35 | CONF_MODELS = { |
|
37 | CONF_MODELS = { | |
36 | 'rc': RCConfiguration, |
|
38 | 'rc': RCConfiguration, | |
37 | 'dds': DDSConfiguration, |
|
39 | 'dds': DDSConfiguration, | |
38 | 'jars': JARSConfiguration, |
|
40 | 'jars': JARSConfiguration, | |
39 | 'cgs': CGSConfiguration, |
|
41 | 'cgs': CGSConfiguration, | |
40 | 'abs': ABSConfiguration, |
|
42 | 'abs': ABSConfiguration, | |
41 | 'usrp': USRPConfiguration, |
|
43 | 'usrp': USRPConfiguration, | |
42 | } |
|
44 | } | |
43 |
|
45 | |||
|
46 | MIX_MODES = { | |||
|
47 | '0': 'OR', | |||
|
48 | '1': 'XOR', | |||
|
49 | '2': 'AND', | |||
|
50 | '3': 'NAND' | |||
|
51 | } | |||
|
52 | ||||
44 |
|
53 | |||
45 | def index(request): |
|
54 | def index(request): | |
46 | kwargs = {} |
|
55 | kwargs = {} | |
47 |
|
56 | |||
48 | return render(request, 'index.html', kwargs) |
|
57 | return render(request, 'index.html', kwargs) | |
49 |
|
58 | |||
50 |
|
59 | |||
51 | def locations(request): |
|
60 | def locations(request): | |
52 |
|
61 | |||
53 | locations = Location.objects.all().order_by('name') |
|
62 | locations = Location.objects.all().order_by('name') | |
54 |
|
63 | |||
55 | keys = ['id', 'name', 'description'] |
|
64 | keys = ['id', 'name', 'description'] | |
56 |
|
65 | |||
57 | kwargs = {} |
|
66 | kwargs = {} | |
58 | kwargs['location_keys'] = keys[1:] |
|
67 | kwargs['location_keys'] = keys[1:] | |
59 | kwargs['locations'] = locations |
|
68 | kwargs['locations'] = locations | |
60 | kwargs['title'] = 'Location' |
|
69 | kwargs['title'] = 'Location' | |
61 | kwargs['suptitle'] = 'List' |
|
70 | kwargs['suptitle'] = 'List' | |
62 | kwargs['button'] = 'New Location' |
|
71 | kwargs['button'] = 'New Location' | |
63 |
|
72 | |||
64 | return render(request, 'locations.html', kwargs) |
|
73 | return render(request, 'locations.html', kwargs) | |
65 |
|
74 | |||
66 |
|
75 | |||
67 | def location(request, id_loc): |
|
76 | def location(request, id_loc): | |
68 |
|
77 | |||
69 | location = get_object_or_404(Location, pk=id_loc) |
|
78 | location = get_object_or_404(Location, pk=id_loc) | |
70 |
|
79 | |||
71 | kwargs = {} |
|
80 | kwargs = {} | |
72 | kwargs['location'] = location |
|
81 | kwargs['location'] = location | |
73 | kwargs['location_keys'] = ['name', 'description'] |
|
82 | kwargs['location_keys'] = ['name', 'description'] | |
74 |
|
83 | |||
75 | kwargs['title'] = 'Location' |
|
84 | kwargs['title'] = 'Location' | |
76 | kwargs['suptitle'] = 'Details' |
|
85 | kwargs['suptitle'] = 'Details' | |
77 |
|
86 | |||
78 | return render(request, 'location.html', kwargs) |
|
87 | return render(request, 'location.html', kwargs) | |
79 |
|
88 | |||
80 |
|
89 | |||
81 | def location_new(request): |
|
90 | def location_new(request): | |
82 |
|
91 | |||
83 | if request.method == 'GET': |
|
92 | if request.method == 'GET': | |
84 | form = LocationForm() |
|
93 | form = LocationForm() | |
85 |
|
94 | |||
86 | if request.method == 'POST': |
|
95 | if request.method == 'POST': | |
87 | form = LocationForm(request.POST) |
|
96 | form = LocationForm(request.POST) | |
88 |
|
97 | |||
89 | if form.is_valid(): |
|
98 | if form.is_valid(): | |
90 | form.save() |
|
99 | form.save() | |
91 | return redirect('url_locations') |
|
100 | return redirect('url_locations') | |
92 |
|
101 | |||
93 | kwargs = {} |
|
102 | kwargs = {} | |
94 | kwargs['form'] = form |
|
103 | kwargs['form'] = form | |
95 | kwargs['title'] = 'Location' |
|
104 | kwargs['title'] = 'Location' | |
96 | kwargs['suptitle'] = 'New' |
|
105 | kwargs['suptitle'] = 'New' | |
97 | kwargs['button'] = 'Create' |
|
106 | kwargs['button'] = 'Create' | |
98 |
|
107 | |||
99 | return render(request, 'location_edit.html', kwargs) |
|
108 | return render(request, 'location_edit.html', kwargs) | |
100 |
|
109 | |||
101 |
|
110 | |||
102 | def location_edit(request, id_loc): |
|
111 | def location_edit(request, id_loc): | |
103 |
|
112 | |||
104 | location = get_object_or_404(Location, pk=id_loc) |
|
113 | location = get_object_or_404(Location, pk=id_loc) | |
105 |
|
114 | |||
106 | if request.method=='GET': |
|
115 | if request.method=='GET': | |
107 | form = LocationForm(instance=location) |
|
116 | form = LocationForm(instance=location) | |
108 |
|
117 | |||
109 | if request.method=='POST': |
|
118 | if request.method=='POST': | |
110 | form = LocationForm(request.POST, instance=location) |
|
119 | form = LocationForm(request.POST, instance=location) | |
111 |
|
120 | |||
112 | if form.is_valid(): |
|
121 | if form.is_valid(): | |
113 | form.save() |
|
122 | form.save() | |
114 | return redirect('url_locations') |
|
123 | return redirect('url_locations') | |
115 |
|
124 | |||
116 | kwargs = {} |
|
125 | kwargs = {} | |
117 | kwargs['form'] = form |
|
126 | kwargs['form'] = form | |
118 | kwargs['title'] = 'Location' |
|
127 | kwargs['title'] = 'Location' | |
119 | kwargs['suptitle'] = 'Edit' |
|
128 | kwargs['suptitle'] = 'Edit' | |
120 | kwargs['button'] = 'Update' |
|
129 | kwargs['button'] = 'Update' | |
121 |
|
130 | |||
122 | return render(request, 'location_edit.html', kwargs) |
|
131 | return render(request, 'location_edit.html', kwargs) | |
123 |
|
132 | |||
124 |
|
133 | |||
125 | def location_delete(request, id_loc): |
|
134 | def location_delete(request, id_loc): | |
126 |
|
135 | |||
127 | location = get_object_or_404(Location, pk=id_loc) |
|
136 | location = get_object_or_404(Location, pk=id_loc) | |
128 |
|
137 | |||
129 | if request.method=='POST': |
|
138 | if request.method=='POST': | |
130 |
|
139 | |||
131 | if request.user.is_staff: |
|
140 | if request.user.is_staff: | |
132 | location.delete() |
|
141 | location.delete() | |
133 | return redirect('url_locations') |
|
142 | return redirect('url_locations') | |
134 |
|
143 | |||
135 | messages.error(request, 'Not enough permission to delete this object') |
|
144 | messages.error(request, 'Not enough permission to delete this object') | |
136 | return redirect(location.get_absolute_url()) |
|
145 | return redirect(location.get_absolute_url()) | |
137 |
|
146 | |||
138 | kwargs = { |
|
147 | kwargs = { | |
139 | 'title': 'Delete', |
|
148 | 'title': 'Delete', | |
140 | 'suptitle': 'Location', |
|
149 | 'suptitle': 'Location', | |
141 | 'object': location, |
|
150 | 'object': location, | |
142 | 'previous': location.get_absolute_url(), |
|
151 | 'previous': location.get_absolute_url(), | |
143 | 'delete': True |
|
152 | 'delete': True | |
144 | } |
|
153 | } | |
145 |
|
154 | |||
146 | return render(request, 'confirm.html', kwargs) |
|
155 | return render(request, 'confirm.html', kwargs) | |
147 |
|
156 | |||
148 |
|
157 | |||
149 | def devices(request): |
|
158 | def devices(request): | |
150 |
|
159 | |||
151 | devices = Device.objects.all().order_by('device_type__name') |
|
160 | devices = Device.objects.all().order_by('device_type__name') | |
152 |
|
161 | |||
153 | # keys = ['id', 'device_type__name', 'name', 'ip_address'] |
|
162 | # keys = ['id', 'device_type__name', 'name', 'ip_address'] | |
154 | keys = ['id', 'name', 'ip_address', 'port_address', 'device_type'] |
|
163 | keys = ['id', 'name', 'ip_address', 'port_address', 'device_type'] | |
155 |
|
164 | |||
156 | kwargs = {} |
|
165 | kwargs = {} | |
157 | kwargs['device_keys'] = keys[1:] |
|
166 | kwargs['device_keys'] = keys[1:] | |
158 | kwargs['devices'] = devices#.values(*keys) |
|
167 | kwargs['devices'] = devices#.values(*keys) | |
159 | kwargs['title'] = 'Device' |
|
168 | kwargs['title'] = 'Device' | |
160 | kwargs['suptitle'] = 'List' |
|
169 | kwargs['suptitle'] = 'List' | |
161 | kwargs['button'] = 'New Device' |
|
170 | kwargs['button'] = 'New Device' | |
162 |
|
171 | |||
163 | return render(request, 'devices.html', kwargs) |
|
172 | return render(request, 'devices.html', kwargs) | |
164 |
|
173 | |||
165 |
|
174 | |||
166 | def device(request, id_dev): |
|
175 | def device(request, id_dev): | |
167 |
|
176 | |||
168 | device = get_object_or_404(Device, pk=id_dev) |
|
177 | device = get_object_or_404(Device, pk=id_dev) | |
169 |
|
178 | |||
170 | kwargs = {} |
|
179 | kwargs = {} | |
171 | kwargs['device'] = device |
|
180 | kwargs['device'] = device | |
172 | kwargs['device_keys'] = ['device_type', 'name', 'ip_address', 'port_address', 'description'] |
|
181 | kwargs['device_keys'] = ['device_type', 'name', 'ip_address', 'port_address', 'description'] | |
173 |
|
182 | |||
174 | kwargs['title'] = 'Device' |
|
183 | kwargs['title'] = 'Device' | |
175 | kwargs['suptitle'] = 'Details' |
|
184 | kwargs['suptitle'] = 'Details' | |
176 |
|
185 | |||
177 | return render(request, 'device.html', kwargs) |
|
186 | return render(request, 'device.html', kwargs) | |
178 |
|
187 | |||
179 |
|
188 | |||
180 | def device_new(request): |
|
189 | def device_new(request): | |
181 |
|
190 | |||
182 | if request.method == 'GET': |
|
191 | if request.method == 'GET': | |
183 | form = DeviceForm() |
|
192 | form = DeviceForm() | |
184 |
|
193 | |||
185 | if request.method == 'POST': |
|
194 | if request.method == 'POST': | |
186 | form = DeviceForm(request.POST) |
|
195 | form = DeviceForm(request.POST) | |
187 |
|
196 | |||
188 | if form.is_valid(): |
|
197 | if form.is_valid(): | |
189 | form.save() |
|
198 | form.save() | |
190 | return redirect('url_devices') |
|
199 | return redirect('url_devices') | |
191 |
|
200 | |||
192 | kwargs = {} |
|
201 | kwargs = {} | |
193 | kwargs['form'] = form |
|
202 | kwargs['form'] = form | |
194 | kwargs['title'] = 'Device' |
|
203 | kwargs['title'] = 'Device' | |
195 | kwargs['suptitle'] = 'New' |
|
204 | kwargs['suptitle'] = 'New' | |
196 | kwargs['button'] = 'Create' |
|
205 | kwargs['button'] = 'Create' | |
197 |
|
206 | |||
198 | return render(request, 'device_edit.html', kwargs) |
|
207 | return render(request, 'device_edit.html', kwargs) | |
199 |
|
208 | |||
200 |
|
209 | |||
201 | def device_edit(request, id_dev): |
|
210 | def device_edit(request, id_dev): | |
202 |
|
211 | |||
203 | device = get_object_or_404(Device, pk=id_dev) |
|
212 | device = get_object_or_404(Device, pk=id_dev) | |
204 |
|
213 | |||
205 | if request.method=='GET': |
|
214 | if request.method=='GET': | |
206 | form = DeviceForm(instance=device) |
|
215 | form = DeviceForm(instance=device) | |
207 |
|
216 | |||
208 | if request.method=='POST': |
|
217 | if request.method=='POST': | |
209 | form = DeviceForm(request.POST, instance=device) |
|
218 | form = DeviceForm(request.POST, instance=device) | |
210 |
|
219 | |||
211 | if form.is_valid(): |
|
220 | if form.is_valid(): | |
212 | form.save() |
|
221 | form.save() | |
213 | return redirect(device.get_absolute_url()) |
|
222 | return redirect(device.get_absolute_url()) | |
214 |
|
223 | |||
215 | kwargs = {} |
|
224 | kwargs = {} | |
216 | kwargs['form'] = form |
|
225 | kwargs['form'] = form | |
217 | kwargs['title'] = 'Device' |
|
226 | kwargs['title'] = 'Device' | |
218 | kwargs['suptitle'] = 'Edit' |
|
227 | kwargs['suptitle'] = 'Edit' | |
219 | kwargs['button'] = 'Update' |
|
228 | kwargs['button'] = 'Update' | |
220 |
|
229 | |||
221 | return render(request, 'device_edit.html', kwargs) |
|
230 | return render(request, 'device_edit.html', kwargs) | |
222 |
|
231 | |||
223 |
|
232 | |||
224 | def device_delete(request, id_dev): |
|
233 | def device_delete(request, id_dev): | |
225 |
|
234 | |||
226 | device = get_object_or_404(Device, pk=id_dev) |
|
235 | device = get_object_or_404(Device, pk=id_dev) | |
227 |
|
236 | |||
228 | if request.method=='POST': |
|
237 | if request.method=='POST': | |
229 |
|
238 | |||
230 | if request.user.is_staff: |
|
239 | if request.user.is_staff: | |
231 | device.delete() |
|
240 | device.delete() | |
232 | return redirect('url_devices') |
|
241 | return redirect('url_devices') | |
233 |
|
242 | |||
234 | messages.error(request, 'Not enough permission to delete this object') |
|
243 | messages.error(request, 'Not enough permission to delete this object') | |
235 | return redirect(device.get_absolute_url()) |
|
244 | return redirect(device.get_absolute_url()) | |
236 |
|
245 | |||
237 | kwargs = { |
|
246 | kwargs = { | |
238 | 'title': 'Delete', |
|
247 | 'title': 'Delete', | |
239 | 'suptitle': 'Device', |
|
248 | 'suptitle': 'Device', | |
240 | 'object': device, |
|
249 | 'object': device, | |
241 | 'previous': device.get_absolute_url(), |
|
250 | 'previous': device.get_absolute_url(), | |
242 | 'delete': True |
|
251 | 'delete': True | |
243 | } |
|
252 | } | |
244 |
|
253 | |||
245 | return render(request, 'confirm.html', kwargs) |
|
254 | return render(request, 'confirm.html', kwargs) | |
246 |
|
255 | |||
247 |
|
256 | |||
248 | def campaigns(request): |
|
257 | def campaigns(request): | |
249 |
|
258 | |||
250 | campaigns = Campaign.objects.all().order_by('start_date') |
|
259 | campaigns = Campaign.objects.all().order_by('start_date') | |
251 |
|
260 | |||
252 | keys = ['id', 'name', 'start_date', 'end_date'] |
|
261 | keys = ['id', 'name', 'start_date', 'end_date'] | |
253 |
|
262 | |||
254 | kwargs = {} |
|
263 | kwargs = {} | |
255 | kwargs['campaign_keys'] = keys[1:] |
|
264 | kwargs['campaign_keys'] = keys[1:] | |
256 | kwargs['campaigns'] = campaigns#.values(*keys) |
|
265 | kwargs['campaigns'] = campaigns#.values(*keys) | |
257 | kwargs['title'] = 'Campaign' |
|
266 | kwargs['title'] = 'Campaign' | |
258 | kwargs['suptitle'] = 'List' |
|
267 | kwargs['suptitle'] = 'List' | |
259 | kwargs['button'] = 'New Campaign' |
|
268 | kwargs['button'] = 'New Campaign' | |
260 |
|
269 | |||
261 | return render(request, 'campaigns.html', kwargs) |
|
270 | return render(request, 'campaigns.html', kwargs) | |
262 |
|
271 | |||
263 |
|
272 | |||
264 | def campaign(request, id_camp): |
|
273 | def campaign(request, id_camp): | |
265 |
|
274 | |||
266 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
275 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
267 | experiments = Experiment.objects.filter(campaign=campaign) |
|
276 | experiments = Experiment.objects.filter(campaign=campaign) | |
268 |
|
277 | |||
269 | form = CampaignForm(instance=campaign) |
|
278 | form = CampaignForm(instance=campaign) | |
270 |
|
279 | |||
271 | kwargs = {} |
|
280 | kwargs = {} | |
272 | kwargs['campaign'] = campaign |
|
281 | kwargs['campaign'] = campaign | |
273 | kwargs['campaign_keys'] = ['template', 'name', 'start_date', 'end_date', 'tags', 'description'] |
|
282 | kwargs['campaign_keys'] = ['template', 'name', 'start_date', 'end_date', 'tags', 'description'] | |
274 |
|
283 | |||
275 | kwargs['experiments'] = experiments |
|
284 | kwargs['experiments'] = experiments | |
276 | kwargs['experiment_keys'] = ['name', 'radar', 'start_time', 'end_time'] |
|
285 | kwargs['experiment_keys'] = ['name', 'radar', 'start_time', 'end_time'] | |
277 |
|
286 | |||
278 | kwargs['title'] = 'Campaign' |
|
287 | kwargs['title'] = 'Campaign' | |
279 | kwargs['suptitle'] = 'Details' |
|
288 | kwargs['suptitle'] = 'Details' | |
280 |
|
289 | |||
281 | kwargs['form'] = form |
|
290 | kwargs['form'] = form | |
282 | kwargs['button'] = 'Add Experiment' |
|
291 | kwargs['button'] = 'Add Experiment' | |
283 |
|
292 | |||
284 | return render(request, 'campaign.html', kwargs) |
|
293 | return render(request, 'campaign.html', kwargs) | |
285 |
|
294 | |||
286 |
|
295 | |||
287 | def campaign_new(request): |
|
296 | def campaign_new(request): | |
288 |
|
297 | |||
289 | kwargs = {} |
|
298 | kwargs = {} | |
290 |
|
299 | |||
291 | if request.method == 'GET': |
|
300 | if request.method == 'GET': | |
292 |
|
301 | |||
293 | if 'template' in request.GET: |
|
302 | if 'template' in request.GET: | |
294 | if request.GET['template']=='0': |
|
303 | if request.GET['template']=='0': | |
295 | form = NewForm(initial={'create_from':2}, |
|
304 | form = NewForm(initial={'create_from':2}, | |
296 | template_choices=Campaign.objects.filter(template=True).values_list('id', 'name')) |
|
305 | template_choices=Campaign.objects.filter(template=True).values_list('id', 'name')) | |
297 | else: |
|
306 | else: | |
298 | kwargs['button'] = 'Create' |
|
307 | kwargs['button'] = 'Create' | |
299 | kwargs['experiments'] = Configuration.objects.filter(experiment=request.GET['template']) |
|
308 | kwargs['experiments'] = Configuration.objects.filter(experiment=request.GET['template']) | |
300 | kwargs['experiment_keys'] = ['name', 'start_time', 'end_time'] |
|
309 | kwargs['experiment_keys'] = ['name', 'start_time', 'end_time'] | |
301 | camp = Campaign.objects.get(pk=request.GET['template']) |
|
310 | camp = Campaign.objects.get(pk=request.GET['template']) | |
302 | form = CampaignForm(instance=camp, |
|
311 | form = CampaignForm(instance=camp, | |
303 | initial={'name':'{} [{:%Y/%m/%d}]'.format(camp.name, datetime.now()), |
|
312 | initial={'name':'{} [{:%Y/%m/%d}]'.format(camp.name, datetime.now()), | |
304 | 'template':False}) |
|
313 | 'template':False}) | |
305 | elif 'blank' in request.GET: |
|
314 | elif 'blank' in request.GET: | |
306 | kwargs['button'] = 'Create' |
|
315 | kwargs['button'] = 'Create' | |
307 | form = CampaignForm() |
|
316 | form = CampaignForm() | |
308 | else: |
|
317 | else: | |
309 | form = NewForm() |
|
318 | form = NewForm() | |
310 |
|
319 | |||
311 | if request.method == 'POST': |
|
320 | if request.method == 'POST': | |
312 | kwargs['button'] = 'Create' |
|
321 | kwargs['button'] = 'Create' | |
313 | post = request.POST.copy() |
|
322 | post = request.POST.copy() | |
314 | experiments = [] |
|
323 | experiments = [] | |
315 |
|
324 | |||
316 | for id_exp in post.getlist('experiments'): |
|
325 | for id_exp in post.getlist('experiments'): | |
317 | exp = Experiment.objects.get(pk=id_exp) |
|
326 | exp = Experiment.objects.get(pk=id_exp) | |
318 | new_exp = exp.clone(template=False) |
|
327 | new_exp = exp.clone(template=False) | |
319 | experiments.append(new_exp) |
|
328 | experiments.append(new_exp) | |
320 |
|
329 | |||
321 | post.setlist('experiments', []) |
|
330 | post.setlist('experiments', []) | |
322 |
|
331 | |||
323 | form = CampaignForm(post) |
|
332 | form = CampaignForm(post) | |
324 |
|
333 | |||
325 | if form.is_valid(): |
|
334 | if form.is_valid(): | |
326 | campaign = form.save() |
|
335 | campaign = form.save() | |
327 | for exp in experiments: |
|
336 | for exp in experiments: | |
328 | campaign.experiments.add(exp) |
|
337 | campaign.experiments.add(exp) | |
329 | campaign.save() |
|
338 | campaign.save() | |
330 | return redirect('url_campaign', id_camp=campaign.id) |
|
339 | return redirect('url_campaign', id_camp=campaign.id) | |
331 |
|
340 | |||
332 | kwargs['form'] = form |
|
341 | kwargs['form'] = form | |
333 | kwargs['title'] = 'Campaign' |
|
342 | kwargs['title'] = 'Campaign' | |
334 | kwargs['suptitle'] = 'New' |
|
343 | kwargs['suptitle'] = 'New' | |
335 |
|
344 | |||
336 | return render(request, 'campaign_edit.html', kwargs) |
|
345 | return render(request, 'campaign_edit.html', kwargs) | |
337 |
|
346 | |||
338 |
|
347 | |||
339 | def campaign_edit(request, id_camp): |
|
348 | def campaign_edit(request, id_camp): | |
340 |
|
349 | |||
341 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
350 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
342 |
|
351 | |||
343 | if request.method=='GET': |
|
352 | if request.method=='GET': | |
344 | form = CampaignForm(instance=campaign) |
|
353 | form = CampaignForm(instance=campaign) | |
345 |
|
354 | |||
346 | if request.method=='POST': |
|
355 | if request.method=='POST': | |
347 | exps = campaign.experiments.all().values_list('pk', flat=True) |
|
356 | exps = campaign.experiments.all().values_list('pk', flat=True) | |
348 | post = request.POST.copy() |
|
357 | post = request.POST.copy() | |
349 | new_exps = post.getlist('experiments') |
|
358 | new_exps = post.getlist('experiments') | |
350 | post.setlist('experiments', []) |
|
359 | post.setlist('experiments', []) | |
351 | form = CampaignForm(post, instance=campaign) |
|
360 | form = CampaignForm(post, instance=campaign) | |
352 |
|
361 | |||
353 | if form.is_valid(): |
|
362 | if form.is_valid(): | |
354 | camp = form.save() |
|
363 | camp = form.save() | |
355 | for id_exp in new_exps: |
|
364 | for id_exp in new_exps: | |
356 | if int(id_exp) in exps: |
|
365 | if int(id_exp) in exps: | |
357 | exps.pop(id_exp) |
|
366 | exps.pop(id_exp) | |
358 | else: |
|
367 | else: | |
359 | exp = Experiment.objects.get(pk=id_exp) |
|
368 | exp = Experiment.objects.get(pk=id_exp) | |
360 | if exp.template: |
|
369 | if exp.template: | |
361 | camp.experiments.add(exp.clone(template=False)) |
|
370 | camp.experiments.add(exp.clone(template=False)) | |
362 | else: |
|
371 | else: | |
363 | camp.experiments.add(exp) |
|
372 | camp.experiments.add(exp) | |
364 |
|
373 | |||
365 | for id_exp in exps: |
|
374 | for id_exp in exps: | |
366 | camp.experiments.remove(Experiment.objects.get(pk=id_exp)) |
|
375 | camp.experiments.remove(Experiment.objects.get(pk=id_exp)) | |
367 |
|
376 | |||
368 | return redirect('url_campaign', id_camp=id_camp) |
|
377 | return redirect('url_campaign', id_camp=id_camp) | |
369 |
|
378 | |||
370 | kwargs = {} |
|
379 | kwargs = {} | |
371 | kwargs['form'] = form |
|
380 | kwargs['form'] = form | |
372 | kwargs['title'] = 'Campaign' |
|
381 | kwargs['title'] = 'Campaign' | |
373 | kwargs['suptitle'] = 'Edit' |
|
382 | kwargs['suptitle'] = 'Edit' | |
374 | kwargs['button'] = 'Update' |
|
383 | kwargs['button'] = 'Update' | |
375 |
|
384 | |||
376 | return render(request, 'campaign_edit.html', kwargs) |
|
385 | return render(request, 'campaign_edit.html', kwargs) | |
377 |
|
386 | |||
378 |
|
387 | |||
379 | def campaign_delete(request, id_camp): |
|
388 | def campaign_delete(request, id_camp): | |
380 |
|
389 | |||
381 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
390 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
382 |
|
391 | |||
383 | if request.method=='POST': |
|
392 | if request.method=='POST': | |
384 | if request.user.is_staff: |
|
393 | if request.user.is_staff: | |
385 |
|
394 | |||
386 | for exp in campaign.experiments.all(): |
|
395 | for exp in campaign.experiments.all(): | |
387 | for conf in Configuration.objects.filter(experiment=exp): |
|
396 | for conf in Configuration.objects.filter(experiment=exp): | |
388 | conf.delete() |
|
397 | conf.delete() | |
389 | exp.delete() |
|
398 | exp.delete() | |
390 | campaign.delete() |
|
399 | campaign.delete() | |
391 |
|
400 | |||
392 | return redirect('url_campaigns') |
|
401 | return redirect('url_campaigns') | |
393 |
|
402 | |||
394 | messages.error(request, 'Not enough permission to delete this object') |
|
403 | messages.error(request, 'Not enough permission to delete this object') | |
395 | return redirect(campaign.get_absolute_url()) |
|
404 | return redirect(campaign.get_absolute_url()) | |
396 |
|
405 | |||
397 | kwargs = { |
|
406 | kwargs = { | |
398 | 'title': 'Delete', |
|
407 | 'title': 'Delete', | |
399 | 'suptitle': 'Campaign', |
|
408 | 'suptitle': 'Campaign', | |
400 | 'object': campaign, |
|
409 | 'object': campaign, | |
401 | 'previous': campaign.get_absolute_url(), |
|
410 | 'previous': campaign.get_absolute_url(), | |
402 | 'delete': True |
|
411 | 'delete': True | |
403 | } |
|
412 | } | |
404 |
|
413 | |||
405 | return render(request, 'confirm.html', kwargs) |
|
414 | return render(request, 'confirm.html', kwargs) | |
406 |
|
415 | |||
407 | def campaign_export(request, id_camp): |
|
416 | def campaign_export(request, id_camp): | |
408 |
|
417 | |||
409 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
418 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
410 | content = campaign.parms_to_dict() |
|
419 | content = campaign.parms_to_dict() | |
411 | content_type = 'application/json' |
|
420 | content_type = 'application/json' | |
412 | filename = '%s_%s.json' %(campaign.name, campaign.id) |
|
421 | filename = '%s_%s.json' %(campaign.name, campaign.id) | |
413 |
|
422 | |||
414 | response = HttpResponse(content_type=content_type) |
|
423 | response = HttpResponse(content_type=content_type) | |
415 | response['Content-Disposition'] = 'attachment; filename="%s"' %filename |
|
424 | response['Content-Disposition'] = 'attachment; filename="%s"' %filename | |
416 | response.write(content) |
|
425 | response.write(content) | |
417 |
|
426 | |||
418 | return response |
|
427 | return response | |
419 |
|
428 | |||
420 | def experiments(request): |
|
429 | def experiments(request): | |
421 |
|
430 | |||
422 | experiment_list = Experiment.objects.all() |
|
431 | experiment_list = Experiment.objects.all() | |
423 |
|
432 | |||
424 | keys = ['id', 'name', 'start_time', 'end_time'] |
|
433 | keys = ['id', 'name', 'start_time', 'end_time'] | |
425 |
|
434 | |||
426 | kwargs = {} |
|
435 | kwargs = {} | |
427 |
|
436 | |||
428 | kwargs['experiment_keys'] = keys[1:] |
|
437 | kwargs['experiment_keys'] = keys[1:] | |
429 | kwargs['experiments'] = experiment_list |
|
438 | kwargs['experiments'] = experiment_list | |
430 |
|
439 | |||
431 | kwargs['title'] = 'Experiment' |
|
440 | kwargs['title'] = 'Experiment' | |
432 | kwargs['suptitle'] = 'List' |
|
441 | kwargs['suptitle'] = 'List' | |
433 | kwargs['button'] = 'New Experiment' |
|
442 | kwargs['button'] = 'New Experiment' | |
434 |
|
443 | |||
435 | return render(request, 'experiments.html', kwargs) |
|
444 | return render(request, 'experiments.html', kwargs) | |
436 |
|
445 | |||
437 |
|
446 | |||
438 | def experiment(request, id_exp): |
|
447 | def experiment(request, id_exp): | |
439 |
|
448 | |||
440 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
449 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
441 |
|
450 | |||
442 | configurations = Configuration.objects.filter(experiment=experiment, type=0) |
|
451 | configurations = Configuration.objects.filter(experiment=experiment, type=0) | |
443 |
|
452 | |||
444 | kwargs = {} |
|
453 | kwargs = {} | |
445 |
|
454 | |||
446 | kwargs['experiment_keys'] = ['template', 'radar', 'name', 'start_time', 'end_time'] |
|
455 | kwargs['experiment_keys'] = ['template', 'radar', 'name', 'start_time', 'end_time'] | |
447 | kwargs['experiment'] = experiment |
|
456 | kwargs['experiment'] = experiment | |
448 |
|
457 | |||
449 |
kwargs['configuration_keys'] = [' |
|
458 | kwargs['configuration_keys'] = ['name', 'device__device_type', 'device__ip_address', 'device__port_address'] | |
450 | kwargs['configurations'] = configurations |
|
459 | kwargs['configurations'] = configurations | |
451 |
|
460 | |||
452 | kwargs['title'] = 'Experiment' |
|
461 | kwargs['title'] = 'Experiment' | |
453 | kwargs['suptitle'] = 'Details' |
|
462 | kwargs['suptitle'] = 'Details' | |
454 |
|
463 | |||
455 | kwargs['button'] = 'Add Configuration' |
|
464 | kwargs['button'] = 'Add Configuration' | |
456 |
|
465 | |||
457 | ###### SIDEBAR ###### |
|
466 | ###### SIDEBAR ###### | |
458 | kwargs.update(sidebar(experiment=experiment)) |
|
467 | kwargs.update(sidebar(experiment=experiment)) | |
459 |
|
468 | |||
460 | return render(request, 'experiment.html', kwargs) |
|
469 | return render(request, 'experiment.html', kwargs) | |
461 |
|
470 | |||
462 |
|
471 | |||
463 | def experiment_new(request, id_camp=None): |
|
472 | def experiment_new(request, id_camp=None): | |
464 |
|
473 | |||
465 | kwargs = {} |
|
474 | kwargs = {} | |
466 |
|
475 | |||
467 | if request.method == 'GET': |
|
476 | if request.method == 'GET': | |
468 | if 'template' in request.GET: |
|
477 | if 'template' in request.GET: | |
469 | if request.GET['template']=='0': |
|
478 | if request.GET['template']=='0': | |
470 | form = NewForm(initial={'create_from':2}, |
|
479 | form = NewForm(initial={'create_from':2}, | |
471 | template_choices=Experiment.objects.filter(template=True).values_list('id', 'name')) |
|
480 | template_choices=Experiment.objects.filter(template=True).values_list('id', 'name')) | |
472 | else: |
|
481 | else: | |
473 | kwargs['button'] = 'Create' |
|
482 | kwargs['button'] = 'Create' | |
474 | kwargs['configurations'] = Configuration.objects.filter(experiment=request.GET['template']) |
|
483 | kwargs['configurations'] = Configuration.objects.filter(experiment=request.GET['template']) | |
475 | kwargs['configuration_keys'] = ['name', 'device__name', 'device__ip_address', 'device__port_address'] |
|
484 | kwargs['configuration_keys'] = ['name', 'device__name', 'device__ip_address', 'device__port_address'] | |
476 | exp=Experiment.objects.get(pk=request.GET['template']) |
|
485 | exp=Experiment.objects.get(pk=request.GET['template']) | |
477 | form = ExperimentForm(instance=exp, |
|
486 | form = ExperimentForm(instance=exp, | |
478 | initial={'name': '{} [{:%Y/%m/%d}]'.format(exp.name, datetime.now()), |
|
487 | initial={'name': '{} [{:%Y/%m/%d}]'.format(exp.name, datetime.now()), | |
479 | 'template': False}) |
|
488 | 'template': False}) | |
480 | elif 'blank' in request.GET: |
|
489 | elif 'blank' in request.GET: | |
481 | kwargs['button'] = 'Create' |
|
490 | kwargs['button'] = 'Create' | |
482 | form = ExperimentForm() |
|
491 | form = ExperimentForm() | |
483 | else: |
|
492 | else: | |
484 | form = NewForm() |
|
493 | form = NewForm() | |
485 |
|
494 | |||
486 | if request.method == 'POST': |
|
495 | if request.method == 'POST': | |
487 | form = ExperimentForm(request.POST) |
|
496 | form = ExperimentForm(request.POST) | |
488 | if form.is_valid(): |
|
497 | if form.is_valid(): | |
489 | experiment = form.save() |
|
498 | experiment = form.save() | |
490 |
|
499 | |||
491 | if 'template' in request.GET: |
|
500 | if 'template' in request.GET: | |
492 | configurations = Configuration.objects.filter(experiment=request.GET['template'], type=0) |
|
501 | configurations = Configuration.objects.filter(experiment=request.GET['template'], type=0) | |
493 | for conf in configurations: |
|
502 | for conf in configurations: | |
494 | conf.clone(experiment=experiment, template=False) |
|
503 | conf.clone(experiment=experiment, template=False) | |
495 |
|
504 | |||
496 | return redirect('url_experiment', id_exp=experiment.id) |
|
505 | return redirect('url_experiment', id_exp=experiment.id) | |
497 |
|
506 | |||
498 | kwargs['form'] = form |
|
507 | kwargs['form'] = form | |
499 | kwargs['title'] = 'Experiment' |
|
508 | kwargs['title'] = 'Experiment' | |
500 | kwargs['suptitle'] = 'New' |
|
509 | kwargs['suptitle'] = 'New' | |
501 |
|
510 | |||
502 | return render(request, 'experiment_edit.html', kwargs) |
|
511 | return render(request, 'experiment_edit.html', kwargs) | |
503 |
|
512 | |||
504 |
|
513 | |||
505 | def experiment_edit(request, id_exp): |
|
514 | def experiment_edit(request, id_exp): | |
506 |
|
515 | |||
507 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
516 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
508 |
|
517 | |||
509 | if request.method == 'GET': |
|
518 | if request.method == 'GET': | |
510 | form = ExperimentForm(instance=experiment) |
|
519 | form = ExperimentForm(instance=experiment) | |
511 |
|
520 | |||
512 | if request.method=='POST': |
|
521 | if request.method=='POST': | |
513 | form = ExperimentForm(request.POST, instance=experiment) |
|
522 | form = ExperimentForm(request.POST, instance=experiment) | |
514 |
|
523 | |||
515 | if form.is_valid(): |
|
524 | if form.is_valid(): | |
516 | experiment = form.save() |
|
525 | experiment = form.save() | |
517 | return redirect('url_experiment', id_exp=experiment.id) |
|
526 | return redirect('url_experiment', id_exp=experiment.id) | |
518 |
|
527 | |||
519 | kwargs = {} |
|
528 | kwargs = {} | |
520 | kwargs['form'] = form |
|
529 | kwargs['form'] = form | |
521 | kwargs['title'] = 'Experiment' |
|
530 | kwargs['title'] = 'Experiment' | |
522 | kwargs['suptitle'] = 'Edit' |
|
531 | kwargs['suptitle'] = 'Edit' | |
523 | kwargs['button'] = 'Update' |
|
532 | kwargs['button'] = 'Update' | |
524 |
|
533 | |||
525 | return render(request, 'experiment_edit.html', kwargs) |
|
534 | return render(request, 'experiment_edit.html', kwargs) | |
526 |
|
535 | |||
527 |
|
536 | |||
528 | def experiment_delete(request, id_exp): |
|
537 | def experiment_delete(request, id_exp): | |
529 |
|
538 | |||
530 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
539 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
531 |
|
540 | |||
532 | if request.method=='POST': |
|
541 | if request.method=='POST': | |
533 | if request.user.is_staff: |
|
542 | if request.user.is_staff: | |
534 | for conf in Configuration.objects.filter(experiment=experiment): |
|
543 | for conf in Configuration.objects.filter(experiment=experiment): | |
535 | conf.delete() |
|
544 | conf.delete() | |
536 | experiment.delete() |
|
545 | experiment.delete() | |
537 | return redirect('url_experiments') |
|
546 | return redirect('url_experiments') | |
538 |
|
547 | |||
539 | messages.error(request, 'Not enough permission to delete this object') |
|
548 | messages.error(request, 'Not enough permission to delete this object') | |
540 | return redirect(experiment.get_absolute_url()) |
|
549 | return redirect(experiment.get_absolute_url()) | |
541 |
|
550 | |||
542 | kwargs = { |
|
551 | kwargs = { | |
543 | 'title': 'Delete', |
|
552 | 'title': 'Delete', | |
544 | 'suptitle': 'Experiment', |
|
553 | 'suptitle': 'Experiment', | |
545 | 'object': experiment, |
|
554 | 'object': experiment, | |
546 | 'previous': experiment.get_absolute_url(), |
|
555 | 'previous': experiment.get_absolute_url(), | |
547 | 'delete': True |
|
556 | 'delete': True | |
548 | } |
|
557 | } | |
549 |
|
558 | |||
550 | return render(request, 'confirm.html', kwargs) |
|
559 | return render(request, 'confirm.html', kwargs) | |
551 |
|
560 | |||
552 |
|
561 | |||
553 | def experiment_export(request, id_exp): |
|
562 | def experiment_export(request, id_exp): | |
554 |
|
563 | |||
555 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
564 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
556 | content = experiment.parms_to_dict() |
|
565 | content = experiment.parms_to_dict() | |
557 | content_type = 'application/json' |
|
566 | content_type = 'application/json' | |
558 | filename = '%s_%s.json' %(experiment.name, experiment.id) |
|
567 | filename = '%s_%s.json' %(experiment.name, experiment.id) | |
559 |
|
568 | |||
560 | response = HttpResponse(content_type=content_type) |
|
569 | response = HttpResponse(content_type=content_type) | |
561 | response['Content-Disposition'] = 'attachment; filename="%s"' %filename |
|
570 | response['Content-Disposition'] = 'attachment; filename="%s"' %filename | |
562 | response.write(content) |
|
571 | response.write(content) | |
563 |
|
572 | |||
564 | return response |
|
573 | return response | |
565 |
|
574 | |||
566 |
|
575 | |||
|
576 | def experiment_mix(request, id_exp): | |||
|
577 | ||||
|
578 | experiment = get_object_or_404(Experiment, pk=id_exp) | |||
|
579 | rc_confs = [conf for conf in RCConfiguration.objects.filter(experiment=id_exp, | |||
|
580 | mix=False)] | |||
|
581 | ||||
|
582 | if len(rc_confs)<2: | |||
|
583 | messages.warning(request, 'You need at least two RC Configurations to make a mix') | |||
|
584 | return redirect(experiment.get_absolute_url()) | |||
|
585 | ||||
|
586 | mix_confs = RCConfiguration.objects.filter(experiment=id_exp, mix=True) | |||
|
587 | ||||
|
588 | if mix_confs: | |||
|
589 | mix = mix_confs[0] | |||
|
590 | else: | |||
|
591 | mix = RCConfiguration(experiment=experiment, | |||
|
592 | device=rc_confs[0].device, | |||
|
593 | ipp=rc_confs[0].ipp, | |||
|
594 | clock_in=rc_confs[0].clock_in, | |||
|
595 | clock_divider=rc_confs[0].clock_divider, | |||
|
596 | mix=True, | |||
|
597 | parameters='') | |||
|
598 | mix.save() | |||
|
599 | ||||
|
600 | line_type = RCLineType.objects.get(name='mix') | |||
|
601 | for i in range(len(rc_confs[0].get_lines())): | |||
|
602 | line = RCLine(rc_configuration=mix, line_type=line_type, channel=i) | |||
|
603 | line.save() | |||
|
604 | ||||
|
605 | initial = {'name': mix.name, | |||
|
606 | 'result': parse_mix_result(mix.parameters), | |||
|
607 | 'delay': 0, | |||
|
608 | 'mask': [0,1,2,3,4,5,6,7] | |||
|
609 | } | |||
|
610 | ||||
|
611 | if request.method=='GET': | |||
|
612 | form = RCMixConfigurationForm(confs=rc_confs, initial=initial) | |||
|
613 | ||||
|
614 | if request.method=='POST': | |||
|
615 | ||||
|
616 | result = mix.parameters | |||
|
617 | ||||
|
618 | if '{}|'.format(request.POST['experiment']) in result: | |||
|
619 | messages.error(request, 'Configuration already added') | |||
|
620 | else: | |||
|
621 | if result: | |||
|
622 | result = '{}-{}|{}|{}|{}'.format(mix.parameters, | |||
|
623 | request.POST['experiment'], | |||
|
624 | MIX_MODES[request.POST['operation']], | |||
|
625 | float(request.POST['delay']), | |||
|
626 | parse_mask(request.POST.getlist('mask')) | |||
|
627 | ) | |||
|
628 | else: | |||
|
629 | result = '{}|{}|{}|{}'.format(request.POST['experiment'], | |||
|
630 | MIX_MODES[request.POST['operation']], | |||
|
631 | float(request.POST['delay']), | |||
|
632 | parse_mask(request.POST.getlist('mask')) | |||
|
633 | ) | |||
|
634 | ||||
|
635 | mix.parameters = result | |||
|
636 | mix.name = request.POST['name'] | |||
|
637 | mix.save() | |||
|
638 | mix.update_pulses() | |||
|
639 | ||||
|
640 | ||||
|
641 | initial['result'] = parse_mix_result(result) | |||
|
642 | initial['name'] = mix.name | |||
|
643 | ||||
|
644 | form = RCMixConfigurationForm(initial=initial, confs=rc_confs) | |||
|
645 | ||||
|
646 | ||||
|
647 | kwargs = { | |||
|
648 | 'title': 'Experiment', | |||
|
649 | 'suptitle': 'Mix Configurations', | |||
|
650 | 'form' : form, | |||
|
651 | 'extra_button': 'Delete', | |||
|
652 | 'button': 'Add', | |||
|
653 | 'cancel': 'Back', | |||
|
654 | 'previous': experiment.get_absolute_url(), | |||
|
655 | 'id_exp':id_exp, | |||
|
656 | ||||
|
657 | } | |||
|
658 | ||||
|
659 | return render(request, 'experiment_mix.html', kwargs) | |||
|
660 | ||||
|
661 | ||||
|
662 | def experiment_mix_delete(request, id_exp): | |||
|
663 | ||||
|
664 | conf = RCConfiguration.objects.get(experiment=id_exp, mix=True) | |||
|
665 | values = conf.parameters.split('-') | |||
|
666 | conf.parameters = '-'.join(values[:-1]) | |||
|
667 | conf.save() | |||
|
668 | ||||
|
669 | return redirect('url_mix_experiment', id_exp=id_exp) | |||
|
670 | ||||
|
671 | ||||
|
672 | def parse_mix_result(s): | |||
|
673 | ||||
|
674 | values = s.split('-') | |||
|
675 | html = '' | |||
|
676 | ||||
|
677 | ||||
|
678 | for i, value in enumerate(values): | |||
|
679 | if not value: | |||
|
680 | continue | |||
|
681 | pk, mode, delay, mask = value.split('|') | |||
|
682 | conf = RCConfiguration.objects.get(pk=pk) | |||
|
683 | if i==0: | |||
|
684 | html += '{:20.18}{:4}{:9}km{:>6}\r\n'.format( | |||
|
685 | conf.name[:18], | |||
|
686 | '---', | |||
|
687 | delay, | |||
|
688 | mask) | |||
|
689 | else: | |||
|
690 | html += '{:20.18}{:4}{:9}km{:>6}\r\n'.format( | |||
|
691 | conf.name[:18], | |||
|
692 | mode, | |||
|
693 | delay, | |||
|
694 | mask) | |||
|
695 | ||||
|
696 | return mark_safe(html) | |||
|
697 | ||||
|
698 | def parse_mask(l): | |||
|
699 | ||||
|
700 | values = [] | |||
|
701 | ||||
|
702 | for x in range(8): | |||
|
703 | if '{}'.format(x) in l: | |||
|
704 | values.append(1) | |||
|
705 | else: | |||
|
706 | values.append(0) | |||
|
707 | ||||
|
708 | values.reverse() | |||
|
709 | ||||
|
710 | return int(''.join([str(x) for x in values]), 2) | |||
|
711 | ||||
|
712 | ||||
567 | def dev_confs(request): |
|
713 | def dev_confs(request): | |
568 |
|
714 | |||
569 | configurations = Configuration.objects.all().order_by('type', 'device__device_type', 'experiment') |
|
715 | configurations = Configuration.objects.all().order_by('type', 'device__device_type', 'experiment') | |
570 |
|
716 | |||
571 | kwargs = {} |
|
717 | kwargs = {} | |
572 |
|
718 | |||
573 | kwargs['configuration_keys'] = ['device', 'experiment', 'type', 'programmed_date'] |
|
719 | kwargs['configuration_keys'] = ['device', 'name', 'experiment', 'type', 'programmed_date'] | |
574 | kwargs['configurations'] = configurations |
|
720 | kwargs['configurations'] = configurations | |
575 |
|
721 | |||
576 | kwargs['title'] = 'Configuration' |
|
722 | kwargs['title'] = 'Configuration' | |
577 | kwargs['suptitle'] = 'List' |
|
723 | kwargs['suptitle'] = 'List' | |
578 |
|
724 | |||
579 | return render(request, 'dev_confs.html', kwargs) |
|
725 | return render(request, 'dev_confs.html', kwargs) | |
580 |
|
726 | |||
581 |
|
727 | |||
582 | def dev_conf(request, id_conf): |
|
728 | def dev_conf(request, id_conf): | |
583 |
|
729 | |||
584 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
730 | conf = get_object_or_404(Configuration, pk=id_conf) | |
585 |
|
731 | |||
586 | return redirect(conf.get_absolute_url()) |
|
732 | return redirect(conf.get_absolute_url()) | |
587 |
|
733 | |||
588 |
|
734 | |||
589 | def dev_conf_new(request, id_exp=0, id_dev=0): |
|
735 | def dev_conf_new(request, id_exp=0, id_dev=0): | |
590 |
|
736 | |||
591 | initial = {} |
|
737 | initial = {} | |
|
738 | kwargs = {} | |||
592 |
|
739 | |||
593 | if id_exp<>0: |
|
740 | if id_exp<>0: | |
594 | initial['experiment'] = id_exp |
|
741 | initial['experiment'] = id_exp | |
595 |
|
742 | |||
596 | if id_dev<>0: |
|
743 | if id_dev<>0: | |
597 | initial['device'] = id_dev |
|
744 | initial['device'] = id_dev | |
598 |
|
745 | |||
599 | if request.method == 'GET': |
|
746 | if request.method == 'GET': | |
600 | if id_dev==0: |
|
747 | ||
601 | form = ConfigurationForm(initial=initial) |
|
748 | if id_dev: | |
602 | else: |
|
749 | kwargs['button'] = 'Create' | |
603 | device = Device.objects.get(pk=id_dev) |
|
750 | device = Device.objects.get(pk=id_dev) | |
604 | DevConfForm = CONF_FORMS[device.device_type.name] |
|
751 | DevConfForm = CONF_FORMS[device.device_type.name] | |
605 |
|
752 | initial['name'] = request.GET['name'] | ||
606 | form = DevConfForm(initial=initial) |
|
753 | form = DevConfForm(initial=initial) | |
|
754 | else: | |||
|
755 | if 'template' in request.GET: | |||
|
756 | if request.GET['template']=='0': | |||
|
757 | form = NewForm(initial={'create_from':2}, | |||
|
758 | template_choices=Configuration.objects.filter(template=True).values_list('id', 'name')) | |||
|
759 | else: | |||
|
760 | kwargs['button'] = 'Create' | |||
|
761 | conf = Configuration.objects.get(pk=request.GET['template']) | |||
|
762 | DevConfForm = CONF_FORMS[conf.device.device_type.name] | |||
|
763 | form = DevConfForm(instance=conf, | |||
|
764 | initial={'name': '{} [{:%Y/%m/%d}]'.format(conf.name, datetime.now()), | |||
|
765 | 'template': False}) | |||
|
766 | elif 'blank' in request.GET: | |||
|
767 | kwargs['button'] = 'Create' | |||
|
768 | form = ConfigurationForm(initial=initial) | |||
|
769 | else: | |||
|
770 | form = NewForm() | |||
607 |
|
771 | |||
608 | if request.method == 'POST': |
|
772 | if request.method == 'POST': | |
609 |
|
773 | |||
610 | device = Device.objects.get(pk=request.POST['device']) |
|
774 | device = Device.objects.get(pk=request.POST['device']) | |
611 | DevConfForm = CONF_FORMS[device.device_type.name] |
|
775 | DevConfForm = CONF_FORMS[device.device_type.name] | |
612 |
|
776 | |||
613 | form = DevConfForm(request.POST) |
|
777 | form = DevConfForm(request.POST) | |
614 |
|
778 | |||
615 | if form.is_valid(): |
|
779 | if form.is_valid(): | |
616 |
|
|
780 | conf = form.save() | |
617 |
|
781 | |||
618 | return redirect('url_dev_confs') |
|
782 | if 'template' in request.GET and conf.device.device_type.name=='rc': | |
|
783 | lines = RCLine.objects.filter(rc_configuration=request.GET['template']) | |||
|
784 | for line in lines: | |||
|
785 | line.clone(rc_configuration=conf) | |||
|
786 | ||||
|
787 | return redirect('url_dev_conf', id_conf=conf.pk) | |||
619 |
|
788 | |||
620 | kwargs = {} |
|
789 | ||
621 | kwargs['id_exp'] = id_exp |
|
790 | kwargs['id_exp'] = id_exp | |
622 | kwargs['form'] = form |
|
791 | kwargs['form'] = form | |
623 | kwargs['title'] = 'Configuration' |
|
792 | kwargs['title'] = 'Configuration' | |
624 | kwargs['suptitle'] = 'New' |
|
793 | kwargs['suptitle'] = 'New' | |
625 | kwargs['button'] = 'Create' |
|
794 | ||
626 |
|
795 | |||
627 | if id_dev != 0: |
|
796 | if id_dev != 0: | |
628 | device = Device.objects.get(pk=id_dev) |
|
797 | device = Device.objects.get(pk=id_dev) | |
629 | if 'dds' in device.device_type.name: |
|
798 | if 'dds' in device.device_type.name: | |
630 | kwargs['dds_device'] = True |
|
799 | kwargs['dds_device'] = True | |
631 |
|
800 | |||
632 | return render(request, 'dev_conf_edit.html', kwargs) |
|
801 | return render(request, 'dev_conf_edit.html', kwargs) | |
633 |
|
802 | |||
634 |
|
803 | |||
635 | def dev_conf_edit(request, id_conf): |
|
804 | def dev_conf_edit(request, id_conf): | |
636 |
|
805 | |||
637 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
806 | conf = get_object_or_404(Configuration, pk=id_conf) | |
638 |
|
807 | |||
639 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
808 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
640 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
809 | DevConfForm = CONF_FORMS[conf.device.device_type.name] | |
641 |
|
810 | |||
642 | dev_conf = DevConfModel.objects.get(pk=id_conf) |
|
811 | dev_conf = DevConfModel.objects.get(pk=id_conf) | |
643 |
|
812 | |||
644 | if request.method=='GET': |
|
813 | if request.method=='GET': | |
645 | form = DevConfForm(instance=dev_conf) |
|
814 | form = DevConfForm(instance=dev_conf) | |
646 |
|
815 | |||
647 | if request.method=='POST': |
|
816 | if request.method=='POST': | |
648 | form = DevConfForm(request.POST, instance=dev_conf) |
|
817 | form = DevConfForm(request.POST, instance=dev_conf) | |
649 |
|
818 | |||
650 | if form.is_valid(): |
|
819 | if form.is_valid(): | |
651 | form.save() |
|
820 | form.save() | |
652 | return redirect('url_dev_conf', id_conf=id_conf) |
|
821 | return redirect('url_dev_conf', id_conf=id_conf) | |
653 |
|
822 | |||
654 | kwargs = {} |
|
823 | kwargs = {} | |
655 | kwargs['form'] = form |
|
824 | kwargs['form'] = form | |
656 | kwargs['title'] = 'Device Configuration' |
|
825 | kwargs['title'] = 'Device Configuration' | |
657 | kwargs['suptitle'] = 'Edit' |
|
826 | kwargs['suptitle'] = 'Edit' | |
658 | kwargs['button'] = 'Update' |
|
827 | kwargs['button'] = 'Update' | |
659 |
|
828 | |||
660 | ###### SIDEBAR ###### |
|
829 | ###### SIDEBAR ###### | |
661 | kwargs.update(sidebar(conf=conf)) |
|
830 | kwargs.update(sidebar(conf=conf)) | |
662 |
|
831 | |||
663 | return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs) |
|
832 | return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs) | |
664 |
|
833 | |||
665 |
|
834 | |||
666 | def dev_conf_start(request, id_conf): |
|
835 | def dev_conf_start(request, id_conf): | |
667 |
|
836 | |||
668 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
837 | conf = get_object_or_404(Configuration, pk=id_conf) | |
669 |
|
838 | |||
670 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
839 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
671 |
|
840 | |||
672 | conf = DevConfModel.objects.get(pk=id_conf) |
|
841 | conf = DevConfModel.objects.get(pk=id_conf) | |
673 |
|
842 | |||
674 | if conf.start_device(): |
|
843 | if conf.start_device(): | |
675 | messages.success(request, conf.message) |
|
844 | messages.success(request, conf.message) | |
676 | else: |
|
845 | else: | |
677 | messages.error(request, conf.message) |
|
846 | messages.error(request, conf.message) | |
678 |
|
847 | |||
679 | conf.status_device() |
|
848 | conf.status_device() | |
680 |
|
849 | |||
681 | return redirect(conf.get_absolute_url()) |
|
850 | return redirect(conf.get_absolute_url()) | |
682 |
|
851 | |||
683 |
|
852 | |||
684 | def dev_conf_stop(request, id_conf): |
|
853 | def dev_conf_stop(request, id_conf): | |
685 |
|
854 | |||
686 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
855 | conf = get_object_or_404(Configuration, pk=id_conf) | |
687 |
|
856 | |||
688 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
857 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
689 |
|
858 | |||
690 | conf = DevConfModel.objects.get(pk=id_conf) |
|
859 | conf = DevConfModel.objects.get(pk=id_conf) | |
691 |
|
860 | |||
692 | if conf.stop_device(): |
|
861 | if conf.stop_device(): | |
693 | messages.success(request, conf.message) |
|
862 | messages.success(request, conf.message) | |
694 | else: |
|
863 | else: | |
695 | messages.error(request, conf.message) |
|
864 | messages.error(request, conf.message) | |
696 |
|
865 | |||
697 | conf.status_device() |
|
866 | conf.status_device() | |
698 |
|
867 | |||
699 | return redirect(conf.get_absolute_url()) |
|
868 | return redirect(conf.get_absolute_url()) | |
700 |
|
869 | |||
701 |
|
870 | |||
702 | def dev_conf_status(request, id_conf): |
|
871 | def dev_conf_status(request, id_conf): | |
703 |
|
872 | |||
704 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
873 | conf = get_object_or_404(Configuration, pk=id_conf) | |
705 |
|
874 | |||
706 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
875 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
707 |
|
876 | |||
708 | conf = DevConfModel.objects.get(pk=id_conf) |
|
877 | conf = DevConfModel.objects.get(pk=id_conf) | |
709 |
|
878 | |||
710 | if conf.status_device(): |
|
879 | if conf.status_device(): | |
711 | messages.success(request, conf.message) |
|
880 | messages.success(request, conf.message) | |
712 | else: |
|
881 | else: | |
713 | messages.error(request, conf.message) |
|
882 | messages.error(request, conf.message) | |
714 |
|
883 | |||
715 | return redirect(conf.get_absolute_url()) |
|
884 | return redirect(conf.get_absolute_url()) | |
716 |
|
885 | |||
717 |
|
886 | |||
718 | def dev_conf_write(request, id_conf): |
|
887 | def dev_conf_write(request, id_conf): | |
719 |
|
888 | |||
720 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
889 | conf = get_object_or_404(Configuration, pk=id_conf) | |
721 |
|
890 | |||
722 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
891 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
723 |
|
892 | |||
724 | conf = DevConfModel.objects.get(pk=id_conf) |
|
893 | conf = DevConfModel.objects.get(pk=id_conf) | |
725 |
|
894 | |||
726 | answer = conf.write_device() |
|
895 | answer = conf.write_device() | |
727 | conf.status_device() |
|
896 | conf.status_device() | |
728 |
|
897 | |||
729 | if answer: |
|
898 | if answer: | |
730 | messages.success(request, conf.message) |
|
899 | messages.success(request, conf.message) | |
731 |
|
900 | |||
732 | #Creating a historical configuration |
|
901 | #Creating a historical configuration | |
733 | conf.clone(type=0, template=False) |
|
902 | conf.clone(type=0, template=False) | |
734 |
|
903 | |||
735 | #Original configuration |
|
904 | #Original configuration | |
736 | conf = DevConfModel.objects.get(pk=id_conf) |
|
905 | conf = DevConfModel.objects.get(pk=id_conf) | |
737 | else: |
|
906 | else: | |
738 | messages.error(request, conf.message) |
|
907 | messages.error(request, conf.message) | |
739 |
|
908 | |||
740 | return redirect(conf.get_absolute_url()) |
|
909 | return redirect(conf.get_absolute_url()) | |
741 |
|
910 | |||
742 |
|
911 | |||
743 | def dev_conf_read(request, id_conf): |
|
912 | def dev_conf_read(request, id_conf): | |
744 |
|
913 | |||
745 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
914 | conf = get_object_or_404(Configuration, pk=id_conf) | |
746 |
|
915 | |||
747 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
916 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
748 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
917 | DevConfForm = CONF_FORMS[conf.device.device_type.name] | |
749 |
|
918 | |||
750 | conf = DevConfModel.objects.get(pk=id_conf) |
|
919 | conf = DevConfModel.objects.get(pk=id_conf) | |
751 |
|
920 | |||
752 | if request.method=='GET': |
|
921 | if request.method=='GET': | |
753 |
|
922 | |||
754 | parms = conf.read_device() |
|
923 | parms = conf.read_device() | |
755 | conf.status_device() |
|
924 | conf.status_device() | |
756 |
|
925 | |||
757 | if not parms: |
|
926 | if not parms: | |
758 | messages.error(request, conf.message) |
|
927 | messages.error(request, conf.message) | |
759 | return redirect(conf.get_absolute_url()) |
|
928 | return redirect(conf.get_absolute_url()) | |
760 |
|
929 | |||
761 | form = DevConfForm(initial=parms, instance=conf) |
|
930 | form = DevConfForm(initial=parms, instance=conf) | |
762 |
|
931 | |||
763 | if request.method=='POST': |
|
932 | if request.method=='POST': | |
764 | form = DevConfForm(request.POST, instance=conf) |
|
933 | form = DevConfForm(request.POST, instance=conf) | |
765 |
|
934 | |||
766 | if form.is_valid(): |
|
935 | if form.is_valid(): | |
767 | form.save() |
|
936 | form.save() | |
768 | return redirect(conf.get_absolute_url()) |
|
937 | return redirect(conf.get_absolute_url()) | |
769 |
|
938 | |||
770 | messages.error(request, "Parameters could not be saved") |
|
939 | messages.error(request, "Parameters could not be saved") | |
771 |
|
940 | |||
772 | kwargs = {} |
|
941 | kwargs = {} | |
773 | kwargs['id_dev'] = conf.id |
|
942 | kwargs['id_dev'] = conf.id | |
774 | kwargs['form'] = form |
|
943 | kwargs['form'] = form | |
775 | kwargs['title'] = 'Device Configuration' |
|
944 | kwargs['title'] = 'Device Configuration' | |
776 | kwargs['suptitle'] = 'Parameters read from device' |
|
945 | kwargs['suptitle'] = 'Parameters read from device' | |
777 | kwargs['button'] = 'Save' |
|
946 | kwargs['button'] = 'Save' | |
778 |
|
947 | |||
779 | ###### SIDEBAR ###### |
|
948 | ###### SIDEBAR ###### | |
780 | kwargs.update(sidebar(conf=conf)) |
|
949 | kwargs.update(sidebar(conf=conf)) | |
781 |
|
950 | |||
782 | return render(request, '%s_conf_edit.html' %conf.device.device_type.name, kwargs) |
|
951 | return render(request, '%s_conf_edit.html' %conf.device.device_type.name, kwargs) | |
783 |
|
952 | |||
784 |
|
953 | |||
785 | def dev_conf_import(request, id_conf): |
|
954 | def dev_conf_import(request, id_conf): | |
786 |
|
955 | |||
787 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
956 | conf = get_object_or_404(Configuration, pk=id_conf) | |
788 |
|
957 | |||
789 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
958 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
790 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
959 | DevConfForm = CONF_FORMS[conf.device.device_type.name] | |
791 | conf = DevConfModel.objects.get(pk=id_conf) |
|
960 | conf = DevConfModel.objects.get(pk=id_conf) | |
792 |
|
961 | |||
793 | if request.method == 'GET': |
|
962 | if request.method == 'GET': | |
794 | file_form = UploadFileForm() |
|
963 | file_form = UploadFileForm() | |
795 |
|
964 | |||
796 | if request.method == 'POST': |
|
965 | if request.method == 'POST': | |
797 | file_form = UploadFileForm(request.POST, request.FILES) |
|
966 | file_form = UploadFileForm(request.POST, request.FILES) | |
798 |
|
967 | |||
799 | if file_form.is_valid(): |
|
968 | if file_form.is_valid(): | |
800 |
|
969 | |||
801 | parms = conf.import_from_file(request.FILES['file']) |
|
970 | parms = conf.import_from_file(request.FILES['file']) | |
802 |
|
971 | |||
803 | if parms: |
|
972 | if parms: | |
804 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) |
|
973 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) | |
805 | form = DevConfForm(initial=parms, instance=conf) |
|
974 | form = DevConfForm(initial=parms, instance=conf) | |
806 |
|
975 | |||
807 | kwargs = {} |
|
976 | kwargs = {} | |
808 | kwargs['id_dev'] = conf.id |
|
977 | kwargs['id_dev'] = conf.id | |
809 | kwargs['form'] = form |
|
978 | kwargs['form'] = form | |
810 | kwargs['title'] = 'Device Configuration' |
|
979 | kwargs['title'] = 'Device Configuration' | |
811 | kwargs['suptitle'] = 'Parameters imported' |
|
980 | kwargs['suptitle'] = 'Parameters imported' | |
812 | kwargs['button'] = 'Save' |
|
981 | kwargs['button'] = 'Save' | |
813 | kwargs['action'] = conf.get_absolute_url_edit() |
|
982 | kwargs['action'] = conf.get_absolute_url_edit() | |
814 | kwargs['previous'] = conf.get_absolute_url() |
|
983 | kwargs['previous'] = conf.get_absolute_url() | |
815 |
|
984 | |||
816 | ###### SIDEBAR ###### |
|
985 | ###### SIDEBAR ###### | |
817 | kwargs.update(sidebar(conf=conf)) |
|
986 | kwargs.update(sidebar(conf=conf)) | |
818 |
|
987 | |||
819 | return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs) |
|
988 | return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs) | |
820 |
|
989 | |||
821 | messages.error(request, "Could not import parameters from file") |
|
990 | messages.error(request, "Could not import parameters from file") | |
822 |
|
991 | |||
823 | kwargs = {} |
|
992 | kwargs = {} | |
824 | kwargs['id_dev'] = conf.id |
|
993 | kwargs['id_dev'] = conf.id | |
825 | kwargs['title'] = 'Device Configuration' |
|
994 | kwargs['title'] = 'Device Configuration' | |
826 | kwargs['form'] = file_form |
|
995 | kwargs['form'] = file_form | |
827 | kwargs['suptitle'] = 'Importing file' |
|
996 | kwargs['suptitle'] = 'Importing file' | |
828 | kwargs['button'] = 'Import' |
|
997 | kwargs['button'] = 'Import' | |
829 |
|
998 | |||
830 | kwargs.update(sidebar(conf=conf)) |
|
999 | kwargs.update(sidebar(conf=conf)) | |
831 |
|
1000 | |||
832 | return render(request, 'dev_conf_import.html', kwargs) |
|
1001 | return render(request, 'dev_conf_import.html', kwargs) | |
833 |
|
1002 | |||
834 |
|
1003 | |||
835 | def dev_conf_export(request, id_conf): |
|
1004 | def dev_conf_export(request, id_conf): | |
836 |
|
1005 | |||
837 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1006 | conf = get_object_or_404(Configuration, pk=id_conf) | |
838 |
|
1007 | |||
839 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
1008 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
840 |
|
1009 | |||
841 | conf = DevConfModel.objects.get(pk=id_conf) |
|
1010 | conf = DevConfModel.objects.get(pk=id_conf) | |
842 |
|
1011 | |||
843 | if request.method == 'GET': |
|
1012 | if request.method == 'GET': | |
844 | file_form = DownloadFileForm(conf.device.device_type.name) |
|
1013 | file_form = DownloadFileForm(conf.device.device_type.name) | |
845 |
|
1014 | |||
846 | if request.method == 'POST': |
|
1015 | if request.method == 'POST': | |
847 | file_form = DownloadFileForm(conf.device.device_type.name, request.POST) |
|
1016 | file_form = DownloadFileForm(conf.device.device_type.name, request.POST) | |
848 |
|
1017 | |||
849 | if file_form.is_valid(): |
|
1018 | if file_form.is_valid(): | |
850 | fields = conf.export_to_file(format = file_form.cleaned_data['format']) |
|
1019 | fields = conf.export_to_file(format = file_form.cleaned_data['format']) | |
851 |
|
1020 | |||
852 | response = HttpResponse(content_type=fields['content_type']) |
|
1021 | response = HttpResponse(content_type=fields['content_type']) | |
853 | response['Content-Disposition'] = 'attachment; filename="%s"' %fields['filename'] |
|
1022 | response['Content-Disposition'] = 'attachment; filename="%s"' %fields['filename'] | |
854 | response.write(fields['content']) |
|
1023 | response.write(fields['content']) | |
855 |
|
1024 | |||
856 | return response |
|
1025 | return response | |
857 |
|
1026 | |||
858 | messages.error(request, "Could not export parameters") |
|
1027 | messages.error(request, "Could not export parameters") | |
859 |
|
1028 | |||
860 | kwargs = {} |
|
1029 | kwargs = {} | |
861 | kwargs['id_dev'] = conf.id |
|
1030 | kwargs['id_dev'] = conf.id | |
862 | kwargs['title'] = 'Device Configuration' |
|
1031 | kwargs['title'] = 'Device Configuration' | |
863 | kwargs['form'] = file_form |
|
1032 | kwargs['form'] = file_form | |
864 | kwargs['suptitle'] = 'Exporting file' |
|
1033 | kwargs['suptitle'] = 'Exporting file' | |
865 | kwargs['button'] = 'Export' |
|
1034 | kwargs['button'] = 'Export' | |
866 |
|
1035 | |||
867 | return render(request, 'dev_conf_export.html', kwargs) |
|
1036 | return render(request, 'dev_conf_export.html', kwargs) | |
868 |
|
1037 | |||
869 |
|
1038 | |||
870 | def dev_conf_delete(request, id_conf): |
|
1039 | def dev_conf_delete(request, id_conf): | |
871 |
|
1040 | |||
872 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1041 | conf = get_object_or_404(Configuration, pk=id_conf) | |
873 |
|
1042 | |||
874 | if request.method=='POST': |
|
1043 | if request.method=='POST': | |
875 | if request.user.is_staff: |
|
1044 | if request.user.is_staff: | |
876 | conf.delete() |
|
1045 | conf.delete() | |
877 | return redirect('url_dev_confs') |
|
1046 | return redirect('url_dev_confs') | |
878 |
|
1047 | |||
879 | messages.error(request, 'Not enough permission to delete this object') |
|
1048 | messages.error(request, 'Not enough permission to delete this object') | |
880 | return redirect(conf.get_absolute_url()) |
|
1049 | return redirect(conf.get_absolute_url()) | |
881 |
|
1050 | |||
882 | kwargs = { |
|
1051 | kwargs = { | |
883 | 'title': 'Delete', |
|
1052 | 'title': 'Delete', | |
884 | 'suptitle': 'Experiment', |
|
1053 | 'suptitle': 'Experiment', | |
885 | 'object': conf, |
|
1054 | 'object': conf, | |
886 | 'previous': conf.get_absolute_url(), |
|
1055 | 'previous': conf.get_absolute_url(), | |
887 | 'delete': True |
|
1056 | 'delete': True | |
888 | } |
|
1057 | } | |
889 |
|
1058 | |||
890 | return render(request, 'confirm.html', kwargs) |
|
1059 | return render(request, 'confirm.html', kwargs) | |
891 |
|
1060 | |||
892 |
|
1061 | |||
893 | def sidebar(**kwargs): |
|
1062 | def sidebar(**kwargs): | |
894 |
|
1063 | |||
895 | side_data = {} |
|
1064 | side_data = {} | |
896 |
|
1065 | |||
897 | conf = kwargs.get('conf', None) |
|
1066 | conf = kwargs.get('conf', None) | |
898 | experiment = kwargs.get('experiment', None) |
|
1067 | experiment = kwargs.get('experiment', None) | |
899 |
|
1068 | |||
900 | if not experiment: |
|
1069 | if not experiment: | |
901 | experiment = conf.experiment |
|
1070 | experiment = conf.experiment | |
902 |
|
1071 | |||
903 | if experiment: |
|
1072 | if experiment: | |
904 | side_data['experiment'] = experiment |
|
1073 | side_data['experiment'] = experiment | |
905 | campaign = experiment.campaign_set.all() |
|
1074 | campaign = experiment.campaign_set.all() | |
906 | if campaign: |
|
1075 | if campaign: | |
907 | side_data['campaign'] = campaign[0] |
|
1076 | side_data['campaign'] = campaign[0] | |
908 | experiments = campaign[0].experiments.all() |
|
1077 | experiments = campaign[0].experiments.all() | |
909 | else: |
|
1078 | else: | |
910 | experiments = [experiment] |
|
1079 | experiments = [experiment] | |
911 | configurations = experiment.configuration_set.filter(type=0) |
|
1080 | configurations = experiment.configuration_set.filter(type=0) | |
912 | side_data['side_experiments'] = experiments |
|
1081 | side_data['side_experiments'] = experiments | |
913 | side_data['side_configurations'] = configurations |
|
1082 | side_data['side_configurations'] = configurations | |
914 |
|
1083 | |||
915 | return side_data |
|
1084 | return side_data | |
916 |
|
1085 | |||
917 |
|
1086 | |||
918 | def operation(request, id_camp=None): |
|
1087 | def operation(request, id_camp=None): | |
919 |
|
1088 | |||
920 | if not id_camp: |
|
1089 | if not id_camp: | |
921 | campaigns = Campaign.objects.all().order_by('-start_date') |
|
1090 | campaigns = Campaign.objects.all().order_by('-start_date') | |
922 |
|
1091 | |||
923 | if not campaigns: |
|
1092 | if not campaigns: | |
924 | kwargs = {} |
|
1093 | kwargs = {} | |
925 | kwargs['title'] = 'No Campaigns' |
|
1094 | kwargs['title'] = 'No Campaigns' | |
926 | kwargs['suptitle'] = 'Empty' |
|
1095 | kwargs['suptitle'] = 'Empty' | |
927 | return render(request, 'operation.html', kwargs) |
|
1096 | return render(request, 'operation.html', kwargs) | |
928 |
|
1097 | |||
929 | id_camp = campaigns[0].id |
|
1098 | id_camp = campaigns[0].id | |
930 |
|
1099 | |||
931 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
1100 | campaign = get_object_or_404(Campaign, pk = id_camp) | |
932 |
|
1101 | |||
933 | if request.method=='GET': |
|
1102 | if request.method=='GET': | |
934 | form = OperationForm(initial={'campaign': campaign.id}, length = 5) |
|
1103 | form = OperationForm(initial={'campaign': campaign.id}, length = 5) | |
935 |
|
1104 | |||
936 | if request.method=='POST': |
|
1105 | if request.method=='POST': | |
937 | form = OperationForm(request.POST, initial={'campaign':campaign.id}, length = 5) |
|
1106 | form = OperationForm(request.POST, initial={'campaign':campaign.id}, length = 5) | |
938 |
|
1107 | |||
939 | if form.is_valid(): |
|
1108 | if form.is_valid(): | |
940 | return redirect('url_operation', id_camp=campaign.id) |
|
1109 | return redirect('url_operation', id_camp=campaign.id) | |
941 | #locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct() |
|
1110 | #locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct() | |
942 | experiments = Experiment.objects.filter(campaign__pk=campaign.id) |
|
1111 | experiments = Experiment.objects.filter(campaign__pk=campaign.id) | |
943 | #for exs in experiments: |
|
1112 | #for exs in experiments: | |
944 | # exs.get_status() |
|
1113 | # exs.get_status() | |
945 | locations= Location.objects.filter(experiment=experiments).distinct() |
|
1114 | locations= Location.objects.filter(experiment=experiments).distinct() | |
946 | #experiments = [Experiment.objects.filter(location__pk=location.id).filter(campaign__pk=campaign.id) for location in locations] |
|
1115 | #experiments = [Experiment.objects.filter(location__pk=location.id).filter(campaign__pk=campaign.id) for location in locations] | |
947 | kwargs = {} |
|
1116 | kwargs = {} | |
948 | #---Campaign |
|
1117 | #---Campaign | |
949 | kwargs['campaign'] = campaign |
|
1118 | kwargs['campaign'] = campaign | |
950 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] |
|
1119 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] | |
951 | #---Experiment |
|
1120 | #---Experiment | |
952 | keys = ['id', 'name', 'start_time', 'end_time', 'status'] |
|
1121 | keys = ['id', 'name', 'start_time', 'end_time', 'status'] | |
953 | kwargs['experiment_keys'] = keys[1:] |
|
1122 | kwargs['experiment_keys'] = keys[1:] | |
954 | kwargs['experiments'] = experiments |
|
1123 | kwargs['experiments'] = experiments | |
955 | #---Radar |
|
1124 | #---Radar | |
956 | kwargs['locations'] = locations |
|
1125 | kwargs['locations'] = locations | |
957 | #---Else |
|
1126 | #---Else | |
958 | kwargs['title'] = 'Campaign' |
|
1127 | kwargs['title'] = 'Campaign' | |
959 | kwargs['suptitle'] = campaign.name |
|
1128 | kwargs['suptitle'] = campaign.name | |
960 | kwargs['form'] = form |
|
1129 | kwargs['form'] = form | |
961 | kwargs['button'] = 'Search' |
|
1130 | kwargs['button'] = 'Search' | |
962 | kwargs['details'] = True |
|
1131 | kwargs['details'] = True | |
963 | kwargs['search_button'] = True |
|
1132 | kwargs['search_button'] = True | |
964 |
|
1133 | |||
965 | return render(request, 'operation.html', kwargs) |
|
1134 | return render(request, 'operation.html', kwargs) | |
966 |
|
1135 | |||
967 |
|
1136 | |||
968 | def operation_search(request, id_camp=None): |
|
1137 | def operation_search(request, id_camp=None): | |
969 |
|
1138 | |||
970 |
|
1139 | |||
971 | if not id_camp: |
|
1140 | if not id_camp: | |
972 | campaigns = Campaign.objects.all().order_by('-start_date') |
|
1141 | campaigns = Campaign.objects.all().order_by('-start_date') | |
973 |
|
1142 | |||
974 | if not campaigns: |
|
1143 | if not campaigns: | |
975 | return render(request, 'operation.html', {}) |
|
1144 | return render(request, 'operation.html', {}) | |
976 |
|
1145 | |||
977 | id_camp = campaigns[0].id |
|
1146 | id_camp = campaigns[0].id | |
978 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
1147 | campaign = get_object_or_404(Campaign, pk = id_camp) | |
979 |
|
1148 | |||
980 | if request.method=='GET': |
|
1149 | if request.method=='GET': | |
981 | form = OperationSearchForm(initial={'campaign': campaign.id}) |
|
1150 | form = OperationSearchForm(initial={'campaign': campaign.id}) | |
982 |
|
1151 | |||
983 | if request.method=='POST': |
|
1152 | if request.method=='POST': | |
984 | form = OperationSearchForm(request.POST, initial={'campaign':campaign.id}) |
|
1153 | form = OperationSearchForm(request.POST, initial={'campaign':campaign.id}) | |
985 |
|
1154 | |||
986 | if form.is_valid(): |
|
1155 | if form.is_valid(): | |
987 | return redirect('url_operation', id_camp=campaign.id) |
|
1156 | return redirect('url_operation', id_camp=campaign.id) | |
988 |
|
1157 | |||
989 | #locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct() |
|
1158 | #locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct() | |
990 | experiments = Experiment.objects.filter(campaign__pk=campaign.id) |
|
1159 | experiments = Experiment.objects.filter(campaign__pk=campaign.id) | |
991 | #for exs in experiments: |
|
1160 | #for exs in experiments: | |
992 | # exs.get_status() |
|
1161 | # exs.get_status() | |
993 | locations= Location.objects.filter(experiment=experiments).distinct() |
|
1162 | locations= Location.objects.filter(experiment=experiments).distinct() | |
994 | form = OperationSearchForm(initial={'campaign': campaign.id}) |
|
1163 | form = OperationSearchForm(initial={'campaign': campaign.id}) | |
995 |
|
1164 | |||
996 | kwargs = {} |
|
1165 | kwargs = {} | |
997 | #---Campaign |
|
1166 | #---Campaign | |
998 | kwargs['campaign'] = campaign |
|
1167 | kwargs['campaign'] = campaign | |
999 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] |
|
1168 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] | |
1000 | #---Experiment |
|
1169 | #---Experiment | |
1001 | keys = ['id', 'name', 'start_time', 'end_time', 'status'] |
|
1170 | keys = ['id', 'name', 'start_time', 'end_time', 'status'] | |
1002 | kwargs['experiment_keys'] = keys[1:] |
|
1171 | kwargs['experiment_keys'] = keys[1:] | |
1003 | kwargs['experiments'] = experiments |
|
1172 | kwargs['experiments'] = experiments | |
1004 | #---Radar |
|
1173 | #---Radar | |
1005 | kwargs['locations'] = locations |
|
1174 | kwargs['locations'] = locations | |
1006 | #---Else |
|
1175 | #---Else | |
1007 | kwargs['title'] = 'Campaign' |
|
1176 | kwargs['title'] = 'Campaign' | |
1008 | kwargs['suptitle'] = campaign.name |
|
1177 | kwargs['suptitle'] = campaign.name | |
1009 | kwargs['form'] = form |
|
1178 | kwargs['form'] = form | |
1010 | kwargs['button'] = 'Select' |
|
1179 | kwargs['button'] = 'Select' | |
1011 | kwargs['details'] = True |
|
1180 | kwargs['details'] = True | |
1012 | kwargs['search_button'] = False |
|
1181 | kwargs['search_button'] = False | |
1013 |
|
1182 | |||
1014 | return render(request, 'operation.html', kwargs) |
|
1183 | return render(request, 'operation.html', kwargs) | |
1015 |
|
1184 | |||
1016 |
|
1185 | |||
1017 | def radar_play(request, id_camp, id_radar): |
|
1186 | def radar_play(request, id_camp, id_radar): | |
1018 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
1187 | campaign = get_object_or_404(Campaign, pk = id_camp) | |
1019 | radar = get_object_or_404(Location, pk = id_radar) |
|
1188 | radar = get_object_or_404(Location, pk = id_radar) | |
1020 | today = datetime.today() |
|
1189 | today = datetime.today() | |
1021 | now = today.time() |
|
1190 | now = today.time() | |
1022 |
|
1191 | |||
1023 | #--Clear Old Experiments From RunningExperiment Object |
|
1192 | #--Clear Old Experiments From RunningExperiment Object | |
1024 | running_experiment = RunningExperiment.objects.filter(radar=radar) |
|
1193 | running_experiment = RunningExperiment.objects.filter(radar=radar) | |
1025 | if running_experiment: |
|
1194 | if running_experiment: | |
1026 | running_experiment = running_experiment[0] |
|
1195 | running_experiment = running_experiment[0] | |
1027 | running_experiment.running_experiment.clear() |
|
1196 | running_experiment.running_experiment.clear() | |
1028 | running_experiment.save() |
|
1197 | running_experiment.save() | |
1029 |
|
1198 | |||
1030 | #--If campaign datetime is ok: |
|
1199 | #--If campaign datetime is ok: | |
1031 | if today >= campaign.start_date and today <= campaign.end_date: |
|
1200 | if today >= campaign.start_date and today <= campaign.end_date: | |
1032 | experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) |
|
1201 | experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) | |
1033 | for exp in experiments: |
|
1202 | for exp in experiments: | |
1034 | #--If experiment time is ok: |
|
1203 | #--If experiment time is ok: | |
1035 | if now >= exp.start_time and now <= exp.end_time: |
|
1204 | if now >= exp.start_time and now <= exp.end_time: | |
1036 | configurations = Configuration.objects.filter(experiment = exp) |
|
1205 | configurations = Configuration.objects.filter(experiment = exp) | |
1037 | for conf in configurations: |
|
1206 | for conf in configurations: | |
1038 | if 'cgs' in conf.device.device_type.name: |
|
1207 | if 'cgs' in conf.device.device_type.name: | |
1039 | conf.status_device() |
|
1208 | conf.status_device() | |
1040 | else: |
|
1209 | else: | |
1041 | answer = conf.start_device() |
|
1210 | answer = conf.start_device() | |
1042 | conf.status_device() |
|
1211 | conf.status_device() | |
1043 | #--Running Experiment |
|
1212 | #--Running Experiment | |
1044 | old_running_experiment = RunningExperiment.objects.filter(radar=radar) |
|
1213 | old_running_experiment = RunningExperiment.objects.filter(radar=radar) | |
1045 | #--If RunningExperiment element exists |
|
1214 | #--If RunningExperiment element exists | |
1046 | if old_running_experiment: |
|
1215 | if old_running_experiment: | |
1047 | old_running_experiment = old_running_experiment[0] |
|
1216 | old_running_experiment = old_running_experiment[0] | |
1048 | old_running_experiment.running_experiment.add(exp) |
|
1217 | old_running_experiment.running_experiment.add(exp) | |
1049 | old_running_experiment.status = 3 |
|
1218 | old_running_experiment.status = 3 | |
1050 | old_running_experiment.save() |
|
1219 | old_running_experiment.save() | |
1051 | #--Create a new Running_Experiment Object |
|
1220 | #--Create a new Running_Experiment Object | |
1052 | else: |
|
1221 | else: | |
1053 | new_running_experiment = RunningExperiment( |
|
1222 | new_running_experiment = RunningExperiment( | |
1054 | radar = radar, |
|
1223 | radar = radar, | |
1055 | status = 3, |
|
1224 | status = 3, | |
1056 | ) |
|
1225 | ) | |
1057 | new_running_experiment.save() |
|
1226 | new_running_experiment.save() | |
1058 | new_running_experiment.running_experiment.add(exp) |
|
1227 | new_running_experiment.running_experiment.add(exp) | |
1059 | new_running_experiment.save() |
|
1228 | new_running_experiment.save() | |
1060 |
|
1229 | |||
1061 | if answer: |
|
1230 | if answer: | |
1062 | messages.success(request, conf.message) |
|
1231 | messages.success(request, conf.message) | |
1063 | exp.status=2 |
|
1232 | exp.status=2 | |
1064 | exp.save() |
|
1233 | exp.save() | |
1065 | else: |
|
1234 | else: | |
1066 | messages.error(request, conf.message) |
|
1235 | messages.error(request, conf.message) | |
1067 | else: |
|
1236 | else: | |
1068 | if exp.status == 1 or exp.status == 3: |
|
1237 | if exp.status == 1 or exp.status == 3: | |
1069 | exp.status=3 |
|
1238 | exp.status=3 | |
1070 | exp.save() |
|
1239 | exp.save() | |
1071 |
|
1240 | |||
1072 |
|
1241 | |||
1073 | route = request.META['HTTP_REFERER'] |
|
1242 | route = request.META['HTTP_REFERER'] | |
1074 | route = str(route) |
|
1243 | route = str(route) | |
1075 | if 'search' in route: |
|
1244 | if 'search' in route: | |
1076 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) |
|
1245 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) | |
1077 | else: |
|
1246 | else: | |
1078 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) |
|
1247 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) | |
1079 |
|
1248 | |||
1080 |
|
1249 | |||
1081 | def radar_stop(request, id_camp, id_radar): |
|
1250 | def radar_stop(request, id_camp, id_radar): | |
1082 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
1251 | campaign = get_object_or_404(Campaign, pk = id_camp) | |
1083 | radar = get_object_or_404(Location, pk = id_radar) |
|
1252 | radar = get_object_or_404(Location, pk = id_radar) | |
1084 | experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) |
|
1253 | experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) | |
1085 |
|
1254 | |||
1086 | for exp in experiments: |
|
1255 | for exp in experiments: | |
1087 | configurations = Configuration.objects.filter(experiment = exp) |
|
1256 | configurations = Configuration.objects.filter(experiment = exp) | |
1088 | for conf in configurations: |
|
1257 | for conf in configurations: | |
1089 | if 'cgs' in conf.device.device_type.name: |
|
1258 | if 'cgs' in conf.device.device_type.name: | |
1090 | conf.status_device() |
|
1259 | conf.status_device() | |
1091 | else: |
|
1260 | else: | |
1092 | answer = conf.stop_device() |
|
1261 | answer = conf.stop_device() | |
1093 | conf.status_device() |
|
1262 | conf.status_device() | |
1094 |
|
1263 | |||
1095 | if answer: |
|
1264 | if answer: | |
1096 | messages.success(request, conf.message) |
|
1265 | messages.success(request, conf.message) | |
1097 | exp.status=1 |
|
1266 | exp.status=1 | |
1098 | exp.save() |
|
1267 | exp.save() | |
1099 | else: |
|
1268 | else: | |
1100 | messages.error(request, conf.message) |
|
1269 | messages.error(request, conf.message) | |
1101 |
|
1270 | |||
1102 |
|
1271 | |||
1103 | route = request.META['HTTP_REFERER'] |
|
1272 | route = request.META['HTTP_REFERER'] | |
1104 | route = str(route) |
|
1273 | route = str(route) | |
1105 | if 'search' in route: |
|
1274 | if 'search' in route: | |
1106 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) |
|
1275 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) | |
1107 | else: |
|
1276 | else: | |
1108 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) |
|
1277 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) | |
1109 |
|
1278 | |||
1110 |
|
1279 | |||
1111 | def radar_refresh(request, id_camp, id_radar): |
|
1280 | def radar_refresh(request, id_camp, id_radar): | |
1112 |
|
1281 | |||
1113 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
1282 | campaign = get_object_or_404(Campaign, pk = id_camp) | |
1114 | radar = get_object_or_404(Location, pk = id_radar) |
|
1283 | radar = get_object_or_404(Location, pk = id_radar) | |
1115 | experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) |
|
1284 | experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) | |
1116 | for exs in experiments: |
|
1285 | for exs in experiments: | |
1117 | exs.get_status() |
|
1286 | exs.get_status() | |
1118 |
|
1287 | |||
1119 | route = request.META['HTTP_REFERER'] |
|
1288 | route = request.META['HTTP_REFERER'] | |
1120 | route = str(route) |
|
1289 | route = str(route) | |
1121 | if 'search' in route: |
|
1290 | if 'search' in route: | |
1122 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) |
|
1291 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) | |
1123 | else: |
|
1292 | else: | |
1124 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) |
|
1293 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) | |
1125 |
|
1294 |
General Comments 0
You need to be logged in to leave comments.
Login now