Recherche
This commit is contained in:
parent
e183abe947
commit
784de8af71
2 changed files with 14 additions and 11 deletions
|
@ -17,13 +17,11 @@
|
|||
<div id="map_searchlieu"></div>
|
||||
<script>
|
||||
$(function(){
|
||||
$("#addlieu").geocomplete({
|
||||
$("#id_lieu").geocomplete({
|
||||
map: "#map_searchlieu",
|
||||
types: ["geocode", "establishment"],
|
||||
}).on("geocode:result", function(event, result){ $("#map_searchlieu").css("display", "block"); digere(result); console.log(result); });
|
||||
});
|
||||
var fieldcount = {{ numforms }};
|
||||
var places = $("#places");
|
||||
|
||||
var predata;
|
||||
function digere (gdata) {
|
||||
|
@ -44,7 +42,8 @@
|
|||
data["name"] = gdata.name;
|
||||
data["longitude"] = gdata.geometry.location.lng();
|
||||
data["latitude"] = gdata.geometry.location.lat();
|
||||
// TODO set to hidden inputs
|
||||
$("#id_longitude").val(data["longitude"]);
|
||||
$("#id_latitude").val(data["latitude"]);
|
||||
}
|
||||
|
||||
</script>
|
||||
|
@ -52,7 +51,7 @@
|
|||
</form>
|
||||
</div>
|
||||
{% if resultats %}
|
||||
<p>{{ resultats.length }} stage(s) trouvé(s)</p>
|
||||
<p>{{ resultats|length }} stage(s) trouvé(s)</p>
|
||||
{% for stage in resultats %}
|
||||
<div class="stagefound">
|
||||
<h3><a href="{% url 'monstage:stage' stage.id %}">{{ stage.sujet }}</a></h3>
|
||||
|
|
|
@ -268,6 +268,7 @@ def detail(request, question_id):
|
|||
#
|
||||
# Recherche de stages
|
||||
#
|
||||
from django.db.models import Q
|
||||
|
||||
class SearchForm(forms.Form):
|
||||
matiere = forms.ChoiceField(label='Matière :', required=False, choices=tuple([('','Toute matière')] + [(mat.id, mat.name) for mat in StageMatiere.objects.all()]))
|
||||
|
@ -286,20 +287,23 @@ def search(request):
|
|||
if form.is_valid():
|
||||
lon = form.cleaned_data['longitude']
|
||||
lat = form.cleaned_data['latitude']
|
||||
lieu = form.cleaned_data['lieu']
|
||||
stages = Stage.objects
|
||||
if lat and lon:
|
||||
if lat and lon and lieu:
|
||||
coords = GEOSGeometry('POINT(%f %f)' % (lon, lat), srid=4326)
|
||||
distance = {'km': form.cleaned_data['tolerance']}
|
||||
lieux = Lieu.objects.filter(coord__distance_lte=(coords, measure.D(**distance)))
|
||||
lieux = lieux.distance(coords).order_by('distance')
|
||||
stages = lieux.stage_set
|
||||
stages = stages.filter(lieux__in=lieux)
|
||||
matiere = form.cleaned_data['matiere']
|
||||
if matiere:
|
||||
stages = stages.filter(matieres__pk=matiere)
|
||||
thematiques = form.cleaned_data['thematiques']
|
||||
thematiques = form.cleaned_data['thematiques'].split(',')
|
||||
if thematiques:
|
||||
#todo
|
||||
pass
|
||||
q = Q()
|
||||
for thematique in thematiques:
|
||||
q |= Q(thematiques__name__icontains = thematique)
|
||||
stages = stages.filter(q).distinct()
|
||||
stages = stages.all()
|
||||
else:
|
||||
form = SearchForm()
|
||||
|
|
Loading…
Reference in a new issue