Skip to content
Snippets Groups Projects
Commit 70690a3b authored by Piotr Gawron's avatar Piotr Gawron
Browse files

filtering by location added

parent 5e850f27
No related branches found
No related tags found
1 merge request!34Performance of subject list
...@@ -17,9 +17,12 @@ def cities(request): ...@@ -17,9 +17,12 @@ def cities(request):
@login_required @login_required
def locations(request): def locations(request):
X = Location.objects.values_list('name').distinct() locations = Location.objects.all()
data = []
for location in locations:
data.append({"id": location.id, "name": location.name})
return JsonResponse({ return JsonResponse({
"locations": [x[0] for x in X] "locations": data
}) })
...@@ -107,10 +110,10 @@ def get_subjects_filtered(subjects, filters): ...@@ -107,10 +110,10 @@ def get_subjects_filtered(subjects, filters):
result = result.filter(resigned=(value == "true")) result = result.filter(resigned=(value == "true"))
elif column == "postponed": elif column == "postponed":
result = result.filter(postponed=(value == "true")) result = result.filter(postponed=(value == "true"))
elif column == "default_location":
result = result.filter(default_location=value)
else: else:
print row print "UNKNOWN filter: " + row
# elif order_column == "default_location":
# result = subjects.order_by(order_direction + 'default_location')
return result return result
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
{% block styles %} {% block styles %}
{{ block.super }} {{ block.super }}
<link rel="stylesheet" href="{% static 'AdminLTE/plugins/datatables/dataTables.bootstrap.css' %}"> <link rel="stylesheet" href="{% static 'AdminLTE/plugins/datatables/dataTables.bootstrap.css' %}">
{% endblock styles %} {% endblock styles %}
{% block ui_active_tab %}'subjects'{% endblock ui_active_tab %} {% block ui_active_tab %}'subjects'{% endblock ui_active_tab %}
...@@ -55,7 +56,9 @@ ...@@ -55,7 +56,9 @@
<th> <th>
<div name="string_filter">Surname</div> <div name="string_filter">Surname</div>
</th> </th>
<th>Default location</th> <th>
<div name="location_filter">---</div>
</th>
<th> <th>
<div name="yes_no_filter">---</div> <div name="yes_no_filter">---</div>
</th> </th>
...@@ -87,10 +90,19 @@ ...@@ -87,10 +90,19 @@
}); });
$('#table tfoot div[name="yes_no_filter"]').each(function () { $('#table tfoot div[name="yes_no_filter"]').each(function () {
var title = $(this).text();
$(this).html('<select ><option value selected="selected">----------</option><option value="true">YES</option><option value="false">NO</option></select>'); $(this).html('<select ><option value selected="selected">----------</option><option value="true">YES</option><option value="false">NO</option></select>');
}); });
$('#table tfoot div[name="location_filter"]').each(function () {
var obj = $(this)
obj.html('<select ><option value selected="selected">----------</option></select>');
$.get("{% url 'web.api.locations' %}", function (data) {
$.each(data.locations, function (index, location) {
$('select', obj).append( '<option value="' + location.id + '">' + location.name + '</option>');
});
});
});
$(function () { $(function () {
var table = $('#table').DataTable({ var table = $('#table').DataTable({
serverSide: true, serverSide: true,
...@@ -126,6 +138,7 @@ ...@@ -126,6 +138,7 @@
} }
}); });
}); });
$('#table_filter').css("display","none");
}); });
</script> </script>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment