Skip to content
Snippets Groups Projects
Commit d2a7d200 authored by Tor-Einar Skog's avatar Tor-Einar Skog
Browse files

Added date search field for observations

parent 7915959a
No related branches found
No related tags found
No related merge requests found
from django import forms
class ObservationTimeFilterForm(forms.Form):
timeOfObservationFrom = forms.DateField(required=False)
timeOfObservationTo = forms.DateField(required=False)
\ No newline at end of file
...@@ -44,7 +44,17 @@ ...@@ -44,7 +44,17 @@
</div> </div>
</div> </div>
<div class="col-xs-6"> <div class="col-xs-6">
</div> <form class="form-inline" method="get" action="/observations">
<div class="form-group">
<input class="form-control" type="date" name="{{form.timeOfObservationFrom.html_name}}" value="{{form.timeOfObservationFrom.value | default_if_none:""}}" placeholder="{% trans "From" %}"/>
</div>
-
<div class="form-group">
<input class="form-control" type="date" name="{{form.timeOfObservationTo.html_name}}" value="{{form.timeOfObservationTo.value | default_if_none:""}}" placeholder="{% trans "To" %}"/>
</div>
<button type="submit" class="btn btn-primary">{% trans "Date search" %}</button>
</form>
</div>
</div> </div>
<table class="table"> <table class="table">
<thead> <thead>
...@@ -80,7 +90,11 @@ ...@@ -80,7 +90,11 @@
}; };
$(document).ready(function() { $(document).ready(function() {
$(".chosen-select").chosen({placeholder_text_multiple:"{% trans "Crops" %}"}); $(".chosen-select").chosen({placeholder_text_multiple:"{% trans "Crops" %}"});
$.getJSON("/vipslogicproxy/rest/observation/broadcast/list/" + settings.vipsOrganizationId, function( json ) { {% if form.timeOfObservationFrom.value or form.timeOfObservationTo.value %}
$.getJSON("/vipslogicproxy/rest/observation/broadcast/list/" + settings.vipsOrganizationId+ "?timeOfObservationFrom={{form.timeOfObservationFrom.value | default_if_none:""}}&timeOfObservationTo={{form.timeOfObservationTo.value | default_if_none:""}}", function( json ) {
{% else %}
$.getJSON("/vipslogicproxy/rest/observation/broadcast/list/" + settings.vipsOrganizationId+ "?season=" + getCurrentYear(), function( json ) {
{% endif %}
allObservations = json; allObservations = json;
allObservations.sort(sortObservationMessages).reverse(); allObservations.sort(sortObservationMessages).reverse();
for(var i in allObservations) for(var i in allObservations)
......
...@@ -19,16 +19,21 @@ ...@@ -19,16 +19,21 @@
from django.shortcuts import render from django.shortcuts import render
from django.utils import translation from django.utils import translation
from observations.forms import ObservationTimeFilterForm
from organisms.models import CropCategory from organisms.models import CropCategory
def index(request): def index(request):
form = ObservationTimeFilterForm(request.GET)
if form == None:
form = ObservationTimeFilterForm()
context = { context = {
'crop_categories': CropCategory.get_crop_categories(translation.get_language()) "crop_categories": CropCategory.get_crop_categories(translation.get_language()),
"form" : form
} }
return render(request, 'observations/index.html', context) return render(request, 'observations/index.html', context)
def detail(request, observation_id): def detail(request, observation_id):
context = { context = {
"observation_id" : observation_id "observation_id" : observation_id,
} }
return render(request, 'observations/detail.html', context) return render(request, 'observations/detail.html', context)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment