@@ -0,0 +1,21 | |||
|
1 | from django import forms | |
|
2 | from .models import Device, Experiment, ExperimentTemplate | |
|
3 | ||
|
4 | def add_empty_choice(choices, pos=0, label='-----'): | |
|
5 | if len(choices)>0: | |
|
6 | choices = list(choices) | |
|
7 | choices.insert(0, (0, label)) | |
|
8 | return choices | |
|
9 | else: | |
|
10 | return [(0, label)] | |
|
11 | ||
|
12 | class ExperimentForm(forms.ModelForm): | |
|
13 | class Meta: | |
|
14 | model = Experiment | |
|
15 | fields = ['name', 'alias', 'start_date', 'end_date'] | |
|
16 | ||
|
17 | ||
|
18 | class TemplatesForm(forms.Form): | |
|
19 | template = forms.ChoiceField(choices=add_empty_choice(ExperimentTemplate.objects.all().values_list('id', 'experiment_detail__experiment__name')), | |
|
20 | required=False) | |
|
21 | No newline at end of file |
@@ -0,0 +1,22 | |||
|
1 | {% extends "base.html" %} | |
|
2 | {% load bootstrap3 %} | |
|
3 | {% block exp-active %}active{% endblock %} | |
|
4 | ||
|
5 | {% block content-title %}Experiments{% endblock %} | |
|
6 | {% block content-suptitle %}New{% endblock %} | |
|
7 | ||
|
8 | {% block content %} | |
|
9 | <div class='col-md-8'> | |
|
10 | <form class="form" method="post" action="{% url 'new_experiment' %}"> | |
|
11 | {% csrf_token %} | |
|
12 | {% bootstrap_form form layout='horizontal' size='medium' %} | |
|
13 | <div style="clear: both;"></div> | |
|
14 | <br> | |
|
15 | <button type="submit" class="btn btn-primary pull-right">Create</button> | |
|
16 | </form> | |
|
17 | </div> | |
|
18 | ||
|
19 | {% endblock %} | |
|
20 | ||
|
21 | {% block sidebar%} | |
|
22 | {% endblock %} |
@@ -6,6 +6,7 | |||
|
6 | 6 | {% block content-suptitle %}Authetication{% endblock %} |
|
7 | 7 | |
|
8 | 8 | {% block content %} |
|
9 | <div class='col-md-8'> | |
|
9 | 10 | <form class="form" method="post" action="{% url 'django.contrib.auth.views.login' %}"> |
|
10 | 11 | {% csrf_token %} |
|
11 | 12 | {% bootstrap_form form %} |
@@ -14,6 +15,7 | |||
|
14 | 15 | <button type="submit" class="btn btn-primary">Login</button> |
|
15 | 16 | {% endbuttons %} |
|
16 | 17 | </form> |
|
18 | </div> | |
|
17 | 19 | {% endblock %} |
|
18 | 20 | |
|
19 | 21 | {% block messages%} |
@@ -1,3 +1,11 | |||
|
1 | 1 | from django.contrib import admin |
|
2 | from .models import Device, DeviceType, Experiment, ExperimentDetail, ExperimentTemplate, Configuration | |
|
2 | 3 | |
|
3 | 4 | # Register your models here. |
|
5 | ||
|
6 | admin.site.register(Experiment) | |
|
7 | admin.site.register(ExperimentDetail) | |
|
8 | admin.site.register(ExperimentTemplate) | |
|
9 | admin.site.register(Device) | |
|
10 | admin.site.register(Configuration) | |
|
11 | admin.site.register(DeviceType) No newline at end of file |
@@ -1,3 +1,84 | |||
|
1 | 1 | from django.db import models |
|
2 | 2 | |
|
3 | STATES = ( | |
|
4 | (0, 'Inactive'), | |
|
5 | (1, 'Active'), | |
|
6 | ) | |
|
7 | ||
|
3 | 8 | # Create your models here. |
|
9 | ||
|
10 | class DeviceType(models.Model): | |
|
11 | ||
|
12 | name = models.CharField(max_length=40) | |
|
13 | alias = models.CharField(max_length=40) | |
|
14 | info = models.TextField(blank=True, null=True) | |
|
15 | status = models.PositiveSmallIntegerField(default=1, choices=STATES) | |
|
16 | ||
|
17 | class Meta: | |
|
18 | db_table = 'device_types' | |
|
19 | ||
|
20 | def __unicode__(self): | |
|
21 | return u'%s' % self.alias | |
|
22 | ||
|
23 | class Device(models.Model): | |
|
24 | ||
|
25 | device_type = models.ForeignKey(DeviceType) | |
|
26 | model = models.CharField(max_length=40, default='') | |
|
27 | serial = models.CharField(max_length=40, default='') | |
|
28 | ip_address = models.GenericIPAddressField(protocol='IPv4', default='0.0.0.0') | |
|
29 | status = models.PositiveSmallIntegerField(default=1, choices=STATES) | |
|
30 | ||
|
31 | class Meta: | |
|
32 | db_table = 'devices' | |
|
33 | ||
|
34 | def __unicode__(self): | |
|
35 | return u'%s-%s' % (self.device_type, self.ip_address) | |
|
36 | ||
|
37 | class Experiment(models.Model): | |
|
38 | ||
|
39 | name = models.CharField(max_length=40) | |
|
40 | alias = models.CharField(max_length=40) | |
|
41 | start_date = models.DateTimeField() | |
|
42 | end_date = models.DateTimeField() | |
|
43 | status = models.PositiveSmallIntegerField(default=1, choices=STATES) | |
|
44 | ||
|
45 | class Meta: | |
|
46 | db_table = 'experiments' | |
|
47 | ||
|
48 | def __unicode__(self): | |
|
49 | return u'%s: %s-%s' % (self.name, self.start_date, self.end_date) | |
|
50 | ||
|
51 | class Configuration(models.Model): | |
|
52 | ||
|
53 | device = models.ForeignKey(Device) | |
|
54 | parameters = models.TextField() | |
|
55 | status = models.PositiveSmallIntegerField(default=1, choices=STATES) | |
|
56 | ||
|
57 | def __unicode__(self): | |
|
58 | return u'%s Conf' % self.device | |
|
59 | class Meta: | |
|
60 | db_table = 'configurations' | |
|
61 | ||
|
62 | class ExperimentDetail(models.Model): | |
|
63 | ||
|
64 | experiment = models.ForeignKey(Experiment) | |
|
65 | configurations = models.ManyToManyField(Configuration) | |
|
66 | status = models.PositiveSmallIntegerField(default=1, choices=STATES) | |
|
67 | ||
|
68 | class Meta: | |
|
69 | db_table = 'experiments_detail' | |
|
70 | ||
|
71 | def __unicode__(self): | |
|
72 | return u'%s Configuration' % self.experiment.name | |
|
73 | ||
|
74 | class ExperimentTemplate(models.Model): | |
|
75 | ||
|
76 | experiment_detail = models.ForeignKey(ExperimentDetail) | |
|
77 | status = models.PositiveSmallIntegerField(default=1, choices=STATES) | |
|
78 | ||
|
79 | class Meta: | |
|
80 | db_table = 'templates' | |
|
81 | ||
|
82 | def __unicode__(self): | |
|
83 | return u'%s Template' % (self.experiment_detail.experiment.name) | |
|
84 | No newline at end of file |
@@ -1,6 +1,4 | |||
|
1 | 1 | <!DOCTYPE html> |
|
2 | {% load bootstrap3 %} | |
|
3 | {% load url from future %} | |
|
4 | 2 | {% load static %} |
|
5 | 3 | <html lang="en"> |
|
6 | 4 | <head> |
@@ -13,7 +11,7 | |||
|
13 | 11 | <link href="{% static 'css/bootstrap-flatly.min.css' %}" media="screen" rel="stylesheet"> |
|
14 | 12 | <style type="text/css"> |
|
15 | 13 | body {padding-top: 60px} |
|
16 |
.logo {height: |
|
|
14 | .logo {padding-top: 5px; height: 50px} | |
|
17 | 15 | </style> |
|
18 | 16 | <!--[if lt IE 9]> |
|
19 | 17 | <script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script> |
@@ -34,11 +32,24 | |||
|
34 | 32 | <span class="icon-bar"></span> |
|
35 | 33 | <span class="icon-bar"></span> |
|
36 | 34 | </button> |
|
37 |
<a class="navbar-brand" href=" |
|
|
35 | <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> | |
|
38 | 36 | </div> |
|
39 | 37 | <div class="collapse navbar-collapse" id="navigationbar"> |
|
40 | 38 | <ul class="nav navbar-nav"> |
|
41 | <li class="{% block mainactive %}{% endblock %}"><a href="{% url 'apps.main.views.index' %}">About</a></li> | |
|
39 | <li class=" dropdown {% block exp-active %}{% endblock %}"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Experiments<span class="caret"></span></a> | |
|
40 | <ul class="dropdown-menu" role="menu"> | |
|
41 | <li><a href="{% url 'index' %}">Templates</a></li> | |
|
42 | <li><a href="#">Search</a></li> | |
|
43 | <li><a href="{% url 'new_experiment'%}">New</a></li> | |
|
44 | </ul> | |
|
45 | </li> | |
|
46 | <li class=" dropdown {% block dev-active %}{% endblock %}"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Devices<span class="caret"></span></a> | |
|
47 | <ul class="dropdown-menu" role="menu"> | |
|
48 | <li><a href="#">Scan</a></li> | |
|
49 | <li><a href="#">Search</a></li> | |
|
50 | <li><a href="{% url 'new_device'%}">New</a></li> | |
|
51 | </ul> | |
|
52 | </li> | |
|
42 | 53 | </ul> |
|
43 | 54 | <ul class="nav navbar-nav navbar-right"> |
|
44 | 55 | <li class="nav-divider"></li> |
@@ -62,10 +73,10 | |||
|
62 | 73 | |
|
63 | 74 | <div class="container"> |
|
64 | 75 |
|
|
65 | <div class="col-md-9 col-xs-12" role="main"> | |
|
66 | 76 |
|
|
67 | 77 |
|
|
68 | 78 |
|
|
79 | <div class="col-md-9 col-xs-12" role="main"> | |
|
69 | 80 |
|
|
70 | 81 |
|
|
71 | 82 |
|
@@ -97,7 +108,7 | |||
|
97 | 108 | {# bootstrap_javascript jquery=True #} |
|
98 | 109 | <script src="{% static 'js/jquery.min.js' %}"></script> |
|
99 | 110 | <script src="{% static 'js/bootstrap.min.js' %}"></script> |
|
100 |
{% block |
|
|
111 | {% block extra-js %} | |
|
101 | 112 | {% endblock%} |
|
102 | 113 | </body> |
|
103 | 114 | </html> |
@@ -1,14 +1,59 | |||
|
1 | 1 | {% extends "base.html" %} |
|
2 | {% block mainactive %}active{% endblock %} | |
|
3 | ||
|
4 |
{% block content-title %} |
|
|
5 |
{% block content-suptitle %} |
|
|
2 | {% load bootstrap3 %} | |
|
3 | {% block exp-active %}active{% endblock %} | |
|
4 | {% block content-title %}Experiments{% endblock %} | |
|
5 | {% block content-suptitle %}{% endblock %} | |
|
6 | 6 | |
|
7 | 7 | {% block content %} |
|
8 | <p class="text-justify"> | |
|
9 | {% lorem %} | |
|
10 | </p> | |
|
8 | <div class='col-md-8'> | |
|
9 | {% bootstrap_form form size='medium' %} | |
|
10 | </div> | |
|
11 | <div style="clear: both;"></div> | |
|
12 | <br> | |
|
13 | <table class="table"> | |
|
14 | <tr> | |
|
15 | <th>Device</th> | |
|
16 | <th>IP Adress</th> | |
|
17 | <th>Model</th> | |
|
18 | <th>Status</th> | |
|
19 | </tr> | |
|
20 | {% for device in devices %} | |
|
21 | <tr> | |
|
22 | <td>{{device.device_type.name}}</td> | |
|
23 | <td>{{device.ip_address}}</td> | |
|
24 | <td>{{device.model}}</td> | |
|
25 | <td>{{device.status}}</td> | |
|
26 | </tr> | |
|
27 | {% endfor %} | |
|
28 | </table> | |
|
29 | <div style="clear: both;"></div> | |
|
30 | <br> | |
|
31 | <button class="btn btn-primary">Add Device</button> | |
|
11 | 32 | {% endblock %} |
|
12 | 33 | |
|
13 | 34 | {% block sidebar%} |
|
35 | {% if devices %} | |
|
36 | <div class="panel panel-default"> | |
|
37 | <div class="panel-heading"> | |
|
38 | <h3 class="panel-title">Devices</h3> | |
|
39 | </div> | |
|
40 | {% block sidebar-content %} | |
|
41 | <div class="list-group"> | |
|
42 | {% for device in devices %} | |
|
43 | <a href="#" class="list-group-item {{device.active}}">{{device.device_type.name}}</a> | |
|
44 | {% endfor %} | |
|
45 | </div> | |
|
46 | {% endblock %} | |
|
47 | </div> | |
|
48 | {% endif %} | |
|
49 | {% endblock %} | |
|
50 | ||
|
51 | {% block extra-js%} | |
|
52 | <script type="text/javascript"> | |
|
53 | $('#id_template').change(function(){ | |
|
54 | if($(this).val() != "0"){ | |
|
55 | location.href="/main/experiment/"+$(this).val()+"/"; | |
|
56 | } | |
|
57 | }); | |
|
58 | </script> | |
|
14 | 59 | {% endblock %} No newline at end of file |
@@ -1,5 +1,7 | |||
|
1 |
from django.conf.urls import |
|
|
1 | from django.conf.urls import url | |
|
2 | 2 | |
|
3 | urlpatterns = patterns('apps.main.views', | |
|
4 | url(r'^$', 'index', name="index"), | |
|
3 | urlpatterns = ( | |
|
4 | url(r'^new/experiment/$', 'apps.main.views.new_experiment', name='new_experiment'), | |
|
5 | url(r'^new/device/$', 'apps.main.views.new_device', name='new_device'), | |
|
6 | url(r'^experiment/(?P<idtemplate>-?\d+)/$', 'apps.main.views.index', name='template'), | |
|
5 | 7 | ) |
@@ -1,8 +1,35 | |||
|
1 | 1 | from django.shortcuts import render,render_to_response |
|
2 | 2 | from django.template import RequestContext |
|
3 | from .forms import ExperimentForm, TemplatesForm | |
|
3 | 4 | |
|
5 | from .models import ExperimentTemplate, Device | |
|
4 | 6 | # Create your views here. |
|
5 | 7 | |
|
6 | def index(request): | |
|
8 | def index(request, idtemplate=0): | |
|
7 | 9 | kwargs = {} |
|
10 | if idtemplate not in (0, "0"): | |
|
11 | form = TemplatesForm(initial={'template':idtemplate}) | |
|
12 | template = ExperimentTemplate.objects.get(id=idtemplate) | |
|
13 | devices = Device.objects.filter(configuration__experimentdetail__experiment=template.experiment_detail.experiment) | |
|
14 | kwargs['devices'] = devices | |
|
15 | else: | |
|
16 | form = TemplatesForm() | |
|
17 | kwargs['form'] = form | |
|
8 | 18 | return render_to_response("index.html", kwargs, context_instance=RequestContext(request)) |
|
19 | ||
|
20 | def new_experiment(request): | |
|
21 | kwargs = {} | |
|
22 | if request.method == 'POST': | |
|
23 | form = ExperimentForm(request.POST) | |
|
24 | if form.is_valid(): | |
|
25 | form.save() | |
|
26 | return render_to_response("index.html", kwargs, context_instance=RequestContext(request)) | |
|
27 | else: | |
|
28 | form = ExperimentForm() | |
|
29 | kwargs['form'] = form | |
|
30 | return render_to_response("new_experiment.html", kwargs, context_instance=RequestContext(request)) | |
|
31 | ||
|
32 | def new_device(request): | |
|
33 | kwargs = {} | |
|
34 | ||
|
35 | return render_to_response("new_device.html", kwargs, context_instance=RequestContext(request)) No newline at end of file |
|
1 | NO CONTENT: modified file |
@@ -17,8 +17,9 from django.conf.urls import include, url | |||
|
17 | 17 | from django.contrib import admin |
|
18 | 18 | |
|
19 | 19 | urlpatterns = [ |
|
20 | url(r'^$', 'apps.main.views.index', name='index'), | |
|
20 | 21 | url(r'^admin/', include(admin.site.urls)), |
|
21 |
url(r'^ |
|
|
22 | url(r'^main/', include('apps.main.urls')), | |
|
22 | 23 | url(r'^accounts/', include('apps.accounts.urls')), |
|
23 | 24 | url(r'^rc/', include('apps.rc.urls')), |
|
24 | 25 | url(r'^dds/', include('apps.dds.urls')), |
General Comments 0
You need to be logged in to leave comments.
Login now