Recherche sommaire et améliorations diverses
This commit is contained in:
parent
e550fa0131
commit
9374a5f158
10 changed files with 166 additions and 6 deletions
|
@ -9,6 +9,7 @@ class LieuResource(ModelResource):
|
|||
class Meta:
|
||||
queryset = Lieu.objects.all()
|
||||
resource_name = "lieu"
|
||||
fields = ["nom", "pays", "coord", "type_lieu", "id"]
|
||||
|
||||
def build_filters(self, filters=None, **kwargs):
|
||||
if filters is None:
|
||||
|
@ -22,7 +23,9 @@ class LieuResource(ModelResource):
|
|||
pt = geos.Point((lng,lat), srid=4326)
|
||||
self.reference_point = pt
|
||||
orm_filters['coord__distance_lte'] = (pt, 50)
|
||||
print orm_filters
|
||||
|
||||
if "has_stage" in filters:
|
||||
orm_filters['stages__public'] = True
|
||||
|
||||
return orm_filters
|
||||
|
||||
|
@ -35,4 +38,7 @@ class LieuResource(ModelResource):
|
|||
|
||||
if "lat" in bundle.request.GET and "lng" in bundle.request.GET:
|
||||
bundle.data['distance'] = self.reference_point.distance(bundle.obj.coord)
|
||||
bundle.data["pays_nom"] = obj.get_pays_display()
|
||||
bundle.data["type_lieu_nom"] = obj.get_type_lieu_display()
|
||||
|
||||
return bundle
|
||||
|
|
|
@ -4,6 +4,8 @@ from django import forms
|
|||
from avisstage.models import Normalien, Stage, Lieu, AvisLieu, AvisStage
|
||||
from widgets import LatLonField
|
||||
|
||||
from django.utils import timezone
|
||||
|
||||
import re
|
||||
|
||||
class HTMLTrimmerForm(forms.ModelForm):
|
||||
|
@ -68,7 +70,7 @@ class StageForm(forms.ModelForm):
|
|||
def save(self, commit=True):
|
||||
if self.instance.id is None and hasattr(self, 'request'):
|
||||
self.instance.auteur = self.request.user.profil
|
||||
|
||||
self.date_maj = timezone.now()
|
||||
stage = super(StageForm, self).save(commit=commit)
|
||||
return stage
|
||||
|
||||
|
|
|
@ -38,6 +38,9 @@ class Normalien(models.Model):
|
|||
def __unicode__(self):
|
||||
return u"%s (%s)" % (self.nom, self.user.username)
|
||||
|
||||
def stages_publics(self):
|
||||
return self.stages.filter(public=True)
|
||||
|
||||
# Hook à la création d'un nouvel utilisateur : récupération de ses infos par LDAP
|
||||
def create_user_profile(sender, instance, created, **kwargs):
|
||||
if created:
|
||||
|
|
60
avisstage/static/css/MarkerCluster.Default.css
Normal file
60
avisstage/static/css/MarkerCluster.Default.css
Normal file
|
@ -0,0 +1,60 @@
|
|||
.marker-cluster-small {
|
||||
background-color: rgba(181, 226, 140, 0.6);
|
||||
}
|
||||
.marker-cluster-small div {
|
||||
background-color: rgba(110, 204, 57, 0.6);
|
||||
}
|
||||
|
||||
.marker-cluster-medium {
|
||||
background-color: rgba(241, 211, 87, 0.6);
|
||||
}
|
||||
.marker-cluster-medium div {
|
||||
background-color: rgba(240, 194, 12, 0.6);
|
||||
}
|
||||
|
||||
.marker-cluster-large {
|
||||
background-color: rgba(253, 156, 115, 0.6);
|
||||
}
|
||||
.marker-cluster-large div {
|
||||
background-color: rgba(241, 128, 23, 0.6);
|
||||
}
|
||||
|
||||
/* IE 6-8 fallback colors */
|
||||
.leaflet-oldie .marker-cluster-small {
|
||||
background-color: rgb(181, 226, 140);
|
||||
}
|
||||
.leaflet-oldie .marker-cluster-small div {
|
||||
background-color: rgb(110, 204, 57);
|
||||
}
|
||||
|
||||
.leaflet-oldie .marker-cluster-medium {
|
||||
background-color: rgb(241, 211, 87);
|
||||
}
|
||||
.leaflet-oldie .marker-cluster-medium div {
|
||||
background-color: rgb(240, 194, 12);
|
||||
}
|
||||
|
||||
.leaflet-oldie .marker-cluster-large {
|
||||
background-color: rgb(253, 156, 115);
|
||||
}
|
||||
.leaflet-oldie .marker-cluster-large div {
|
||||
background-color: rgb(241, 128, 23);
|
||||
}
|
||||
|
||||
.marker-cluster {
|
||||
background-clip: padding-box;
|
||||
border-radius: 20px;
|
||||
}
|
||||
.marker-cluster div {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
margin-left: 5px;
|
||||
margin-top: 5px;
|
||||
|
||||
text-align: center;
|
||||
border-radius: 15px;
|
||||
font: 12px "Helvetica Neue", Arial, Helvetica, sans-serif;
|
||||
}
|
||||
.marker-cluster span {
|
||||
line-height: 30px;
|
||||
}
|
14
avisstage/static/css/MarkerCluster.css
Normal file
14
avisstage/static/css/MarkerCluster.css
Normal file
|
@ -0,0 +1,14 @@
|
|||
.leaflet-cluster-anim .leaflet-marker-icon, .leaflet-cluster-anim .leaflet-marker-shadow {
|
||||
-webkit-transition: -webkit-transform 0.3s ease-out, opacity 0.3s ease-in;
|
||||
-moz-transition: -moz-transform 0.3s ease-out, opacity 0.3s ease-in;
|
||||
-o-transition: -o-transform 0.3s ease-out, opacity 0.3s ease-in;
|
||||
transition: transform 0.3s ease-out, opacity 0.3s ease-in;
|
||||
}
|
||||
|
||||
.leaflet-cluster-spider-leg {
|
||||
/* stroke-dashoffset (duration and function) should match with leaflet-marker-icon transform in order to track it exactly */
|
||||
-webkit-transition: -webkit-stroke-dashoffset 0.3s ease-out, -webkit-stroke-opacity 0.3s ease-in;
|
||||
-moz-transition: -moz-stroke-dashoffset 0.3s ease-out, -moz-stroke-opacity 0.3s ease-in;
|
||||
-o-transition: -o-stroke-dashoffset 0.3s ease-out, -o-stroke-opacity 0.3s ease-in;
|
||||
transition: stroke-dashoffset 0.3s ease-out, stroke-opacity 0.3s ease-in;
|
||||
}
|
7
avisstage/static/js/leaflet.markercluster.js
Normal file
7
avisstage/static/js/leaflet.markercluster.js
Normal file
File diff suppressed because one or more lines are too long
|
@ -59,7 +59,7 @@
|
|||
<article class="stage">
|
||||
<section class="misc">
|
||||
<h3>À propos du stage</h3>
|
||||
{% if object.lieux %}
|
||||
{% if object.lieux.all %}
|
||||
<div id="stage-map"></div>
|
||||
<script type="text/javascript">
|
||||
var lieux = [
|
||||
|
|
|
@ -5,7 +5,19 @@
|
|||
<h1>Editer mon profil</h1>
|
||||
<form action="" method="post">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
{{ form.non_field_errors }}
|
||||
{% for field in form %}
|
||||
{{ field.errors }}
|
||||
<div class="field">
|
||||
<label for="{{ field.id_for_label }}">{{ field.label }}</label>
|
||||
<div class="input">
|
||||
{{ field }}
|
||||
{% if field.help_text %}
|
||||
<p class="help_text">{{ field.help_text }}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
<input type="submit" />
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
|
|
@ -218,6 +218,7 @@
|
|||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
<input type="submit" value="Enregistrer" />
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
@ -242,9 +243,9 @@
|
|||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
<input type="submit" value="Enregistrer" />
|
||||
{% endwith %}
|
||||
</div>
|
||||
<input type="submit" value="Enregistrer" />
|
||||
</form>
|
||||
|
||||
{% lieu_widget %}
|
||||
|
|
55
avisstage/templates/avisstage/recherche.html
Normal file
55
avisstage/templates/avisstage/recherche.html
Normal file
|
@ -0,0 +1,55 @@
|
|||
{% extends "avisstage/base.html" %}
|
||||
{% load staticfiles %}
|
||||
|
||||
{% block extra_head %}
|
||||
<script type="text/javascript" src="{% static "js/leaflet.js" %}"></script>
|
||||
<script type="text/javascript" src="{% static "js/leaflet.markercluster.js" %}"></script>
|
||||
<link rel="stylesheet" type="text/css" href="{% static "css/leaflet.css" %}" />
|
||||
<link rel="stylesheet" type="text/css" href="{% static "css/MarkerCluster.css" %}" />
|
||||
<link rel="stylesheet" type="text/css" href="{% static "css/MarkerCluster.Default.css" %}" />
|
||||
<script type="text/javascript" src="//maps.stamen.com/js/tile.stamen.js?v1.3.0"></script>
|
||||
<script type="text/javascript">
|
||||
$(function () {
|
||||
var STATIC_ROOT = "{{ STATIC_URL|escapejs }}";
|
||||
var map = L.map("stages-map").panTo([30, 0]).setZoom(2);
|
||||
var layer = new L.StamenTileLayer("terrain");
|
||||
map.addLayer(layer);
|
||||
|
||||
function makeIcon(couleur){
|
||||
return L.icon({
|
||||
iconUrl: STATIC_ROOT + 'images/marker-'+couleur+'.png',
|
||||
iconSize: [36, 46],
|
||||
iconAnchor: [18, 45],
|
||||
popupAnchor: [0, -48]
|
||||
})
|
||||
}
|
||||
var greenIcon = makeIcon('red');
|
||||
|
||||
$.getJSON("{% url 'avisstage:api_dispatch_list' resource_name="lieu" api_name="v1" %}?format=json&has_stage&limit=10000", onLoadLieux);
|
||||
|
||||
var marqueurs = L.markerClusterGroup();
|
||||
|
||||
function onLoadLieux(data){
|
||||
console.log(data);
|
||||
var lieux = data.objects;
|
||||
$.each(lieux, function(i, item) {
|
||||
var marqueur = L.marker(item.coord, {icon: greenIcon});
|
||||
marqueur.bindPopup("<h3>"+item.nom+"</h3>");
|
||||
marqueurs.addLayer(marqueur);
|
||||
});
|
||||
map.addLayer(marqueurs);
|
||||
}
|
||||
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% block content %}
|
||||
<h1>Recherche</h1>
|
||||
|
||||
<article>
|
||||
<h2>Carte des stages</h2>
|
||||
<div id="stages-map"></div>
|
||||
</article>
|
||||
{% endblock %}
|
Loading…
Reference in a new issue