##// END OF EJS Templates
Actualizacion de templates y modelos base #263...
Juan C. Espinoza -
r2:6a62ac45a3cd
parent child
Show More
@@ -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 %}
@@ -1,23 +1,25
1 1 {% extends "base.html" %}
2 2 {% load bootstrap3 %}
3 3 {% block mainactive %}active{% endblock %}
4 4
5 5 {% block content-title %}SIR{% endblock %}
6 6 {% block content-suptitle %}Authetication{% endblock %}
7 7
8 8 {% block content %}
9 <form class="form" method="post" action="{% url 'django.contrib.auth.views.login' %}">
9 <div class='col-md-8'>
10 <form class="form" method="post" action="{% url 'django.contrib.auth.views.login' %}">
10 11 {% csrf_token %}
11 12 {% bootstrap_form form %}
12 13 <input type="hidden" name="next" value="{{ next }}" />
13 14 {% buttons %}
14 15 <button type="submit" class="btn btn-primary">Login</button>
15 16 {% endbuttons %}
16 </form>
17 </form>
18 </div>
17 19 {% endblock %}
18 20
19 21 {% block messages%}
20 22 {% endblock %}
21 23
22 24 {% block sidebar%}
23 25 {% endblock %}
@@ -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,104 +1,115
1 1 <!DOCTYPE html>
2 {% load bootstrap3 %}
3 {% load url from future %}
4 2 {% load static %}
5 3 <html lang="en">
6 4 <head>
7 5 <meta charset="utf-8">
8 6 <title>{% block title %}Jicamarca Integrated Radar System:::::{% endblock %}</title>
9 7 <meta name="description" content="">
10 8 <meta name="author" content="">
11 9 <meta name="viewport" content="width=device-width, initial-scale=1">
12 10 {# bootstrap_css #}
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: 45px}
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>
20 18 <![endif]-->
21 19 {% block extra_head %}
22 20 {% endblock %}
23 21 </head>
24 22
25 23 <body>
26 24
27 25 {% block main_menu %}
28 26 <nav class="navbar navbar-default navbar-fixed-top" role="banner">
29 27 <div class="container-fluid">
30 28 <div class="navbar-header">
31 29 <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navigationbar">
32 30 <span class="sr-only">Toggle navigation</span>
33 31 <span class="icon-bar"></span>
34 32 <span class="icon-bar"></span>
35 33 <span class="icon-bar"></span>
36 34 </button>
37 <a class="navbar-brand" href="/" style="padding-top:1px"><img class="logo" alt="JRO" src="{% static "images/logo-jro-white-trans.png" %}"></a>
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 <ul class="nav navbar-nav">
41 <li class="{% block mainactive %}{% endblock %}"><a href="{% url 'apps.main.views.index' %}">About</a></li>
38 <ul class="nav navbar-nav">
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>
45 56 {% if user.is_authenticated %}
46 57 <li class="dropdown">
47 58 <a href="#" class="dropdown-toggle" data-toggle="dropdown">Hi {{ user.username }}<span class="caret"></span></a>
48 59 <ul class="dropdown-menu" role="menu">
49 60 <li><a href="#">Control Panel</a></li>
50 61 <li><a href="{% url 'django.contrib.auth.views.logout' %}">Logout</a></li>
51 62 </ul>
52 63 </li>
53 64 {% else %}
54 65 <li><a href="{% url 'django.contrib.auth.views.login' %}?next={{request.get_full_path}}">Login</a></li>
55 66 {% endif %}
56 67 </ul>
57 68 </div>
58 69 </div>
59 70 </nav>
60 71 <div style="clear: both;"></div>
61 72 {% endblock %}
62 73
63 74 <div class="container">
64 <div id="page" class="row" style="min-height:600px">
65 <div class="col-md-9 col-xs-12" role="main">
66 <div class="page-header">
67 <h1>{% block content-title %}{% endblock %} <small>{% block content-suptitle %}{% endblock %}</small></h1>
68 </div>
69 {% block content %}
70 {% endblock %}
71 <br>
72 {% block messages %}
73 {% endblock %}
74 </div>
75 <div class="col-md-3 hidden-xs hidden-sm" role="complementary">
76 <div id="sidebar" >
77 {% block sidebar %}
78 {% endblock %}
79 </div>
80 </div>
75 <div id="page" class="row" style="min-height:600px">
76 <div class="page-header">
77 <h1>{% block content-title %}{% endblock %} <small>{% block content-suptitle %}{% endblock %}</small></h1>
78 </div>
79 <div class="col-md-9 col-xs-12" role="main">
80 {% block content %}
81 {% endblock %}
82 <br>
83 {% block messages %}
84 {% endblock %}
85 </div>
86 <div class="col-md-3 hidden-xs hidden-sm" role="complementary">
87 <div id="sidebar">
88 {% block sidebar%}
89 {% endblock %}
90 </div>
91 </div>
81 92 </div><!--/row-->
82 93 </div> <!-- container -->
83 94
84 95 <div id="debug">{{debug}}</div>
85 96
86 97 {% block footer %}
87 98 <footer class="footer">
88 99 <div class="container">
89 100 <p><hr></p>
90 101 <p>
91 102 &copy; <a href="http://jro.igp.gob.pe">Jicamarca Radio Observatory</a> - {% now "Y" %}
92 103 </p>
93 104 </div>
94 105 </footer>
95 106 {% endblock %}
96 107
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 js_extra %}
111 {% block extra-js %}
101 112 {% endblock%}
102 113 </body>
103 114 </html>
104 115
@@ -1,14 +1,59
1 1 {% extends "base.html" %}
2 {% block mainactive %}active{% endblock %}
3
4 {% block content-title %}TITLE{% endblock %}
5 {% block content-suptitle %}Suptitle{% endblock %}
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 %}
14 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>
59 {% endblock %} No newline at end of file
@@ -1,5 +1,7
1 from django.conf.urls import patterns, url
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,121 +1,121
1 1 """
2 2 Django settings for radarsys project.
3 3
4 4 Generated by 'django-admin startproject' using Django 1.8.6.
5 5
6 6 For more information on this file, see
7 7 https://docs.djangoproject.com/en/1.8/topics/settings/
8 8
9 9 For the full list of settings and their values, see
10 10 https://docs.djangoproject.com/en/1.8/ref/settings/
11 11 """
12 12
13 13 # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
14 14 import os
15 15
16 16 BASE_DIR = os.path.dirname(os.path.abspath(__file__))
17 17
18 18 # Quick-start development settings - unsuitable for production
19 19 # See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
20 20
21 21 # SECURITY WARNING: keep the secret key used in production secret!
22 22 SECRET_KEY = 'xshb$k5fc-+j16)cvyffj&9u__0q3$l!hieh#+tbzqg)*f^km0'
23 23
24 24 # SECURITY WARNING: don't run with debug turned on in production!
25 25 DEBUG = True
26 26
27 27 ALLOWED_HOSTS = []
28 28
29 29 # Application definition
30 30
31 31 INSTALLED_APPS = (
32 32 'django.contrib.admin',
33 33 'django.contrib.auth',
34 34 'django.contrib.contenttypes',
35 35 'django.contrib.sessions',
36 36 'django.contrib.messages',
37 37 'django.contrib.staticfiles',
38 38 'bootstrap3',
39 39 'apps.accounts',
40 40 'apps.main',
41 41 'apps.misc',
42 42 'apps.rc',
43 43 'apps.dds',
44 44 'apps.cgs',
45 45 'apps.acq',
46 46 'apps.abs',
47 47 )
48 48
49 49 MIDDLEWARE_CLASSES = (
50 50 'django.contrib.sessions.middleware.SessionMiddleware',
51 51 'django.middleware.common.CommonMiddleware',
52 52 'django.middleware.csrf.CsrfViewMiddleware',
53 53 'django.contrib.auth.middleware.AuthenticationMiddleware',
54 54 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
55 55 'django.contrib.messages.middleware.MessageMiddleware',
56 56 'django.middleware.clickjacking.XFrameOptionsMiddleware',
57 57 'django.middleware.security.SecurityMiddleware',
58 58 )
59 59
60 60 ROOT_URLCONF = 'radarsys.urls'
61 61
62 62 TEMPLATES = [
63 63 {
64 64 'BACKEND': 'django.template.backends.django.DjangoTemplates',
65 65 'DIRS': [os.path.join(BASE_DIR, "templates").replace('\\', '/'),],
66 66 'APP_DIRS': True,
67 67 'OPTIONS': {
68 68 'context_processors': [
69 69 'django.template.context_processors.debug',
70 70 'django.template.context_processors.request',
71 71 'django.contrib.auth.context_processors.auth',
72 72 'django.contrib.messages.context_processors.messages',
73 73 ],
74 74 },
75 75 },
76 76 ]
77 77
78 78 WSGI_APPLICATION = 'radarsys.wsgi.application'
79 79
80 80
81 81 # Database
82 82 # https://docs.djangoproject.com/en/1.8/ref/settings/#databases
83 83
84 84 DATABASES = {
85 85 'default': {
86 86 'ENGINE': 'django.db.backends.mysql',
87 87 'NAME': 'radarsys',
88 88 'USER': 'developer',
89 89 'PASSWORD': 'idi2015',
90 90 }
91 91 }
92 92
93 93
94 94 # Internationalization
95 95 # https://docs.djangoproject.com/en/1.8/topics/i18n/
96 96
97 97 LANGUAGE_CODE = 'en-us'
98 98
99 99 TIME_ZONE = 'UTC'
100 100
101 101 USE_I18N = True
102 102
103 103 USE_L10N = True
104 104
105 105 USE_TZ = True
106 106
107 107 # Static files (CSS, JavaScript, Images)
108 108 # https://docs.djangoproject.com/en/1.8/howto/static-files/
109 109
110 110 STATIC_URL = '/static/'
111 111 STATIC_ROOT = '/var/www/html/static/'
112 112
113 113 STATICFILES_DIRS = (
114 114 os.path.join(BASE_DIR, 'apps', 'main', 'static'),
115 115
116 116 )
117 117
118 118 STATICFILES_FINDERS = (
119 119 'django.contrib.staticfiles.finders.FileSystemFinder',
120 120 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
121 ) No newline at end of file
121 )
@@ -1,29 +1,30
1 1 """radarsys URL Configuration
2 2
3 3 The `urlpatterns` list routes URLs to views. For more information please see:
4 4 https://docs.djangoproject.com/en/1.8/topics/http/urls/
5 5 Examples:
6 6 Function views
7 7 1. Add an import: from my_app import views
8 8 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
9 9 Class-based views
10 10 1. Add an import: from other_app.views import Home
11 11 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
12 12 Including another URLconf
13 13 1. Add an import: from blog import urls as blog_urls
14 14 2. Add a URL to urlpatterns: url(r'^blog/', include(blog_urls))
15 15 """
16 16 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'^$', include('apps.main.urls')),
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')),
25 26 url(r'^cgs/', include('apps.cgs.urls')),
26 27 url(r'^acq/', include('apps.acq.urls')),
27 28 url(r'^abs/', include('apps.abs.urls')),
28 29 url(r'^misc/', include('apps.misc.urls')),
29 30 ]
General Comments 0
You need to be logged in to leave comments. Login now