@@ -0,0 +1,34 | |||
|
1 | {% extends "base.html" %} | |
|
2 | {% load bootstrap3 %} | |
|
3 | {% load static %} | |
|
4 | {% load main_tags %} | |
|
5 | ||
|
6 | {% block loc-active %}active{% endblock %} | |
|
7 | ||
|
8 | {% block content-title %}{{title}}{% endblock %} | |
|
9 | {% block content-suptitle %}{{suptitle}}{% endblock %} | |
|
10 | ||
|
11 | {% block content %} | |
|
12 | <table class="table table-bordered"> | |
|
13 | {% for key in location_keys %} | |
|
14 | <tr><th>{{key|title}}</th><td>{{location|attr:key}}</td></tr> | |
|
15 | {% endfor %} | |
|
16 | </table> | |
|
17 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_edit">Edit</button> | |
|
18 | <br></br> | |
|
19 | <br></br> | |
|
20 | {% endblock %} | |
|
21 | ||
|
22 | {% block sidebar%} | |
|
23 | {% include "sidebar_devices.html" %} | |
|
24 | {% endblock %} | |
|
25 | ||
|
26 | {% block extra-js%} | |
|
27 | <script type="text/javascript"> | |
|
28 | ||
|
29 | $("#bt_edit").click(function() { | |
|
30 | document.location = "{% url 'url_edit_location' location.id%}"; | |
|
31 | }); | |
|
32 | ||
|
33 | </script> | |
|
34 | {% endblock %} No newline at end of file |
@@ -0,0 +1,29 | |||
|
1 | {% extends "base.html" %} | |
|
2 | {% load bootstrap3 %} | |
|
3 | {% load static %} | |
|
4 | {% load main_tags %} | |
|
5 | {% block extra-head %} | |
|
6 | <link href="{% static 'css/bootstrap-datetimepicker.min.css' %}" media="screen" rel="stylesheet"> | |
|
7 | {% endblock %} | |
|
8 | ||
|
9 | {% block loc-active %}active{% endblock %} | |
|
10 | ||
|
11 | {% block content-title %}{{title}}{% endblock %} | |
|
12 | {% block content-suptitle %}{{suptitle}}{% endblock %} | |
|
13 | ||
|
14 | {% block content %} | |
|
15 | <form class="form" method="post" action=""> | |
|
16 | {% csrf_token %} | |
|
17 | {% bootstrap_form form layout='horizontal' size='medium' %} | |
|
18 | <div style="clear: both;"></div> | |
|
19 | <br> | |
|
20 | <button type="submit" class="btn btn-primary pull-right">{{button}}</button> | |
|
21 | </form> | |
|
22 | {% endblock %} | |
|
23 | ||
|
24 | {% block sidebar%} | |
|
25 | {% include "sidebar_devices.html" %} | |
|
26 | {% endblock %} | |
|
27 | ||
|
28 | {% block extra-js%} | |
|
29 | {% endblock %} No newline at end of file |
@@ -0,0 +1,47 | |||
|
1 | {% extends "base.html" %} | |
|
2 | {% load bootstrap3 %} | |
|
3 | {% load static %} | |
|
4 | {% load main_tags %} | |
|
5 | ||
|
6 | {% block loc-active %}active{% endblock %} | |
|
7 | ||
|
8 | {% block content-title %}{{title}}{% endblock %} | |
|
9 | {% block content-suptitle %}{{suptitle}}{% endblock %} | |
|
10 | ||
|
11 | {% block content %} | |
|
12 | <table class="table table-hover"> | |
|
13 | <tr> | |
|
14 | <th>#</th> | |
|
15 | {% for key in location_keys %} | |
|
16 | <th>{{ key|title }}</th> | |
|
17 | {% endfor%} | |
|
18 | </tr> | |
|
19 | {% for location in locations %} | |
|
20 | <tr class="clickable-row" data-href="{% url 'url_location' location.id %}"> | |
|
21 | <td>{{ forloop.counter }}</td> | |
|
22 | {% for key in location_keys %} | |
|
23 | <td>{{ location|attr:key }}</td> | |
|
24 | {% endfor %} | |
|
25 | </tr> | |
|
26 | {% endfor %} | |
|
27 | </table> | |
|
28 | <button class="btn btn-primary pull-right" id="bt_add">{{button}}</button> | |
|
29 | {% endblock %} | |
|
30 | ||
|
31 | {% block sidebar%} | |
|
32 | {% include "sidebar_devices.html" %} | |
|
33 | {% endblock %} | |
|
34 | ||
|
35 | {% block extra-js%} | |
|
36 | <script type="text/javascript"> | |
|
37 | ||
|
38 | $("#bt_add").click(function() { | |
|
39 | document.location = "{% url 'url_add_location' %}"; | |
|
40 | }); | |
|
41 | ||
|
42 | $(".clickable-row").click(function() { | |
|
43 | document.location = $(this).data("href"); | |
|
44 | }); | |
|
45 | ||
|
46 | </script> | |
|
47 | {% endblock %} No newline at end of file |
@@ -1,60 +1,64 | |||
|
1 | 1 | from django import forms |
|
2 | 2 | from django.utils.safestring import mark_safe |
|
3 | 3 | |
|
4 | from .models import DeviceType, Device, Experiment, Campaign, Configuration | |
|
4 | from .models import DeviceType, Device, Experiment, Campaign, Configuration, Location | |
|
5 | 5 | |
|
6 | 6 | def add_empty_choice(choices, pos=0, label='-----'): |
|
7 | 7 | if len(choices)>0: |
|
8 | 8 | choices = list(choices) |
|
9 | 9 | choices.insert(0, (0, label)) |
|
10 | 10 | return choices |
|
11 | 11 | else: |
|
12 | 12 | return [(0, label)] |
|
13 | 13 | |
|
14 | 14 | class DatepickerWidget(forms.widgets.TextInput): |
|
15 | 15 | def render(self, name, value, attrs=None): |
|
16 | 16 | input_html = super(DatepickerWidget, self).render(name, value, attrs) |
|
17 | 17 | html = '<div class="input-group date">'+input_html+'<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span></div>' |
|
18 | 18 | return mark_safe(html) |
|
19 | 19 | |
|
20 | 20 | class TimepickerWidget(forms.widgets.TextInput): |
|
21 | 21 | def render(self, name, value, attrs=None): |
|
22 | 22 | input_html = super(TimepickerWidget, self).render(name, value, attrs) |
|
23 | 23 | html = '<div class="input-group time">'+input_html+'<span class="input-group-addon"><i class="glyphicon glyphicon-time"></i></span></div>' |
|
24 | 24 | return mark_safe(html) |
|
25 | 25 | |
|
26 | 26 | class CampaignForm(forms.ModelForm): |
|
27 | 27 | def __init__(self, *args, **kwargs): |
|
28 | 28 | super(CampaignForm, self).__init__(*args, **kwargs) |
|
29 | 29 | self.fields['start_date'].widget = DatepickerWidget(self.fields['start_date'].widget.attrs) |
|
30 | 30 | self.fields['end_date'].widget = DatepickerWidget(self.fields['end_date'].widget.attrs) |
|
31 | 31 | |
|
32 | 32 | class Meta: |
|
33 | 33 | model = Campaign |
|
34 | 34 | fields = ['name', 'start_date', 'end_date', 'tags', 'description', 'template'] |
|
35 | 35 | |
|
36 | 36 | class ExperimentForm(forms.ModelForm): |
|
37 | 37 | def __init__(self, *args, **kwargs): |
|
38 | 38 | super(ExperimentForm, self).__init__(*args, **kwargs) |
|
39 | 39 | self.fields['start_time'].widget = TimepickerWidget(self.fields['start_time'].widget.attrs) |
|
40 | 40 | self.fields['end_time'].widget = TimepickerWidget(self.fields['end_time'].widget.attrs) |
|
41 | 41 | |
|
42 | 42 | self.fields['campaign'].widget.attrs['readonly'] = True |
|
43 | 43 | |
|
44 | 44 | class Meta: |
|
45 | 45 | model = Experiment |
|
46 | 46 | fields = ['campaign', 'name', 'start_time', 'end_time'] |
|
47 | 47 | |
|
48 | class LocationForm(forms.ModelForm): | |
|
49 | class Meta: | |
|
50 | model = Location | |
|
51 | exclude = [''] | |
|
52 | ||
|
48 | 53 | class DeviceForm(forms.ModelForm): |
|
49 | 54 | class Meta: |
|
50 | 55 | model = Device |
|
51 | 56 | exclude = ['status'] |
|
52 | 57 | |
|
53 | 58 | class ConfigurationForm(forms.ModelForm): |
|
54 | 59 | class Meta: |
|
55 | 60 | model = Configuration |
|
56 | 61 | fields = ['experiment', 'device'] |
|
57 | 62 | |
|
58 | 63 | class DeviceTypeForm(forms.Form): |
|
59 | 64 | device_type = forms.ChoiceField(choices=add_empty_choice(DeviceType.objects.all().order_by('name').values_list('id', 'name'))) |
|
60 |
@@ -1,128 +1,142 | |||
|
1 | from itertools import chain | |
|
2 | 1 |
|
|
3 | 2 | from polymorphic import PolymorphicModel |
|
4 | 3 | |
|
5 | 4 | from django.core.urlresolvers import reverse |
|
6 | 5 | |
|
6 | CONF_STATES = ( | |
|
7 | (0, 'Disconnected'), | |
|
8 | (1, 'Connected'), | |
|
9 | (1, 'Running'), | |
|
10 | ) | |
|
11 | ||
|
7 | 12 | CONF_TYPES = ( |
|
8 | 13 | (0, 'Active'), |
|
9 | 14 | (1, 'Historical'), |
|
10 | 15 | ) |
|
11 | 16 | |
|
12 | 17 | DEV_STATES = ( |
|
13 | 18 | (0, 'No connected'), |
|
14 | 19 | (1, 'Connected'), |
|
15 | 20 | (2, 'Configured'), |
|
16 | 21 | (3, 'Running'), |
|
17 | 22 | ) |
|
18 | 23 | |
|
19 | 24 | DEV_TYPES = ( |
|
20 | 25 | ('', 'Select a device type'), |
|
21 | 26 | ('rc', 'Radar Controller'), |
|
22 | 27 | ('dds', 'Direct Digital Synthesizer'), |
|
23 | 28 | ('jars', 'Jicamarca Radar Acquisition System'), |
|
24 | 29 | ('usrp', 'Universal Software Radio Peripheral'), |
|
25 | 30 | ('cgs', 'Clock Generator System'), |
|
26 | 31 | ('abs', 'Automatic Beam Switching'), |
|
27 | 32 | ) |
|
28 | 33 | |
|
29 | 34 | # Create your models here. |
|
35 | ||
|
36 | class Location(models.Model): | |
|
37 | ||
|
38 | name = models.CharField(max_length = 30) | |
|
39 | description = models.TextField(blank=True, null=True) | |
|
40 | ||
|
41 | class Meta: | |
|
42 | db_table = 'db_location' | |
|
43 | ||
|
44 | def __unicode__(self): | |
|
45 | return u'%s' % self.name | |
|
30 | 46 | |
|
31 | 47 | class DeviceType(models.Model): |
|
32 | 48 | |
|
33 | 49 | name = models.CharField(max_length = 10, choices = DEV_TYPES, default = 'rc') |
|
34 | ||
|
35 | 50 | description = models.TextField(blank=True, null=True) |
|
36 | ||
|
37 | # info = models.TextField(blank=True, null=True) | |
|
38 | # status = models.PositiveSmallIntegerField(default=1, choices=STATES) | |
|
39 | 51 | |
|
40 | 52 | class Meta: |
|
41 | 53 | db_table = 'db_device_types' |
|
42 | 54 | |
|
43 | 55 | def __unicode__(self): |
|
44 | 56 | return u'%s' % self.get_name_display() |
|
45 | 57 | |
|
46 | 58 | class Device(models.Model): |
|
47 | 59 | |
|
48 | 60 | device_type = models.ForeignKey(DeviceType) |
|
61 | # location = models.ForeignKey(Location) | |
|
62 | ||
|
49 | 63 | name = models.CharField(max_length=40, default='') |
|
50 | 64 | ip_address = models.GenericIPAddressField(protocol='IPv4', default='0.0.0.0') |
|
51 | 65 | port_address = models.PositiveSmallIntegerField(default=2000) |
|
52 | 66 | description = models.TextField(blank=True, null=True) |
|
53 | 67 | status = models.PositiveSmallIntegerField(default=0, choices=DEV_STATES) |
|
54 | ||
|
55 | # serial_number = models.CharField(max_length=40, default='') | |
|
56 | # mac_address = models.CharField(max_length = 20, null=True, blank=True) | |
|
57 | ||
|
58 | 68 | |
|
59 | 69 | class Meta: |
|
60 | 70 | db_table = 'db_devices' |
|
61 | 71 | |
|
62 | 72 | def __unicode__(self): |
|
63 | 73 | return u'%s | %s' % (self.name, self.ip_address) |
|
64 | 74 | |
|
65 | 75 | class Campaign(models.Model): |
|
66 | 76 | |
|
67 | 77 | name = models.CharField(max_length=40, unique=True) |
|
68 | 78 | start_date = models.DateTimeField(blank=True, null=True) |
|
69 | 79 | end_date = models.DateTimeField(blank=True, null=True) |
|
70 | 80 | tags = models.CharField(max_length=40) |
|
71 | 81 | description = models.TextField(blank=True, null=True) |
|
72 | 82 | template = models.BooleanField(default=False) |
|
73 | 83 | |
|
74 | 84 | class Meta: |
|
75 | 85 | db_table = 'db_campaigns' |
|
76 | 86 | |
|
77 | 87 | def __unicode__(self): |
|
78 | 88 | return u'%s' % (self.name) |
|
79 | 89 | |
|
80 | 90 | class Experiment(models.Model): |
|
81 | 91 | |
|
82 | 92 | campaign = models.ForeignKey(Campaign) |
|
83 | 93 | name = models.CharField(max_length=40, default='') |
|
84 | 94 | start_time = models.TimeField(default='00:00:00') |
|
85 | 95 | end_time = models.TimeField(default='23:59:59') |
|
86 | 96 | |
|
87 | 97 | class Meta: |
|
88 | 98 | db_table = 'db_experiments' |
|
89 | 99 | |
|
90 | 100 | def __unicode__(self): |
|
91 | 101 | return u'[%s]: %s' % (self.campaign.name, self.name) |
|
92 | 102 | |
|
93 | 103 | class Configuration(PolymorphicModel): |
|
94 | 104 | |
|
95 | 105 | experiment = models.ForeignKey(Experiment) |
|
96 | 106 | device = models.ForeignKey(Device) |
|
107 | ||
|
108 | status = models.PositiveSmallIntegerField(default=0, choices=CONF_STATES) | |
|
97 | 109 | type = models.PositiveSmallIntegerField(default=0, choices=CONF_TYPES) |
|
98 | 110 | |
|
111 | name = models.CharField(max_length=40, default='') | |
|
112 | ||
|
99 | 113 | created_date = models.DateTimeField(auto_now_add=True) |
|
100 | 114 | programmed_date = models.DateTimeField(auto_now=True) |
|
101 | 115 | |
|
102 | 116 | parameters = models.TextField(default='{}') |
|
103 | 117 | |
|
104 | 118 | class Meta: |
|
105 | 119 | db_table = 'db_configurations' |
|
106 | 120 | |
|
107 | 121 | def __unicode__(self): |
|
108 | 122 | return u'[%s - %s]: %s' % (self.experiment.campaign.name, |
|
109 | 123 | self.experiment.name, |
|
110 | 124 | self.device.name) |
|
111 | 125 | def get_absolute_url(self): |
|
112 | 126 | |
|
113 | 127 | return reverse('url_%s_conf' % self.device.device_type.name, args=[str(self.id)]) |
|
114 | 128 | |
|
115 | 129 | def get_absolute_url_edit(self): |
|
116 | 130 | return reverse('url_edit_%s_conf' % self.device.device_type.name, args=[str(self.id)]) |
|
117 | 131 | |
|
118 | 132 | def get_absolute_url_import(self): |
|
119 | 133 | return reverse('url_import_%s_conf' % self.device.device_type.name, args=[str(self.id)]) |
|
120 | 134 | |
|
121 | 135 | def get_absolute_url_export(self): |
|
122 | 136 | return reverse('url_export_%s_conf' % self.device.device_type.name, args=[str(self.id)]) |
|
123 | 137 | |
|
124 | 138 | def get_absolute_url_write(self): |
|
125 | 139 | return reverse('url_write_%s_conf' % self.device.device_type.name, args=[str(self.id)]) |
|
126 | 140 | |
|
127 | 141 | def get_absolute_url_read(self): |
|
128 | 142 | return reverse('url_read_%s_conf' % self.device.device_type.name, args=[str(self.id)]) No newline at end of file |
@@ -1,126 +1,128 | |||
|
1 | 1 | <!DOCTYPE html> |
|
2 | 2 | {% load static %} |
|
3 | 3 | <html lang="en"> |
|
4 | 4 | <head> |
|
5 | 5 | <meta charset="utf-8"> |
|
6 | 6 | <title>{% block title %}Jicamarca Integrated Radar System:::::{% endblock %}</title> |
|
7 | 7 | <meta name="description" content=""> |
|
8 | 8 | <meta name="author" content=""> |
|
9 | 9 | <meta name="viewport" content="width=device-width, initial-scale=1"> |
|
10 | 10 | {# bootstrap_css #} |
|
11 | 11 | <link href="{% static 'css/bootstrap-flatly.min.css' %}" media="all" rel="stylesheet"> |
|
12 | 12 | <style type="text/css"> |
|
13 | 13 | body {padding-top: 60px} |
|
14 | 14 | .logo {padding-top: 5px; height: 50px} |
|
15 | 15 | .clickable-row {cursor: pointer;} |
|
16 | 16 | </style> |
|
17 | 17 | <!--[if lt IE 9]> |
|
18 | 18 | <script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script> |
|
19 | 19 | <![endif]--> |
|
20 | 20 | {% block extra-head %} |
|
21 | 21 | {% endblock %} |
|
22 | 22 | </head> |
|
23 | 23 | |
|
24 | 24 | <body> |
|
25 | 25 | |
|
26 | 26 | {% block main_menu %} |
|
27 | 27 | <nav class="navbar navbar-default navbar-fixed-top" role="banner"> |
|
28 | 28 | <div class="container-fluid"> |
|
29 | 29 | <div class="navbar-header"> |
|
30 | 30 | <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navigationbar"> |
|
31 | 31 | <span class="sr-only">Toggle navigation</span> |
|
32 | 32 | <span class="icon-bar"></span> |
|
33 | 33 | <span class="icon-bar"></span> |
|
34 | 34 | <span class="icon-bar"></span> |
|
35 | 35 | </button> |
|
36 | 36 | <a class="navbar-brand" href="{% url 'index' %}" style="padding-top:1px"><img class="logo" alt="JRO" src="{% static "images/logo-jro-white-trans.png" %}"></a> |
|
37 | 37 | </div> |
|
38 | 38 | <div class="collapse navbar-collapse" id="navigationbar"> |
|
39 | 39 | <ul class="nav navbar-nav"> |
|
40 | <li class=" dropdown {% block dev-active %}{% endblock %}"><a href="{% url 'url_devices'%}">Devices</a> | |
|
41 | </li> | |
|
42 | 40 | <li class=" dropdown {% block camp-active %}{% endblock %}"><a href="{% url 'url_campaigns'%}">Campaigns</a> |
|
43 | 41 | </li> |
|
44 | 42 | <li class=" dropdown {% block exp-active %}{% endblock %}"><a href="{% url 'url_experiments'%}">Experiments</a> |
|
45 | 43 | </li> |
|
46 |
<li class=" dropdown {% block conf-active %}{% endblock %}"><a href="{% url 'url_dev_confs'%}"> |
|
|
44 | <li class=" dropdown {% block conf-active %}{% endblock %}"><a href="{% url 'url_dev_confs'%}">Configurations</a> | |
|
45 | </li> | |
|
46 | <li class=" dropdown {% block dev-active %}{% endblock %}"><a href="{% url 'url_devices'%}">Devices</a> | |
|
47 | </li> | |
|
48 | <li class=" dropdown {% block loc-active %}{% endblock %}"><a href="{% url 'url_locations'%}">Locations</a> | |
|
47 | 49 | </li> |
|
48 | 50 | </ul> |
|
49 | 51 | <ul class="nav navbar-nav navbar-right"> |
|
50 | 52 | <li class="nav-divider"></li> |
|
51 | 53 | {% if user.is_authenticated %} |
|
52 | 54 | <li class="dropdown"> |
|
53 | 55 | <a href="#" class="dropdown-toggle" data-toggle="dropdown">Hi {{ user.username }}<span class="caret"></span></a> |
|
54 | 56 | <ul class="dropdown-menu" role="menu"> |
|
55 | 57 | <li><a href="#">Control Panel</a></li> |
|
56 | 58 | <li><a href="{% url 'django.contrib.auth.views.logout' %}">Logout</a></li> |
|
57 | 59 | </ul> |
|
58 | 60 | </li> |
|
59 | 61 | {% else %} |
|
60 | 62 | <li><a href="{% url 'django.contrib.auth.views.login' %}?next={{request.get_full_path}}">Login</a></li> |
|
61 | 63 | {% endif %} |
|
62 | 64 | </ul> |
|
63 | 65 | </div> |
|
64 | 66 | </div> |
|
65 | 67 | </nav> |
|
66 | 68 | <div style="clear: both;"></div> |
|
67 | 69 | {% endblock %} |
|
68 | 70 | |
|
69 | 71 | <div class="container"> |
|
70 | 72 | <div id="page" class="row" style="min-height:600px"> |
|
71 | 73 | |
|
72 | 74 | <div class="col-md-3 hidden-xs hidden-sm" role="complementary"> |
|
73 | 75 | <br><br> |
|
74 | 76 | <div id="sidebar"> |
|
75 | 77 | {% block sidebar%} |
|
76 | 78 | {% endblock %} |
|
77 | 79 | </div> |
|
78 | 80 | </div> |
|
79 | 81 | |
|
80 | 82 | <div class="col-md-9 col-xs-12" role="main"> |
|
81 | 83 | <div class="page-header"> |
|
82 | 84 | <h1>{% block content-title %}{% endblock %} <small>{% block content-suptitle %}{% endblock %}</small></h1> |
|
83 | 85 | <hr> |
|
84 | 86 | </div> |
|
85 | 87 | {% block messages %} |
|
86 | 88 | {% if messages %} |
|
87 | 89 | {% for message in messages %} |
|
88 | 90 | <div class="alert alert-{% if message.tags %}{% if 'error' in message.tags %}danger{% else %}{{ message.tags }}{% endif %}{% else %}info{% endif %} alert-dismissible" role="alert"> |
|
89 | 91 | <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button> |
|
90 | 92 | <strong>{{message.tags|title}}!</strong> {{ message }} |
|
91 | 93 | </div> |
|
92 | 94 | {% endfor %} |
|
93 | 95 | {% endif %} |
|
94 | 96 | {% endblock %} |
|
95 | 97 | |
|
96 | 98 | {% block content %} |
|
97 | 99 | {% endblock %} |
|
98 | 100 | |
|
99 | 101 | </div> |
|
100 | 102 | |
|
101 | 103 | |
|
102 | 104 | </div><!--/row--> |
|
103 | 105 | </div> <!-- container --> |
|
104 | 106 | |
|
105 | 107 | <div id="debug">{{debug}}</div> |
|
106 | 108 | |
|
107 | 109 | {% block footer %} |
|
108 | 110 | <footer class="footer"> |
|
109 | 111 | <div class="container"> |
|
110 | 112 | <p><hr></p> |
|
111 | 113 | <p> |
|
112 | 114 | © <a href="http://jro.igp.gob.pe">Jicamarca Radio Observatory</a> - {% now "Y" %} |
|
113 | 115 | </p> |
|
114 | 116 | </div> |
|
115 | 117 | </footer> |
|
116 | 118 | {% endblock %} |
|
117 | 119 | |
|
118 | 120 | {# bootstrap_javascript jquery=True #} |
|
119 | 121 | <script src="{% static 'js/jquery.min.js' %}"></script> |
|
120 | 122 | <script src="{% static 'js/bootstrap.min.js' %}"></script> |
|
121 | 123 | <script src="{% static 'js/jquery-ui.min.js' %}"></script> |
|
122 | 124 | {% block extra-js %} |
|
123 | 125 | {% endblock%} |
|
124 | 126 | </body> |
|
125 | 127 | </html> |
|
126 | 128 |
@@ -1,35 +1,35 | |||
|
1 | 1 | {% extends "base.html" %} |
|
2 | 2 | {% load bootstrap3 %} |
|
3 | 3 | {% load static %} |
|
4 | 4 | {% load main_tags %} |
|
5 | 5 | |
|
6 | 6 | {% block conf-active %}active{% endblock %} |
|
7 | 7 | |
|
8 | 8 | {% block content-title %}{{title}}{% endblock %} |
|
9 | 9 | {% block content-suptitle %}{{suptitle}}{% endblock %} |
|
10 | 10 | |
|
11 | 11 | {% block content %} |
|
12 | 12 | |
|
13 | 13 | {% if form.is_multipart %} |
|
14 | <form class="form" enctype="multipart/form-data" method="post" action=""> | |
|
14 | <form class="form" enctype="multipart/form-data" method="post" action="{{action}}"> | |
|
15 | 15 | {% else %} |
|
16 | <form class="form" method="post" action=""> | |
|
16 | <form class="form" method="post" action="{{action}}"> | |
|
17 | 17 | {% endif %} |
|
18 | 18 | |
|
19 | 19 | {% csrf_token %} |
|
20 | 20 | {% bootstrap_form form layout='horizontal' size='medium' %} |
|
21 | 21 | <div style="clear: both;"></div> |
|
22 | 22 | <br> |
|
23 | 23 | <div class="pull-right"> |
|
24 | 24 | <button type="button" class="btn btn-primary" onclick="{% if previous %}window.location.replace('{{ previous }}');{% else %}history.go(-1);{% endif %}">Cancel</button> |
|
25 | 25 | <button type="submit" class="btn btn-primary">{{button}}</button> |
|
26 | 26 | </div> |
|
27 | 27 | </form> |
|
28 | 28 | {% endblock %} |
|
29 | 29 | |
|
30 | 30 | {% block sidebar%} |
|
31 | 31 | {% include "sidebar_devices.html" %} |
|
32 | 32 | {% endblock %} |
|
33 | 33 | |
|
34 | 34 | {% block extra-js%} |
|
35 | 35 | {% endblock %} No newline at end of file |
@@ -1,80 +1,80 | |||
|
1 | 1 | {% extends "base.html" %} |
|
2 | 2 | {% load bootstrap3 %} |
|
3 | 3 | {% load static %} |
|
4 | 4 | {% load main_tags %} |
|
5 | 5 | {% block extra-head %} |
|
6 | 6 | <link href="{% static 'css/bootstrap-datetimepicker.min.css' %}" media="screen" rel="stylesheet"> |
|
7 | 7 | {% endblock %} |
|
8 | 8 | |
|
9 | 9 | {% block exp-active %}active{% endblock %} |
|
10 | 10 | |
|
11 | 11 | {% block content-title %}{{title}}{% endblock %} |
|
12 | 12 | {% block content-suptitle %}{{suptitle}}{% endblock %} |
|
13 | 13 | |
|
14 | 14 | {% block content %} |
|
15 | 15 | <table class="table table-bordered"> |
|
16 | 16 | {% for key in experiment_keys %} |
|
17 | 17 | <tr><th>{{key|title}}</th><td>{{experiment|attr:key}}</td></tr> |
|
18 | 18 | {% endfor %} |
|
19 | 19 | </table> |
|
20 | 20 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_export">Export</button> |
|
21 | 21 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_edit">Edit</button> |
|
22 | 22 | <br></br> |
|
23 | 23 | <br></br> |
|
24 | 24 | |
|
25 | 25 | <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> |
|
26 | 26 | |
|
27 | 27 | <div class="panel panel-default"> |
|
28 | 28 | <div class="panel-heading" role="tab" id="headingTwo"> |
|
29 | 29 | <h4 class="panel-title"> |
|
30 | 30 | <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseThree"> |
|
31 | 31 | Device Configurations |
|
32 | 32 | </a> |
|
33 | 33 | </h4> |
|
34 | 34 | </div> |
|
35 | 35 | <div id="collapseTwo" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo"> |
|
36 | 36 | <div class="panel-body"> |
|
37 | 37 | <table class="table table-hover"> |
|
38 | 38 | <tr> |
|
39 | 39 | <th>#</th> |
|
40 |
{% for key in configuration_ |
|
|
40 | {% for key in configuration_labels %} | |
|
41 | 41 | <th>{{ key|title }}</th> |
|
42 | 42 | {% endfor%} |
|
43 | 43 | </tr> |
|
44 | 44 | {% for item in configurations %} |
|
45 |
<tr class="clickable-row" data-href=" |
|
|
45 | <tr class="clickable-row" data-href="{{item.get_absolute_url}}"> | |
|
46 | 46 | <td>{{ forloop.counter }}</td> |
|
47 | 47 | {% for key in configuration_keys %} |
|
48 |
<td>{{ item| |
|
|
48 | <td>{{ item|value:key }}</td> | |
|
49 | 49 | {% endfor %} |
|
50 | 50 | </tr> |
|
51 | 51 | {% endfor %} |
|
52 | 52 | </table> |
|
53 | 53 | <button class="btn btn-primary pull-right" id="bt_add_conf">{{button}}</button> |
|
54 | 54 | </div> |
|
55 | 55 | </div> |
|
56 | 56 | </div> |
|
57 | 57 | </div> |
|
58 | 58 | {% endblock %} |
|
59 | 59 | |
|
60 | 60 | {% block sidebar%} |
|
61 | 61 | {% include "sidebar_devices.html" %} |
|
62 | 62 | {% endblock %} |
|
63 | 63 | |
|
64 | 64 | {% block extra-js%} |
|
65 | 65 | <script type="text/javascript"> |
|
66 | 66 | |
|
67 | 67 | $(".clickable-row").click(function() { |
|
68 | 68 | document.location = $(this).data("href"); |
|
69 | 69 | }); |
|
70 | 70 | |
|
71 | 71 | $("#bt_edit").click(function() { |
|
72 | 72 | document.location = "{% url 'url_edit_experiment' experiment.id%}"; |
|
73 | 73 | }); |
|
74 | 74 | |
|
75 | 75 | $("#bt_add_conf").click(function() { |
|
76 | 76 | document.location = "{% url 'url_add_dev_conf' experiment.id%}"; |
|
77 | 77 | }); |
|
78 | 78 | |
|
79 | 79 | </script> |
|
80 | 80 | {% endblock %} No newline at end of file |
@@ -1,100 +1,100 | |||
|
1 | 1 | {% if campaign %} |
|
2 | 2 | <div class="panel panel-default"> |
|
3 | 3 | <div class="panel-heading"> |
|
4 | 4 | <h4>Campaign</h4> |
|
5 | 5 | </div> |
|
6 | 6 | <div class="list-group"> |
|
7 | 7 | <a href="{% url 'url_campaign' campaign.id %}" class="list-group-item active" >{{ campaign.name }}</a> |
|
8 | 8 | </div> |
|
9 | 9 | </div> |
|
10 | 10 | |
|
11 | 11 | {% if experiments %} |
|
12 | 12 | <div class="panel panel-default"> |
|
13 | 13 | <div class="panel-heading"> |
|
14 | 14 | <h4>Experiments</h4> |
|
15 | 15 | </div> |
|
16 | 16 | <div class="list-group"> |
|
17 | 17 | {% for item in experiments %} |
|
18 | 18 | <a href="{% url 'url_experiment' item.id %}" class="list-group-item {{item.active}}">{{item.name}}</a> |
|
19 | 19 | {% endfor %} |
|
20 | 20 | </div> |
|
21 | 21 | </div> |
|
22 | 22 | {% endif %} |
|
23 | 23 | {% endif %} |
|
24 | 24 | |
|
25 | 25 | {% if experiment %} |
|
26 | 26 | <div class="panel panel-default"> |
|
27 | 27 | <div class="panel-heading"> |
|
28 | 28 | <h4>Campaign</h4> |
|
29 | 29 | </div> |
|
30 | 30 | <div class="list-group"> |
|
31 | 31 | <a href="{% url 'url_campaign' experiment.campaign.id %}" class="list-group-item active" >{{ experiment.campaign.name }}</a> |
|
32 | 32 | </div> |
|
33 | 33 | </div> |
|
34 | 34 | |
|
35 | 35 | {% if experiments %} |
|
36 | 36 | <div class="panel panel-default"> |
|
37 | 37 | <div class="panel-heading"> |
|
38 | 38 | <h4>Experiments</h4> |
|
39 | 39 | </div> |
|
40 | 40 | <div class="list-group"> |
|
41 | 41 | {% for item in experiments %} |
|
42 | 42 | <a href="{% url 'url_experiment' item.id %}" class="list-group-item {%if item.id == experiment.id%}active{%endif%}">{{item.name}}</a> |
|
43 | 43 | {% endfor %} |
|
44 | 44 | </div> |
|
45 | 45 | </div> |
|
46 | 46 | {% endif %} |
|
47 | 47 | |
|
48 | 48 | {% if configurations %} |
|
49 | 49 | <div class="panel panel-default"> |
|
50 | 50 | <div class="panel-heading"> |
|
51 | 51 | <h4>Device Configurations</h4> |
|
52 | 52 | </div> |
|
53 | 53 | <div class="list-group"> |
|
54 | 54 | {% for item in configurations %} |
|
55 |
<a href=" |
|
|
55 | <a href="{{item.get_absolute_url}}" class="list-group-item {{item.active}}">{{item.device.name}}</a> | |
|
56 | 56 | {% endfor %} |
|
57 | 57 | </div> |
|
58 | 58 | </div> |
|
59 | 59 | {% endif %} |
|
60 | 60 | |
|
61 | 61 | {% endif %} |
|
62 | 62 | |
|
63 | 63 | {% if dev_conf %} |
|
64 | 64 | <div class="panel panel-default"> |
|
65 | 65 | <div class="panel-heading"> |
|
66 | 66 | <h4>Campaign</h4> |
|
67 | 67 | </div> |
|
68 | 68 | <div class="list-group"> |
|
69 | 69 | <a href="{% url 'url_campaign' dev_conf.experiment.campaign.id %}" class="list-group-item active" >{{ dev_conf.experiment.campaign.name }}</a> |
|
70 | 70 | </div> |
|
71 | 71 | </div> |
|
72 | 72 | |
|
73 | 73 | {% if experiments %} |
|
74 | 74 | <div class="panel panel-default"> |
|
75 | 75 | <div class="panel-heading"> |
|
76 | 76 | <h4>Experiments</h4> |
|
77 | 77 | </div> |
|
78 | 78 | <div class="list-group"> |
|
79 | 79 | {% for item in experiments %} |
|
80 | 80 | <a href="{% url 'url_experiment' item.id %}" class="list-group-item {%if item.id == dev_conf.experiment.id%}active{%endif%}">{{item.name}}</a> |
|
81 | 81 | {% endfor %} |
|
82 | 82 | </div> |
|
83 | 83 | </div> |
|
84 | 84 | {% endif %} |
|
85 | 85 | |
|
86 | 86 | {% if configurations %} |
|
87 | 87 | <div class="panel panel-default"> |
|
88 | 88 | <div class="panel-heading"> |
|
89 | 89 | <h4>Device Configurations</h4> |
|
90 | 90 | </div> |
|
91 | 91 | <div class="list-group"> |
|
92 | 92 | {% for item in configurations %} |
|
93 |
<a href=" |
|
|
93 | <a href="{{item.get_absolute_url}}" class="list-group-item {%if item.id == dev_conf.id%}active{%endif%}">{{item.device.name}}</a> | |
|
94 | 94 | {% endfor %} |
|
95 | 95 | </div> |
|
96 | 96 | </div> |
|
97 | 97 | {% endif %} |
|
98 | 98 | |
|
99 | 99 | |
|
100 | 100 | {% endif %} |
@@ -1,25 +1,36 | |||
|
1 | 1 | from django.template.defaulttags import register |
|
2 | 2 | |
|
3 | 3 | @register.filter |
|
4 | 4 | def attr(instance, key): |
|
5 | 5 | |
|
6 | 6 | display_key = "get_" + key + "_display" |
|
7 | 7 | |
|
8 | 8 | if hasattr(instance, display_key): |
|
9 | 9 | return getattr(instance, display_key)() |
|
10 | 10 | |
|
11 | 11 | if hasattr(instance, key): |
|
12 | 12 | return getattr(instance, key) |
|
13 | 13 | |
|
14 | 14 | return instance.get(key) |
|
15 | 15 | |
|
16 | 16 | @register.filter |
|
17 | 17 | def title(s): |
|
18 | 18 | return s.replace('_', ' ').title() |
|
19 | 19 | |
|
20 | @register.filter | |
|
21 | def value(instance, key): | |
|
22 | ||
|
23 | item = instance | |
|
24 | for my_key in key.split("__"): | |
|
25 | print "TP Value", item, my_key | |
|
26 | item = attr(item, my_key) | |
|
27 | ||
|
28 | print item | |
|
29 | return item | |
|
30 | ||
|
20 | 31 | @register.simple_tag |
|
21 | 32 | def get_verbose_field_name(instance, field_name): |
|
22 | 33 | """ |
|
23 | 34 | Returns verbose_name for a field. |
|
24 | 35 | """ |
|
25 | 36 | return instance._meta.get_field(field_name).verbose_name.title() No newline at end of file |
@@ -1,27 +1,34 | |||
|
1 | 1 | from django.conf.urls import url |
|
2 | 2 | |
|
3 | 3 | urlpatterns = ( |
|
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'), | |
|
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'), | |
|
8 | url(r'^location/(?P<id_loc>-?\d+)/delete/$', 'apps.main.views.location_delete', name='url_delete_location'), | |
|
9 | ||
|
4 | 10 | url(r'^device/new/$', 'apps.main.views.device_new', name='url_add_device'), |
|
5 | 11 | url(r'^device/$', 'apps.main.views.devices', name='url_devices'), |
|
6 | 12 | url(r'^device/(?P<id_dev>-?\d+)/$', 'apps.main.views.device', name='url_device'), |
|
7 | 13 | url(r'^device/(?P<id_dev>-?\d+)/edit/$', 'apps.main.views.device_edit', name='url_edit_device'), |
|
8 | 14 | url(r'^device/(?P<id_dev>-?\d+)/delete/$', 'apps.main.views.device_delete', name='url_delete_device'), |
|
9 | 15 | |
|
10 | 16 | url(r'^campaign/new/$', 'apps.main.views.campaign_new', name='url_add_campaign'), |
|
11 | 17 | url(r'^campaign/$', 'apps.main.views.campaigns', name='url_campaigns'), |
|
12 | 18 | url(r'^campaign/(?P<id_camp>-?\d+)/$', 'apps.main.views.campaign', name='url_campaign'), |
|
13 | 19 | url(r'^campaign/(?P<id_camp>-?\d+)/edit/$', 'apps.main.views.campaign_edit', name='url_edit_campaign'), |
|
14 | 20 | url(r'^campaign/(?P<id_camp>-?\d+)/delete/$', 'apps.main.views.campaign_delete', name='url_delete_campaign'), |
|
15 | 21 | |
|
16 | 22 | url(r'^campaign/(?P<id_camp>-?\d+)/new_experiment/$', 'apps.main.views.experiment_new', name='url_add_experiment'), |
|
17 | 23 | url(r'^experiment/$', 'apps.main.views.experiments', name='url_experiments'), |
|
18 | 24 | url(r'^experiment/(?P<id_exp>-?\d+)/$', 'apps.main.views.experiment', name='url_experiment'), |
|
19 | 25 | url(r'^experiment/(?P<id_exp>-?\d+)/edit/$', 'apps.main.views.experiment_edit', name='url_edit_experiment'), |
|
20 | 26 | url(r'^experiment/(?P<id_exp>-?\d+)/delete/$', 'apps.main.views.experiment_delete', name='url_delete_experiment'), |
|
21 | 27 | |
|
22 | 28 | url(r'^experiment/(?P<id_exp>-?\d+)/new_dev_conf/$', 'apps.main.views.dev_conf_new', name='url_add_dev_conf'), |
|
23 | 29 | url(r'^dev_conf/$', 'apps.main.views.dev_confs', name='url_dev_confs'), |
|
24 | 30 | url(r'^dev_conf/(?P<id_conf>-?\d+)/$', 'apps.main.views.dev_conf', name='url_dev_conf'), |
|
25 | 31 | url(r'^dev_conf/(?P<id_conf>-?\d+)/edit/$', 'apps.main.views.dev_conf_edit', name='url_edit_dev_conf'), |
|
26 | 32 | url(r'^dev_conf/(?P<id_conf>-?\d+)/delete/$', 'apps.main.views.dev_conf_delete', name='url_delete_dev_conf'), |
|
33 | ||
|
27 | 34 | ) |
@@ -1,509 +1,594 | |||
|
1 | 1 | from django.shortcuts import render, redirect, get_object_or_404, HttpResponse |
|
2 | 2 | from django.contrib import messages |
|
3 | 3 | |
|
4 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm | |
|
4 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm | |
|
5 | 5 | from apps.cgs.forms import CGSConfigurationForm |
|
6 | 6 | from apps.jars.forms import JARSConfigurationForm |
|
7 | 7 | from apps.usrp.forms import USRPConfigurationForm |
|
8 | 8 | from apps.abs.forms import ABSConfigurationForm |
|
9 | 9 | from apps.rc.forms import RCConfigurationForm |
|
10 | 10 | from apps.dds.forms import DDSConfigurationForm |
|
11 | 11 | |
|
12 | from .models import Campaign, Experiment, Device, Configuration | |
|
12 | from .models import Campaign, Experiment, Device, Configuration, Location | |
|
13 | 13 | from apps.cgs.models import CGSConfiguration |
|
14 | 14 | from apps.jars.models import JARSConfiguration |
|
15 | 15 | from apps.usrp.models import USRPConfiguration |
|
16 | 16 | from apps.abs.models import ABSConfiguration |
|
17 | 17 | from apps.rc.models import RCConfiguration |
|
18 | 18 | from apps.dds.models import DDSConfiguration |
|
19 | 19 | |
|
20 | 20 | # Create your views here. |
|
21 | 21 | |
|
22 | 22 | CONF_FORMS = { |
|
23 | 23 | 'rc': RCConfigurationForm, |
|
24 | 24 | 'dds': DDSConfigurationForm, |
|
25 | 25 | 'jars': JARSConfigurationForm, |
|
26 | 26 | 'cgs': CGSConfigurationForm, |
|
27 | 27 | 'abs': ABSConfigurationForm, |
|
28 | 28 | 'usrp': USRPConfigurationForm, |
|
29 | 29 | } |
|
30 | 30 | |
|
31 | 31 | CONF_MODELS = { |
|
32 | 32 | 'rc': RCConfiguration, |
|
33 | 33 | 'dds': DDSConfiguration, |
|
34 | 34 | 'jars': JARSConfiguration, |
|
35 | 35 | 'cgs': CGSConfiguration, |
|
36 | 36 | 'abs': ABSConfiguration, |
|
37 | 37 | 'usrp': USRPConfiguration, |
|
38 | 38 | } |
|
39 | 39 | |
|
40 | 40 | def index(request): |
|
41 | 41 | kwargs = {} |
|
42 | 42 | |
|
43 | 43 | return render(request, 'index.html', kwargs) |
|
44 | 44 | |
|
45 | def locations(request): | |
|
46 | ||
|
47 | locations = Location.objects.all().order_by('name') | |
|
48 | ||
|
49 | keys = ['id', 'name', 'description'] | |
|
50 | ||
|
51 | kwargs = {} | |
|
52 | kwargs['location_keys'] = keys[1:] | |
|
53 | kwargs['locations'] = locations | |
|
54 | kwargs['title'] = 'Location' | |
|
55 | kwargs['suptitle'] = 'List' | |
|
56 | kwargs['button'] = 'New Location' | |
|
57 | ||
|
58 | return render(request, 'locations.html', kwargs) | |
|
59 | ||
|
60 | def location(request, id_loc): | |
|
61 | ||
|
62 | location = get_object_or_404(Location, pk=id_loc) | |
|
63 | ||
|
64 | kwargs = {} | |
|
65 | kwargs['location'] = location | |
|
66 | kwargs['location_keys'] = ['name', 'description'] | |
|
67 | ||
|
68 | kwargs['title'] = 'Location' | |
|
69 | kwargs['suptitle'] = 'Details' | |
|
70 | ||
|
71 | return render(request, 'location.html', kwargs) | |
|
72 | ||
|
73 | def location_new(request): | |
|
74 | ||
|
75 | if request.method == 'GET': | |
|
76 | form = LocationForm() | |
|
77 | ||
|
78 | if request.method == 'POST': | |
|
79 | form = LocationForm(request.POST) | |
|
80 | ||
|
81 | if form.is_valid(): | |
|
82 | form.save() | |
|
83 | return redirect('url_locations') | |
|
84 | ||
|
85 | kwargs = {} | |
|
86 | kwargs['form'] = form | |
|
87 | kwargs['title'] = 'Location' | |
|
88 | kwargs['suptitle'] = 'New' | |
|
89 | kwargs['button'] = 'Create' | |
|
90 | ||
|
91 | return render(request, 'location_edit.html', kwargs) | |
|
92 | ||
|
93 | def location_edit(request, id_loc): | |
|
94 | ||
|
95 | location = get_object_or_404(Location, pk=id_loc) | |
|
96 | ||
|
97 | if request.method=='GET': | |
|
98 | form = LocationForm(instance=location) | |
|
99 | ||
|
100 | if request.method=='POST': | |
|
101 | form = LocationForm(request.POST, instance=location) | |
|
102 | ||
|
103 | if form.is_valid(): | |
|
104 | form.save() | |
|
105 | return redirect('url_locations') | |
|
106 | ||
|
107 | kwargs = {} | |
|
108 | kwargs['form'] = form | |
|
109 | kwargs['title'] = 'Location' | |
|
110 | kwargs['suptitle'] = 'Edit' | |
|
111 | kwargs['button'] = 'Update' | |
|
112 | ||
|
113 | return render(request, 'location_edit.html', kwargs) | |
|
114 | ||
|
115 | def location_delete(request, id_loc): | |
|
116 | ||
|
117 | location = get_object_or_404(Location, pk=id_loc) | |
|
118 | ||
|
119 | if request.method=='POST': | |
|
120 | ||
|
121 | if request.user.is_staff: | |
|
122 | location.delete() | |
|
123 | return redirect('url_locations') | |
|
124 | ||
|
125 | return HttpResponse("Not enough permission to delete this object") | |
|
126 | ||
|
127 | kwargs = {'object':location, 'loc_active':'active', | |
|
128 | 'url_cancel':'url_location', 'id_item':id_loc} | |
|
129 | ||
|
130 | return render(request, 'item_delete.html', kwargs) | |
|
131 | ||
|
45 | 132 | def devices(request): |
|
46 | 133 | |
|
47 | 134 | devices = Device.objects.all().order_by('device_type__name') |
|
48 | 135 | |
|
49 | 136 | # keys = ['id', 'device_type__name', 'name', 'ip_address'] |
|
50 | keys = ['id', 'name', 'ip_address', 'device_type'] | |
|
137 | keys = ['id', 'name', 'ip_address', 'port_address', 'device_type'] | |
|
51 | 138 | |
|
52 | 139 | kwargs = {} |
|
53 | 140 | kwargs['device_keys'] = keys[1:] |
|
54 | 141 | kwargs['devices'] = devices#.values(*keys) |
|
55 | 142 | kwargs['title'] = 'Device' |
|
56 | 143 | kwargs['suptitle'] = 'List' |
|
57 | 144 | kwargs['button'] = 'New Device' |
|
58 | 145 | |
|
59 | 146 | return render(request, 'devices.html', kwargs) |
|
60 | 147 | |
|
61 | 148 | def device(request, id_dev): |
|
62 | 149 | |
|
63 | 150 | device = get_object_or_404(Device, pk=id_dev) |
|
64 | 151 | |
|
65 | 152 | kwargs = {} |
|
66 | 153 | kwargs['device'] = device |
|
67 | 154 | kwargs['device_keys'] = ['device_type', 'name', 'ip_address', 'port_address', 'description'] |
|
68 | 155 | |
|
69 | 156 | kwargs['title'] = 'Device' |
|
70 | 157 | kwargs['suptitle'] = 'Details' |
|
71 | 158 | |
|
72 | kwargs['button'] = 'Add Device' | |
|
73 | ||
|
74 | 159 | return render(request, 'device.html', kwargs) |
|
75 | 160 | |
|
76 | 161 | def device_new(request): |
|
77 | 162 | |
|
78 | 163 | if request.method == 'GET': |
|
79 | 164 | form = DeviceForm() |
|
80 | 165 | |
|
81 | 166 | if request.method == 'POST': |
|
82 | 167 | form = DeviceForm(request.POST) |
|
83 | 168 | |
|
84 | 169 | if form.is_valid(): |
|
85 | 170 | form.save() |
|
86 | 171 | return redirect('url_devices') |
|
87 | 172 | |
|
88 | 173 | kwargs = {} |
|
89 | 174 | kwargs['form'] = form |
|
90 | 175 | kwargs['title'] = 'Device' |
|
91 | 176 | kwargs['suptitle'] = 'New' |
|
92 | 177 | kwargs['button'] = 'Create' |
|
93 | 178 | |
|
94 | 179 | return render(request, 'device_edit.html', kwargs) |
|
95 | 180 | |
|
96 | 181 | def device_edit(request, id_dev): |
|
97 | 182 | |
|
98 | 183 | device = get_object_or_404(Device, pk=id_dev) |
|
99 | 184 | |
|
100 | 185 | if request.method=='GET': |
|
101 | 186 | form = DeviceForm(instance=device) |
|
102 | 187 | |
|
103 | 188 | if request.method=='POST': |
|
104 | 189 | form = DeviceForm(request.POST, instance=device) |
|
105 | 190 | |
|
106 | 191 | if form.is_valid(): |
|
107 | 192 | form.save() |
|
108 | 193 | return redirect('url_devices') |
|
109 | 194 | |
|
110 | 195 | kwargs = {} |
|
111 | 196 | kwargs['form'] = form |
|
112 | 197 | kwargs['title'] = 'Device' |
|
113 | 198 | kwargs['suptitle'] = 'Edit' |
|
114 | 199 | kwargs['button'] = 'Update' |
|
115 | 200 | |
|
116 | 201 | return render(request, 'device_edit.html', kwargs) |
|
117 | 202 | |
|
118 | 203 | def device_delete(request, id_dev): |
|
119 | 204 | |
|
120 | 205 | device = get_object_or_404(Device, pk=id_dev) |
|
121 | 206 | |
|
122 | 207 | if request.method=='POST': |
|
123 | 208 | |
|
124 | 209 | if request.user.is_staff: |
|
125 | 210 | device.delete() |
|
126 | 211 | return redirect('url_devices') |
|
127 | 212 | |
|
128 | 213 | return HttpResponse("Not enough permission to delete this object") |
|
129 | 214 | |
|
130 | 215 | kwargs = {'object':device, 'dev_active':'active', |
|
131 | 216 | 'url_cancel':'url_device', 'id_item':id_dev} |
|
132 | 217 | |
|
133 | 218 | return render(request, 'item_delete.html', kwargs) |
|
134 | 219 | |
|
135 | 220 | def campaigns(request): |
|
136 | 221 | |
|
137 | 222 | campaigns = Campaign.objects.all().order_by('start_date') |
|
138 | 223 | |
|
139 | 224 | keys = ['id', 'name', 'start_date', 'end_date'] |
|
140 | 225 | |
|
141 | 226 | kwargs = {} |
|
142 | 227 | kwargs['campaign_keys'] = keys[1:] |
|
143 | 228 | kwargs['campaigns'] = campaigns#.values(*keys) |
|
144 | 229 | kwargs['title'] = 'Campaign' |
|
145 | 230 | kwargs['suptitle'] = 'List' |
|
146 | 231 | kwargs['button'] = 'New Campaign' |
|
147 | 232 | |
|
148 | 233 | return render(request, 'campaigns.html', kwargs) |
|
149 | 234 | |
|
150 | 235 | def campaign(request, id_camp): |
|
151 | 236 | |
|
152 | 237 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
153 | 238 | experiments = Experiment.objects.filter(campaign=campaign) |
|
154 | 239 | |
|
155 | 240 | form = CampaignForm(instance=campaign) |
|
156 | 241 | |
|
157 | 242 | kwargs = {} |
|
158 | 243 | kwargs['campaign'] = campaign |
|
159 | 244 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] |
|
160 | 245 | |
|
161 | 246 | keys = ['id', 'name', 'start_time', 'end_time'] |
|
162 | 247 | |
|
163 | 248 | kwargs['experiment_keys'] = keys[1:] |
|
164 | 249 | kwargs['experiments'] = experiments.values(*keys) |
|
165 | 250 | |
|
166 | 251 | kwargs['title'] = 'Campaign' |
|
167 | 252 | kwargs['suptitle'] = 'Details' |
|
168 | 253 | |
|
169 | 254 | kwargs['form'] = form |
|
170 | 255 | kwargs['button'] = 'Add Experiment' |
|
171 | 256 | |
|
172 | 257 | return render(request, 'campaign.html', kwargs) |
|
173 | 258 | |
|
174 | 259 | def campaign_new(request): |
|
175 | 260 | |
|
176 | 261 | if request.method == 'GET': |
|
177 | 262 | form = CampaignForm() |
|
178 | 263 | |
|
179 | 264 | if request.method == 'POST': |
|
180 | 265 | form = CampaignForm(request.POST) |
|
181 | 266 | |
|
182 | 267 | if form.is_valid(): |
|
183 | 268 | campaign = form.save() |
|
184 | 269 | return redirect('url_campaign', id_camp=campaign.id) |
|
185 | 270 | |
|
186 | 271 | kwargs = {} |
|
187 | 272 | kwargs['form'] = form |
|
188 | 273 | kwargs['title'] = 'Campaign' |
|
189 | 274 | kwargs['suptitle'] = 'New' |
|
190 | 275 | kwargs['button'] = 'Create' |
|
191 | 276 | |
|
192 | 277 | return render(request, 'campaign_edit.html', kwargs) |
|
193 | 278 | |
|
194 | 279 | def campaign_edit(request, id_camp): |
|
195 | 280 | |
|
196 | 281 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
197 | 282 | |
|
198 | 283 | if request.method=='GET': |
|
199 | 284 | form = CampaignForm(instance=campaign) |
|
200 | 285 | |
|
201 | 286 | if request.method=='POST': |
|
202 | 287 | form = CampaignForm(request.POST, instance=campaign) |
|
203 | 288 | |
|
204 | 289 | if form.is_valid(): |
|
205 | 290 | form.save() |
|
206 | 291 | return redirect('url_campaign', id_camp=id_camp) |
|
207 | 292 | |
|
208 | 293 | kwargs = {} |
|
209 | 294 | kwargs['form'] = form |
|
210 | 295 | kwargs['title'] = 'Campaign' |
|
211 | 296 | kwargs['suptitle'] = 'Edit' |
|
212 | 297 | kwargs['button'] = 'Update' |
|
213 | 298 | |
|
214 | 299 | return render(request, 'campaign_edit.html', kwargs) |
|
215 | 300 | |
|
216 | 301 | def campaign_delete(request, id_camp): |
|
217 | 302 | |
|
218 | 303 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
219 | 304 | |
|
220 | 305 | if request.method=='POST': |
|
221 | 306 | if request.user.is_staff: |
|
222 | 307 | campaign.delete() |
|
223 | 308 | return redirect('url_campaigns') |
|
224 | 309 | |
|
225 | 310 | return HttpResponse("Not enough permission to delete this object") |
|
226 | 311 | |
|
227 | 312 | kwargs = {'object':campaign, 'camp_active':'active', |
|
228 | 313 | 'url_cancel':'url_campaign', 'id_item':id_camp} |
|
229 | 314 | |
|
230 | 315 | return render(request, 'item_delete.html', kwargs) |
|
231 | 316 | |
|
232 | 317 | def experiments(request): |
|
233 | 318 | |
|
234 | 319 | experiment_list = Experiment.objects.all().order_by('campaign') |
|
235 | 320 | |
|
236 | 321 | keys = ['id', 'name', 'start_time', 'end_time', 'campaign'] |
|
237 | 322 | |
|
238 | 323 | kwargs = {} |
|
239 | 324 | |
|
240 | 325 | kwargs['experiment_keys'] = keys[1:] |
|
241 | 326 | kwargs['experiments'] = experiment_list#.values(*keys) |
|
242 | 327 | |
|
243 | 328 | kwargs['title'] = 'Experiment' |
|
244 | 329 | kwargs['suptitle'] = 'List' |
|
245 | 330 | kwargs['button'] = 'New Experiment' |
|
246 | 331 | |
|
247 | 332 | return render(request, 'experiments.html', kwargs) |
|
248 | 333 | |
|
249 | 334 | def experiment(request, id_exp): |
|
250 | 335 | |
|
251 | 336 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
252 | 337 | |
|
253 | 338 | experiments = Experiment.objects.filter(campaign=experiment.campaign) |
|
254 | configurations = Configuration.objects.filter(experiment=experiment) | |
|
339 | configurations = Configuration.objects.filter(experiment=experiment, type=0) | |
|
255 | 340 | |
|
256 | 341 | kwargs = {} |
|
257 | 342 | |
|
258 | 343 | exp_keys = ['id', 'campaign', 'name', 'start_time', 'end_time'] |
|
259 |
conf_keys = ['id', 'device__name', 'device__device_type |
|
|
344 | conf_keys = ['id', 'device__name', 'device__device_type', 'device__ip_address', 'device__port_address'] | |
|
260 | 345 | |
|
346 | conf_labels = ['id', 'device__name', 'device_type', 'ip_address', 'port_address'] | |
|
261 | 347 | |
|
262 | 348 | kwargs['experiment_keys'] = exp_keys[1:] |
|
263 | 349 | kwargs['experiment'] = experiment |
|
264 | 350 | |
|
265 | 351 | kwargs['experiments'] = experiments.values(*exp_keys) |
|
266 | 352 | |
|
353 | kwargs['configuration_labels'] = conf_labels[1:] | |
|
267 | 354 | kwargs['configuration_keys'] = conf_keys[1:] |
|
268 | kwargs['configurations'] = configurations.values(*conf_keys) | |
|
355 | kwargs['configurations'] = configurations #.values(*conf_keys) | |
|
269 | 356 | |
|
270 | 357 | kwargs['title'] = 'Experiment' |
|
271 | 358 | kwargs['suptitle'] = 'Details' |
|
272 | 359 | |
|
273 | 360 | kwargs['button'] = 'Add Device' |
|
274 | 361 | |
|
275 | 362 | return render(request, 'experiment.html', kwargs) |
|
276 | 363 | |
|
277 | 364 | def experiment_new(request, id_camp=0): |
|
278 | 365 | |
|
279 | 366 | if request.method == 'GET': |
|
280 | 367 | form = ExperimentForm(initial={'campaign':id_camp}) |
|
281 | 368 | |
|
282 | 369 | if request.method == 'POST': |
|
283 | 370 | form = ExperimentForm(request.POST, initial={'campaign':id_camp}) |
|
284 | 371 | |
|
285 | 372 | if form.is_valid(): |
|
286 | 373 | experiment = form.save() |
|
287 | 374 | return redirect('url_experiment', id_exp=experiment.id) |
|
288 | 375 | |
|
289 | 376 | kwargs = {} |
|
290 | 377 | kwargs['form'] = form |
|
291 | 378 | kwargs['title'] = 'Experiment' |
|
292 | 379 | kwargs['suptitle'] = 'New' |
|
293 | 380 | kwargs['button'] = 'Create' |
|
294 | 381 | |
|
295 | 382 | return render(request, 'experiment_edit.html', kwargs) |
|
296 | 383 | |
|
297 | 384 | def experiment_edit(request, id_exp): |
|
298 | 385 | |
|
299 | 386 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
300 | 387 | |
|
301 | 388 | if request.method == 'GET': |
|
302 | 389 | form = ExperimentForm(instance=experiment) |
|
303 | 390 | |
|
304 | 391 | if request.method=='POST': |
|
305 | 392 | form = ExperimentForm(request.POST, instance=experiment) |
|
306 | 393 | |
|
307 | 394 | if form.is_valid(): |
|
308 | 395 | experiment = form.save() |
|
309 | 396 | return redirect('url_experiment', id_exp=experiment.id) |
|
310 | 397 | |
|
311 | 398 | kwargs = {} |
|
312 | 399 | kwargs['form'] = form |
|
313 | 400 | kwargs['title'] = 'Experiment' |
|
314 | 401 | kwargs['suptitle'] = 'Edit' |
|
315 | 402 | kwargs['button'] = 'Update' |
|
316 | 403 | |
|
317 | 404 | return render(request, 'experiment_edit.html', kwargs) |
|
318 | 405 | |
|
319 | 406 | def experiment_delete(request, id_exp): |
|
320 | 407 | |
|
321 | 408 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
322 | 409 | |
|
323 | 410 | if request.method=='POST': |
|
324 | 411 | if request.user.is_staff: |
|
325 | 412 | id_camp = experiment.campaign.id |
|
326 | 413 | experiment.delete() |
|
327 | 414 | return redirect('url_campaign', id_camp=id_camp) |
|
328 | 415 | |
|
329 | 416 | return HttpResponse("Not enough permission to delete this object") |
|
330 | 417 | |
|
331 | 418 | kwargs = {'object':experiment, 'exp_active':'active', |
|
332 | 419 | 'url_cancel':'url_experiment', 'id_item':id_exp} |
|
333 | 420 | |
|
334 | 421 | return render(request, 'item_delete.html', kwargs) |
|
335 | 422 | |
|
336 | 423 | def dev_confs(request): |
|
337 | 424 | |
|
338 | configurations = Configuration.objects.all().order_by('experiment') | |
|
425 | configurations = Configuration.objects.all().order_by('type', 'device__device_type', 'experiment') | |
|
339 | 426 | |
|
340 | 427 | # keys = ['id', 'device__device_type__name', 'device__name', 'experiment__campaign__name', 'experiment__name'] |
|
341 | 428 | |
|
342 | 429 | keys = ['id', 'device', 'experiment', 'type', 'programmed_date'] |
|
343 | 430 | |
|
344 | 431 | kwargs = {} |
|
345 | 432 | |
|
346 | 433 | kwargs['configuration_keys'] = keys[1:] |
|
347 | 434 | kwargs['configurations'] = configurations#.values(*keys) |
|
348 | 435 | |
|
349 | 436 | kwargs['title'] = 'Configuration' |
|
350 | 437 | kwargs['suptitle'] = 'List' |
|
351 | 438 | kwargs['button'] = 'New Configuration' |
|
352 | 439 | |
|
353 | 440 | return render(request, 'dev_confs.html', kwargs) |
|
354 | 441 | |
|
355 | 442 | def dev_conf(request, id_conf): |
|
356 | 443 | |
|
357 | 444 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
358 | 445 | |
|
359 | 446 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
360 | 447 | dev_conf = DevConfModel.objects.get(pk=id_conf) |
|
361 | 448 | |
|
362 | 449 | kwargs = {} |
|
363 | 450 | kwargs['dev_conf'] = dev_conf |
|
364 | 451 | kwargs['dev_conf_keys'] = ['experiment', 'device'] |
|
365 | 452 | |
|
366 | 453 | kwargs['title'] = 'Configuration' |
|
367 | 454 | kwargs['suptitle'] = 'Details' |
|
368 | 455 | |
|
369 | 456 | kwargs['button'] = 'Edit Configuration' |
|
370 | 457 | |
|
371 | 458 | ###### SIDEBAR ###### |
|
372 | 459 | kwargs.update(sidebar(conf)) |
|
373 | 460 | |
|
374 | 461 | return render(request, 'dev_conf.html', kwargs) |
|
375 | 462 | |
|
376 | 463 | def dev_conf_new(request, id_exp=0): |
|
377 | 464 | |
|
378 | 465 | if request.method == 'GET': |
|
379 | 466 | form = ConfigurationForm(initial={'experiment':id_exp}) |
|
380 | 467 | |
|
381 | 468 | if request.method == 'POST': |
|
382 | 469 | form = ConfigurationForm(request.POST) |
|
383 | 470 | |
|
384 | 471 | if form.is_valid(): |
|
385 | 472 | experiment = Experiment.objects.get(pk=request.POST['experiment']) |
|
386 | 473 | device = Device.objects.get(pk=request.POST['device']) |
|
387 | 474 | |
|
388 |
exp_devices = Device.objects.filter(configuration__experiment=experiment |
|
|
475 | exp_devices = Device.objects.filter(configuration__experiment=experiment, | |
|
476 | configuration__type=0) | |
|
389 | 477 | |
|
390 | 478 | if device.id not in exp_devices.values('id',): |
|
391 | 479 | |
|
392 | 480 | DevConfModel = CONF_MODELS[device.device_type.name] |
|
393 | 481 | conf = DevConfModel(experiment=experiment, device=device) |
|
394 | 482 | conf.save() |
|
395 | ||
|
483 | ||
|
396 | 484 | return redirect('url_experiment', id_exp=experiment.id) |
|
397 | 485 | |
|
398 | 486 | kwargs = {} |
|
399 | 487 | kwargs['form'] = form |
|
400 | 488 | kwargs['title'] = 'Configuration' |
|
401 | 489 | kwargs['suptitle'] = 'New' |
|
402 | 490 | kwargs['button'] = 'Create' |
|
403 | 491 | |
|
404 | ###### SIDEBAR ###### | |
|
405 | kwargs.update(sidebar(conf)) | |
|
406 | ||
|
407 | 492 | return render(request, 'dev_conf_edit.html', kwargs) |
|
408 | 493 | |
|
409 | 494 | def dev_conf_edit(request, id_conf): |
|
410 | 495 | |
|
411 | 496 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
412 | 497 | |
|
413 | 498 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
414 | 499 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
415 | 500 | |
|
416 | 501 | dev_conf = DevConfModel.objects.get(pk=id_conf) |
|
417 | 502 | |
|
418 | 503 | if request.method=='GET': |
|
419 | 504 | form = DevConfForm(instance=dev_conf) |
|
420 | 505 | |
|
421 | 506 | if request.method=='POST': |
|
422 | 507 | form = DevConfForm(request.POST, instance=dev_conf) |
|
423 | 508 | |
|
424 | 509 | if form.is_valid(): |
|
425 | 510 | form.save() |
|
426 | 511 | return redirect('url_dev_conf', id_conf=id_conf) |
|
427 | 512 | |
|
428 | 513 | kwargs = {} |
|
429 | 514 | kwargs['form'] = form |
|
430 | 515 | kwargs['title'] = 'Device Configuration' |
|
431 | 516 | kwargs['suptitle'] = 'Edit' |
|
432 | 517 | kwargs['button'] = 'Update' |
|
433 | 518 | |
|
434 | 519 | ###### SIDEBAR ###### |
|
435 | 520 | kwargs.update(sidebar(conf)) |
|
436 | 521 | |
|
437 | 522 | return render(request, 'dev_conf_edit.html', kwargs) |
|
438 | 523 | |
|
439 | 524 | def dev_conf_read(request, id_conf): |
|
440 | 525 | |
|
441 | 526 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
442 | 527 | |
|
443 | 528 | messages.error(request, "Read View not implemented yet") |
|
444 | 529 | |
|
445 | 530 | return redirect('url_dev_conf', id_conf=conf.id) |
|
446 | 531 | |
|
447 | 532 | def dev_conf_write(request, id_conf): |
|
448 | 533 | |
|
449 | 534 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
450 | 535 | |
|
451 | 536 | messages.error(request, "Write View not implemented yet") |
|
452 | 537 | |
|
453 | 538 | return redirect('url_dev_conf', id_conf=conf.id) |
|
454 | 539 | |
|
455 | 540 | def dev_conf_import(request, id_conf): |
|
456 | 541 | |
|
457 | 542 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
458 | 543 | |
|
459 | 544 | messages.error(request, "Import View not implemented yet") |
|
460 | 545 | |
|
461 | 546 | return redirect('url_dev_conf', id_conf=conf.id) |
|
462 | 547 | |
|
463 | 548 | def dev_conf_export(request, id_conf): |
|
464 | 549 | |
|
465 | 550 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
466 | 551 | |
|
467 | 552 | messages.error(request, "Export View not implemented yet") |
|
468 | 553 | |
|
469 | 554 | return redirect('url_dev_conf', id_conf=conf.id) |
|
470 | 555 | |
|
471 | 556 | def dev_conf_delete(request, id_conf): |
|
472 | 557 | |
|
473 | 558 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
474 | 559 | |
|
475 | 560 | if request.method=='POST': |
|
476 | 561 | if request.user.is_staff: |
|
477 | 562 | id_exp = conf.experiment.id |
|
478 | 563 | conf.delete() |
|
479 | 564 | return redirect('url_experiment', id_exp=id_exp) |
|
480 | 565 | |
|
481 | 566 | return HttpResponse("Not enough permission to delete this object") |
|
482 | 567 | |
|
483 | 568 | kwargs = {'object':conf, 'conf_active':'active', |
|
484 | 569 | 'url_cancel':'url_dev_conf', 'id_item':id_conf} |
|
485 | 570 | |
|
486 | 571 | ###### SIDEBAR ###### |
|
487 | 572 | kwargs.update(sidebar(conf)) |
|
488 | 573 | |
|
489 | 574 | return render(request, 'item_delete.html', kwargs) |
|
490 | 575 | |
|
491 | 576 | def sidebar(conf): |
|
492 | 577 | |
|
493 | 578 | experiments = Experiment.objects.filter(campaign=conf.experiment.campaign) |
|
494 | 579 | configurations = Configuration.objects.filter(experiment=conf.experiment, type=0) |
|
495 | 580 | |
|
496 | 581 | exp_keys = ['id', 'campaign', 'name', 'start_time', 'end_time'] |
|
497 | conf_keys = ['id', 'device__name', 'device__device_type__name', 'device__ip_address'] | |
|
582 | conf_keys = ['id', 'device'] | |
|
498 | 583 | |
|
499 | 584 | kwargs = {} |
|
500 | 585 | |
|
501 | 586 | kwargs['dev_conf'] = conf |
|
502 | 587 | |
|
503 | 588 | kwargs['experiment_keys'] = exp_keys[1:] |
|
504 | 589 | kwargs['experiments'] = experiments.values(*exp_keys) |
|
505 | 590 | |
|
506 | 591 | kwargs['configuration_keys'] = conf_keys[1:] |
|
507 | kwargs['configurations'] = configurations.values(*conf_keys) | |
|
592 | kwargs['configurations'] = configurations #.values(*conf_keys) | |
|
508 | 593 | |
|
509 | 594 | return kwargs No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now