Skip to content

Commit

Permalink
Merge pull request #71 from Domotina/test
Browse files Browse the repository at this point in the history
Entrega 3 Sprint 3
- Corrección bug de popups en firefox
- Por ajax cargar los dueños de los inmubles y filtrar sus inmuebles para que se carguen en un combobox y puedan ser seleccionados por el usuario
- Inclusión de funcionalidad para ver reportes de eventos ocurridos en un rango de fechas en HTML.
- Inclusión de validaciones del lado del servidor para que pasen las pruebas de los escenarios en la HU011
- Inclusión de funcionalidad para ver reportes en PDF
- Inclusión imagenes (encabezado) en el reporte PDF
  • Loading branch information
Andrés Felipe Esguerra Restrepo committed Apr 28, 2015
2 parents 0541880 + 01fd672 commit d8758dc
Show file tree
Hide file tree
Showing 15 changed files with 570 additions and 46 deletions.
19 changes: 15 additions & 4 deletions central/templates/delegates_individual.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,18 @@
{% endblock navbar %}

{% block content %}
<form class="form-horizontal" method="get" action=' '>
<script>
$(function() {
$("#owner").change(function() {
alert('hola');
$.get('/central/getHouses/', { owner_id: $("#owner").val() }, function(data){
alert(data);
alert('hola2');
});
});
});
</script>
<form class="form-horizontal" method="post" action='/central/delegate_individual/'>
<fieldset>
<legend>Create Delegate</legend>

Expand Down Expand Up @@ -47,20 +58,20 @@
</div>
</div>
<div class="form-group">
<label for=" " class="col-lg-2 control-label">Owner</label>
<label for="owner" class="col-lg-2 control-label">Owner</label>

<div class="col-lg-10">
<select class="form-control" id="owner" name="owner" required>
<!-- cargar propietarios -->
<option value="0">Select</option>
{% for use in user %}
{% for use in users %}
<option value="{{use.pk}}"> {{use.username|capfirst}}</option>
{% endfor %}
</select>
</div>
</div>
<div class="form-group">
<label for=" " class="col-lg-2 control-label">Property</label>
<label for="property" class="col-lg-2 control-label">Property</label>

<div class="col-lg-10">
<select class="form-control" id="property" name="property" required>
Expand Down
3 changes: 2 additions & 1 deletion central/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
url(r'^delegate_huge/', 'central_huge_delegate_load', name="central_huge_delegate_load"),
url(r'^building-neigh/', 'central_building_neigh', name="central_building_neigh"),
url(r'^create_building-neigh/', 'central_building_create', name="central_building_create"),
url(r'^report/', 'central_month_report', name="central_month_report")
url(r'^report/', 'central_month_report', name="central_month_report"),
url(r'^getHouses/$', 'getHouses', name="getHouses"),
)
42 changes: 29 additions & 13 deletions central/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from django.contrib.auth.models import User
from .notificator import send_email
from map.models import Neighborhood, Place, Floor
from django.template import RequestContext
from django.shortcuts import render_to_response


def user_can_see(user):
Expand Down Expand Up @@ -106,23 +108,37 @@ def central_individual_delegate_load(request):
emailUser = str(request.POST.get("inputEmail", ""))
owner = str(request.POST.get("owner", ""))
property = str(request.POST.get("property", ""))


userCreate = User.objects.create_user(username=username, first_name=name, last_name=lastName, email=emailUser,
password='DOMOTINA123')
userCreate.is_superuser = False
userCreate.is_active = True
userCreate.is_staff = False
userCreate.groups.add(2)#Falta
userCreate.save()
send_email(userCreate)
print owner
print property

# userCreate = User.objects.create_user(username=username, first_name=name, last_name=lastName, email=emailUser,
# password='DOMOTINA123')
# userCreate.is_superuser = False
# userCreate.is_active = True
# userCreate.is_staff = False
# userCreate.groups.add(2)#Falta
# userCreate.save()
# send_email(userCreate)
return redirect('central_home')
else:
user = User.objects.all()
place = Place.objects.all().order_by('name')
context = {'user': request.user, 'place': place, 'user': user}
users = User.objects.all()
#place = Place.objects.all().order_by('name')
context = {'user': request.user, 'users': users}
return render(request, 'delegates_individual.html', context)

def getHouses(request):
context = RequestContext(request)
print 'houses'
#if request.method == 'GET':
print 'get'
owner_id = request.GET['owner_id']
print owner_id
place = get_object_or_404(Place, pk=owner_id)
#place = Place.objects.filer(pk=int(owner_id))
print place
print 'fin'
return render_to_response('central/delegates_individual.html', {'user': request.user, 'place': place}, context)



@login_required
Expand Down
1 change: 1 addition & 0 deletions domotina/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
url(r'^map/', include('map.urls')),
url(r'^', include('index.urls')),
url(r'^central/', include('central.urls')),
url(r'^report/', include('report_manager.urls')),
)
17 changes: 10 additions & 7 deletions map/static/js/historic.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function secondsFormatter(value) {
};

$(function () {
var floorsElement = $("#floors");
/*
Se carga el mapa del primer piso por defecto
*/
Expand All @@ -23,17 +24,19 @@ $(function () {
/*
Se registran todas las opciones de pisos una vez carga el documento
*/
for (idx in floors) {
$("#floors").append("<option value=" + idx + ">Floor " + floors[idx].number + "</option>");
for (idx in window.floors) {
if (window.floors.hasOwnProperty(idx)) {
floorsElement.append("<option value=" + idx + ">Floor " + window.floors[idx].number + "</option>");
}
}

/*
Cuando se selecciona un piso, se pinta de nuevo el mapa del piso
y los respectivos sensores
*/
$("#floors").change(function(){
floorsElement.change(function(){
var idx = $("#floors").find(":selected").val();
window.floor = floors[idx];
window.floor = window.floors[idx];
$('#map').css("background-image", "url(" + floor.url + ")");
showIcons();
});
Expand All @@ -47,7 +50,7 @@ $(function () {
time.setHours(seconds / 60 / 60);
time.setMinutes(seconds / 60 % 60);
time.setSeconds(seconds % 60);
showIcons()
showIcons();
});

/*
Expand All @@ -59,6 +62,6 @@ $(function () {
var url = window.location.pathname.replace(/\d+\/$/, value.replace(/-/g,"")+"/");
window.location.pathname = url;
}
event.preventDefault()
})
event.preventDefault();
});
});
45 changes: 29 additions & 16 deletions map/static/js/place_details.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,25 @@ sensorStatus = function (sensor) {
if (window.time && sensor.events) {
var event;
for (var n in sensor.events) {
event = sensor.events[n];
if (event.timestamp < time) {
sensor.url = event.url;
sensor.status = event.status;
sensor.posX = event.posX;
sensor.posY = event.posY;
break;
if (sensor.events.hasOwnProperty(n)) {
event = sensor.events[n];
if (event.timestamp < time) {
sensor.url = event.url;
sensor.status = event.status;
sensor.posX = event.posX;
sensor.posY = event.posY;
break;
}
}
}
}
};

isValid = function (sensor) {
var floor = window.floor, time = window.time;
return ((!floor || sensor.floor === floor.number) && (!time || sensor.creationDate < time));
};

function showIcons() {
var c = document.getElementById("place_canvas");
var ctx = c.getContext("2d");
Expand All @@ -44,13 +51,13 @@ function showIcons() {
ctx.drawImage(image, sensor.posX, sensor.posY);
}

var sensors = window.sensors, time = window.time, floor = window.floor, sensor;
var sensors = window.sensors, sensor;
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
for (var i in sensors) {
sensor = $.extend({}, sensors[i]);
if (!floor || sensor.floor === floor.number) {
if (!time || sensor.creationDate < time) {
sensorStatus(sensor)
if (sensors.hasOwnProperty(i)) {
sensor = $.extend({}, sensors[i]);
if (isValid(sensor)) {
sensorStatus(sensor);
drawSensor(sensor);
}
}
Expand All @@ -63,15 +70,21 @@ $(function () {
});

$("#place_canvas").on("click", function (event) {
var sensors = window.sensors, time = window.time, floor = window.floor, sensor;
var sensors = window.sensors, sensor;
var area = 34; //tamaño de las imágenes de los sensores
var modal = $("#popup-panel");
var body = $("#popup-sensor");

if (typeof event.offsetX === "undefined" || typeof event.offsetY === "undefined") {
var targetOffset = $(event.target).offset();
event.offsetX = event.pageX - targetOffset.left;
event.offsetY = event.pageY - targetOffset.top;
}

for (var i in sensors) {
sensor = $.extend({}, sensors[i]);
if (!floor || sensor.floor === floor.number) {
if (!time || sensor.creationDate < time) {
if (sensors.hasOwnProperty(i)) {
sensor = $.extend({}, sensors[i]);
if (isValid(sensor)) {
sensorStatus(sensor);
if ((sensor.posX <= event.offsetX && event.offsetX <= sensor.posX + area) &&
(sensor.posY <= event.offsetY && event.offsetY <= sensor.posY + area)) {
Expand Down
4 changes: 2 additions & 2 deletions map/templates/place_details.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ <h1><span id="floor_title">{{ floor.place }}</span></h1>
</li>
<li><a href='{% url "list_sensors" floor.place.pk %}'>Sensors</a></li>
<li><a href='{% url "list_rules" floor.place.pk %}'>Rules</a></li>
<li><a href="{% url "map_history" floor.place.pk now %}">History</a></li>
<li><a href>Reports</a></li>
<li><a href='{% url "map_history" floor.place.pk now %}'>History</a></li>
<li><a href='{% url "report_home" floor.place.pk %}'>Reports</a></li>
<li><a href>Delegates</a></li>
</ul>
</div>
Expand Down
51 changes: 51 additions & 0 deletions report_manager/owner_report_gen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import datetime
from map.models import Place
from event_manager.models import Event


# Validating if date is valid
def is_valid_format(date):
passed = False
try:
start_year = datetime.datetime.strptime(date, "%Y/%m/%d").year
passed = True
except ValueError:
passed = False

return passed


# Getting the place based on its pk
def get_place(pk):
return Place.objects.get(pk=pk)


# Getting events in the place based on a date range
def get_events_in_place(place, start_date, end_date):
try:
start_year = datetime.datetime.strptime(start_date, "%Y/%m/%d").year
end_year = datetime.datetime.strptime(end_date, "%Y/%m/%d").year

start_month = datetime.datetime.strptime(start_date, "%Y/%m/%d").month
end_month = datetime.datetime.strptime(end_date, "%Y/%m/%d").month

start_day = datetime.datetime.strptime(start_date, "%Y/%m/%d").day
end_day = datetime.datetime.strptime(start_date, "%Y/%m/%d").day

events = Event.objects.filter(sensor__floor__place=place)\
.filter(timestamp__gt=datetime.date(start_year, start_month, start_day),
timestamp__lt=datetime.date(end_year, end_month, end_day))
return events

except ValueError:
return None


# Verifying if the end date is greater than the start date
def is_end_date_greater(start_date, end_date):

if datetime.datetime.strptime(start_date, "%Y/%m/%d") > \
datetime.datetime.strptime(end_date, "%Y/%m/%d"):
return False
else:
return True
51 changes: 51 additions & 0 deletions report_manager/templates/events_in_date_range.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{% extends "base.html"%}
{% load static %}

{% block title %}
- Events in a date range
{% endblock %}

{% block navbar %}
<li><a href='{% url "map_home" %}'>My places</a></li>
<li><a href="#">About Smart Home</a></li>
<li><a href="#">About Domotina</a></li>
{% endblock navbar %}

{% block content %}
<div class="well">
<h3>Report of handled events in your place {{place.name}}</h3>
{% if events %}
<h5>These are handled events in your place between {{start_date}} and {{end_date}}.</h5>
{% endif %}

<div class="panel panel-primary">
{% if events %}
<table class="table table-striped table-hover ">
<thead>
<tr>
<th>Date</th>
<th>Time</th>
<th>Asset</th>
<th>Description</th>
</tr>
</thead>
<tbody class="table-striped">
{% for event in events %}
<tr>
<td>{{ event.timestamp.date }}</td>
<td>{{ event.timestamp.time }}</td>
<td>{{ event.sensor }}</td>
<td>Status changed to {{ event }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<ul class="list-group">
<li class="list-group-item">There are no handled events between {{start_date}} and {{end_date}}.</li>
</ul>
{% endif %}
</div>
<a href='{% url "report_home" place.pk %}'>View events in another date.</a>
</div>
{% endblock %}
Loading

0 comments on commit d8758dc

Please sign in to comment.