mirror of https://github.com/interlegis/sapl.git
Edward Ribeiro
10 years ago
12 changed files with 223 additions and 0 deletions
@ -0,0 +1,3 @@ |
|||
from django.contrib import admin |
|||
|
|||
# Register your models here. |
@ -0,0 +1,3 @@ |
|||
from django.db import models |
|||
|
|||
# Create your models here. |
@ -0,0 +1,3 @@ |
|||
from django.test import TestCase |
|||
|
|||
# Create your tests here. |
@ -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'), |
|||
] |
@ -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') |
@ -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> |
@ -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> |
@ -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…
Reference in new issue