Browse Source

Add first files of Painel app (wip)

pull/6/head
Edward Ribeiro 10 years ago
parent
commit
42393be55b
  1. 2
      .gitignore
  2. 0
      painel/__init__.py
  3. 3
      painel/admin.py
  4. 0
      painel/migrations/__init__.py
  5. 3
      painel/models.py
  6. 3
      painel/tests.py
  7. 10
      painel/urls.py
  8. 28
      painel/views.py
  9. 1
      sapl/urls.py
  10. 75
      templates/painel/index.html
  11. 49
      templates/painel/parlamentares.html
  12. 49
      templates/painel/votacao.html

2
.gitignore

@ -51,6 +51,8 @@ coverage.xml
# Django stuff: # Django stuff:
*.log *.log
*.swp
# Sphinx documentation # Sphinx documentation
docs/_build/ docs/_build/

0
painel/__init__.py

3
painel/admin.py

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

0
painel/migrations/__init__.py

3
painel/models.py

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

3
painel/tests.py

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

10
painel/urls.py

@ -0,0 +1,10 @@
from django.conf.urls import include, url
from . views import (json_view, painel_view, painel_parlamentares_view, painel_votacao_view)
urlpatterns = [
url(r'^sistema/painel$', painel_view),
url(r'^sistema/painel/parlamentares', painel_parlamentares_view),
url(r'^sistema/painel/votacao', painel_votacao_view),
url(r'^sistema/painel/json', json_view, name='json_view'),
]

28
painel/views.py

@ -0,0 +1,28 @@
from django.shortcuts import render
from django.http import HttpResponse
from django.http import JsonResponse
from django.core import serializers
import json
from parlamentares.models import Parlamentar
from sessao.models import PresencaOrdemDia
def json_view(request):
#error when trying to retrieve
#print(PresencaOrdemDia.objects.all())
parlamentares = serializers.serialize('json', Parlamentar.objects.all())
return HttpResponse(parlamentares, content_type='application/json')
#return JsonResponse(data) # work with python dict
def painel_view(request):
return render(request, 'painel/index.html')
def painel_parlamentares_view(request):
return render(request, 'painel/parlamentares.html')
def painel_votacao_view(request):
return render(request, 'painel/votacao.html')

1
sapl/urls.py

@ -27,6 +27,7 @@ urlpatterns = [
url(r'', include('materia.urls')), url(r'', include('materia.urls')),
url(r'', include('norma.urls')), url(r'', include('norma.urls')),
url(r'', include('lexml.urls')), url(r'', include('lexml.urls')),
url(r'', include('painel.urls')),
# must come at the end # must come at the end
# so that base /sistema/ url doesn't capture its children # so that base /sistema/ url doesn't capture its children

75
templates/painel/index.html

@ -0,0 +1,75 @@
<!DOCTYPE HTML>
<html lang="pt-br">
<head>
<title>Painel jQuery</title>
<meta charset="UTF-8">
<script src="js/json2.js"></script>
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<STYLE type="text/css">
@media screen {
body {font-size: medium; color: white; line-height: 1em; background: black;}
}
</STYLE>
<script type="text/javascript">
$(document).ready(function() {
var counter = 1;
(function poll() {
$.ajax({
//url: "http://localhost:8000/sistema/painel/json",
url: $("#json_url").val(),
type: "GET",
success: function(data) {
//TODO: json spitted out is very complex, have to simplify/flat it
//TODO: probably building it by hand on REST side
var list = $("#parlamentares");
list.children().remove();
//select 10 random names (for tests purposes only)
var newList = Array();
for (i = 0; i < 10; i++) {
newList[i] = data[Math.floor(Math.random() * data.length)]
}
newList.sort(function(a,b) {
if (a['fields'].nome_parlamentar < b['fields'].nome_parlamentar) return -1;
else if (a['fields'].nome_parlamentar > b['fields'].nome_parlamentar) return 1;
else return 0;
});
// ---
jQuery.each(newList, function(index, value) {
parlamentar = value['fields'];
$('<li />', {text: parlamentar.nome_parlamentar }).appendTo(list);
});
$("#counter").text(counter);
counter++;
},
error: function(err) {
console.error(err);
},
dataType: "json",
complete: setTimeout(function() {poll()}, 5000),
timeout: 2000
})
})();
});
</script>
</head>
<body>
<input id="json_url" type="hidden" value="{% url 'json_view' %}">
<h2>Ajax refresh counter: <span id="counter"></span></h2>
<ul id="parlamentares">
</ul>
</body>
</html>

49
templates/painel/parlamentares.html

@ -0,0 +1,49 @@
<!DOCTYPE HTML>
<html lang="pt-br">
<head>
<title>Painel jQuery</title>
<meta charset="UTF-8">
<script src="js/json2.js"></script>
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<STYLE type="text/css">
@media screen {
body {font-size: medium; color: white; line-height: 1em; background: black;}
}
</STYLE>
<script type="text/javascript">
$(document).ready(function() {
var counter = 1;
(function poll() {
$.ajax({
//url: "http://localhost:8000/sistema/painel/json",
url: $("#json_url").val(),
type: "GET",
success: function(data) {
console.log(data);
$("#name").text(data.nome + ', call=' + counter);
counter++;
},
error: function(err) {
console.error(err);
},
dataType: "json",
complete: setTimeout(function() {poll()}, 5000),
timeout: 2000
})
})();
});
</script>
</head>
<body>
<input id="json_url" type="hidden" value="{% url 'json_view' %}">
<h2><div id="name"></div></h2>
</body>
</html>

49
templates/painel/votacao.html

@ -0,0 +1,49 @@
<!DOCTYPE HTML>
<html lang="pt-br">
<head>
<title>Painel jQuery</title>
<meta charset="UTF-8">
<script src="js/json2.js"></script>
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<STYLE type="text/css">
@media screen {
body {font-size: medium; color: white; line-height: 1em; background: black;}
}
</STYLE>
<script type="text/javascript">
$(document).ready(function() {
var counter = 1;
(function poll() {
$.ajax({
//url: "http://localhost:8000/sistema/painel/json",
url: $("#json_url").val(),
type: "GET",
success: function(data) {
console.log(data);
$("#name").text(data.nome + ', call=' + counter);
counter++;
},
error: function(err) {
console.error(err);
},
dataType: "json",
complete: setTimeout(function() {poll()}, 5000),
timeout: 2000
})
})();
});
</script>
</head>
<body>
<input id="json_url" type="hidden" value="{% url 'json_view' %}">
<h2><div id="name"></div></h2>
</body>
</html>
Loading…
Cancel
Save