Première version de l'ajout des lieux de stage
This commit is contained in:
parent
692b64ee84
commit
1eac90e796
9 changed files with 154 additions and 4 deletions
26
monstage/migrations/0003_auto_20150613_1930.py
Normal file
26
monstage/migrations/0003_auto_20150613_1930.py
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import models, migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('monstage', '0002_auto_20150612_2003'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='lieu',
|
||||||
|
name='pays',
|
||||||
|
field=models.CharField(default='', max_length=200, verbose_name='Pays'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='lieu',
|
||||||
|
name='ville',
|
||||||
|
field=models.CharField(max_length=200, verbose_name='Ville'),
|
||||||
|
preserve_default=True,
|
||||||
|
),
|
||||||
|
]
|
|
@ -40,7 +40,8 @@ cas_user_authenticated.connect(create_user_profile)
|
||||||
|
|
||||||
class Lieu(models.Model):
|
class Lieu(models.Model):
|
||||||
name = models.CharField(_(u"Nom de l'institution d'accueil"), max_length = 250)
|
name = models.CharField(_(u"Nom de l'institution d'accueil"), max_length = 250)
|
||||||
ville = models.CharField(_(u"Ville, Pays"), max_length = 200)
|
ville = models.CharField(_(u"Ville"), max_length = 200)
|
||||||
|
pays = models.CharField(_(u"Pays"), max_length = 200)
|
||||||
coord = geomodels.PointField(_(u"Coordonnées"), geography = True)
|
coord = geomodels.PointField(_(u"Coordonnées"), geography = True)
|
||||||
objects = geomodels.GeoManager() # Requis par GeoDjango
|
objects = geomodels.GeoManager() # Requis par GeoDjango
|
||||||
type_lieu = models.CharField( _(u"Type de structure d'accueil"),
|
type_lieu = models.CharField( _(u"Type de structure d'accueil"),
|
||||||
|
|
4
monstage/static/script/jquery-1.11.1.min.js
vendored
Normal file
4
monstage/static/script/jquery-1.11.1.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
12
monstage/static/script/jquery.geocomplete.min.js
vendored
Normal file
12
monstage/static/script/jquery.geocomplete.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
0
monstage/static/style.css
Normal file
0
monstage/static/style.css
Normal file
|
@ -1,12 +1,88 @@
|
||||||
{% extends "skeleton.html" %}
|
{% extends "skeleton.html" %}
|
||||||
|
{% load staticfiles %}
|
||||||
|
|
||||||
|
{% block extra_head %}
|
||||||
|
<script src="http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places" type="text/javascript"></script>
|
||||||
|
<script src="{% static 'script/jquery-1.11.1.min.js' %}" type="text/javascript"></script>
|
||||||
|
<script src="{% static 'script/jquery.geocomplete.min.js' %}" type="text/javascript"></script>
|
||||||
|
<style type="text/css">
|
||||||
|
#map_canvas {
|
||||||
|
width:300px;
|
||||||
|
height:300px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>Lieux du stage "{{ stage.sujet }}"</h1>
|
<h1>Lieux du stage "{{ stage.sujet }}"</h1>
|
||||||
<p><a href="{% url 'monstage:index' %}">Retour</a></p>
|
<p><a href="{% url 'monstage:index' %}">Retour</a></p>
|
||||||
<form action="{% url 'monstage:stage_add' %}" method="post">
|
<p>{{ debug }}</p>
|
||||||
|
<div id="map_canvas"></div>
|
||||||
|
<input id="geocomplete" type="text" placeholder="Chercher un établissement" />
|
||||||
|
<input type="button" value="Ajouter ce lieu" onclick="addFieldSet(predata);" />
|
||||||
|
<form action="{% url 'monstage:stage_edit_lieu' stage.id %}" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{{ form.as_p }}
|
<div id="places">
|
||||||
|
</div>
|
||||||
<input type="submit" value="Etape suivante" />
|
<input type="submit" value="Etape suivante" />
|
||||||
</form>
|
</form>
|
||||||
|
<script>
|
||||||
|
$(function(){
|
||||||
|
$("#geocomplete").geocomplete({
|
||||||
|
map: "#map_canvas",
|
||||||
|
types: ["geocode", "establishment"],
|
||||||
|
}).on("geocode:result", function(event, result){ digere(result); console.log(predata); });
|
||||||
|
});
|
||||||
|
$(function(){
|
||||||
|
var alreadyknown = [
|
||||||
|
{% for lieu in stage.lieux.all %}
|
||||||
|
{% if not forloop.first %},{% endif %}
|
||||||
|
{ name: "{{ lieu.name }}", ville: "{{ lieu.ville }}", pays: "{{ lieu.pays }}", latitude: "{{ lieu.coord.coords.0 }}", longitude: "{{ lieu.coord.coords.1 }}" }
|
||||||
|
{% endfor %} ];
|
||||||
|
for (var i in alreadyknown) {
|
||||||
|
addFieldSet(alreadyknown[i]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var fieldcount = 0;
|
||||||
|
var places = $("#places");
|
||||||
|
function addFieldSet (data) {
|
||||||
|
if (data == undefined) return;
|
||||||
|
var t = $("<div>")
|
||||||
|
t.append($("<input>", {type:"text", id:"name"+fieldcount, name:"name"+fieldcount, placeholder:"Nom de l'institution", value:data.name || ""}));
|
||||||
|
t.append($("<input>", {type:"text", id:"ville"+fieldcount, name:"ville"+fieldcount, placeholder:"Ville", value:data.ville || ""}));
|
||||||
|
t.append($("<input>", {type:"text", id:"pays"+fieldcount, name:"pays"+fieldcount, placeholder:"Pays", value:data.pays || ""}));
|
||||||
|
t.append($("<input>", {type:"hidden", id:"latitude"+fieldcount, name:"latitude"+fieldcount, value:data.latitude || ""}));
|
||||||
|
t.append($("<input>", {type:"hidden", id:"longitude"+fieldcount, name:"longitude"+fieldcount, value:data.longitude || ""}));
|
||||||
|
places.append(t);
|
||||||
|
// {innerHTML:'<input id="name" type="text" placeholder="Nom de l\'institution" />\n <input id="ville" type="text" placeholder="Ville" />
|
||||||
|
// <input id="pays" type="text" placeholder="Pays" />
|
||||||
|
// <input id="latitude" type="hidden" />
|
||||||
|
// <input id="longitude" type="hidden" />"
|
||||||
|
fieldcount++;
|
||||||
|
predata = undefined;
|
||||||
|
}
|
||||||
|
var predata;
|
||||||
|
function digere (gdata) {
|
||||||
|
var data = {};
|
||||||
|
for (var i in gdata.address_components) {
|
||||||
|
var txt = gdata.address_components[i].long_name;
|
||||||
|
var types = gdata.address_components[i].types
|
||||||
|
for (var j in types) {
|
||||||
|
switch(types[j]) {
|
||||||
|
case "locality":
|
||||||
|
data["ville"] = txt;
|
||||||
|
break;
|
||||||
|
case "country":
|
||||||
|
data["pays"] = txt;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
data["name"] = gdata.name;
|
||||||
|
data["longitude"] = gdata.geometry.location.lng();
|
||||||
|
data["latitude"] = gdata.geometry.location.lat();
|
||||||
|
predata = data;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
|
{% load staticfiles %}
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>ExperiENS</title>
|
<title>ExperiENS</title>
|
||||||
|
<link type="text/css" rel="stylesheet" href="{% static 'style.css' %}" />
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
{% block extra_head %}{% endblock %}
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|
|
@ -10,4 +10,5 @@ urlpatterns = patterns('',
|
||||||
url(r'^stage/new/$', views.stage_add, name='stage_add'),
|
url(r'^stage/new/$', views.stage_add, name='stage_add'),
|
||||||
url(r'^stage/(?P<stage_id>\d+)/edit/$', views.stage_edit, name='stage_edit'),
|
url(r'^stage/(?P<stage_id>\d+)/edit/$', views.stage_edit, name='stage_edit'),
|
||||||
url(r'^stage/(?P<stage_id>\d+)/edit/lieu/$', views.stage_edit_lieu, name='stage_edit_lieu'),
|
url(r'^stage/(?P<stage_id>\d+)/edit/lieu/$', views.stage_edit_lieu, name='stage_edit_lieu'),
|
||||||
|
url(r'^stage/(?P<stage_id>\d+)/edit/avis/$', views.stage_edit_feedback, name='stage_edit_feedback'),
|
||||||
)
|
)
|
|
@ -3,6 +3,7 @@ from django.contrib.auth.decorators import login_required
|
||||||
from django.http import HttpResponseRedirect, HttpResponse, HttpResponseForbidden
|
from django.http import HttpResponseRedirect, HttpResponse, HttpResponseForbidden
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django import forms
|
from django import forms
|
||||||
|
from django.contrib.gis.geos import GEOSGeometry
|
||||||
|
|
||||||
from monstage.models import *
|
from monstage.models import *
|
||||||
|
|
||||||
|
@ -64,9 +65,34 @@ def stage_add(request):
|
||||||
|
|
||||||
def stage_edit_lieu(request, stage_id):
|
def stage_edit_lieu(request, stage_id):
|
||||||
stage = get_object_or_404( Stage, pk = stage_id)
|
stage = get_object_or_404( Stage, pk = stage_id)
|
||||||
|
bullshit = ""
|
||||||
|
if request.POST:
|
||||||
|
i = 0
|
||||||
|
j = str(i)
|
||||||
|
bullshit = ", ".join([k for k in request.POST])
|
||||||
|
while request.POST.get('name'+j, False):
|
||||||
|
lieu = Lieu()
|
||||||
|
lieu.name = request.POST['name'+j]
|
||||||
|
lieu.ville = request.POST['ville'+j]
|
||||||
|
lieu.pays = request.POST['pays'+j]
|
||||||
|
lieu.coord = GEOSGeometry('POINT(%f %f)' % (float(request.POST['latitude'+j]), float(request.POST['longitude'+j])), srid=4326)
|
||||||
|
lieu.save()
|
||||||
|
LieuStage.objects.create(lieu = lieu, stage = stage)
|
||||||
|
i = i+1
|
||||||
|
j = str(i)
|
||||||
|
return HttpResponseRedirect(reverse('monstage:stage_edit_feedback', args=(new_stage.id,)))
|
||||||
if stage.profil_user != request.user.profil:
|
if stage.profil_user != request.user.profil:
|
||||||
return HttpResponseForbidden("Ce stage ne vous appartient pas")
|
return HttpResponseForbidden("Ce stage ne vous appartient pas")
|
||||||
return render(request, 'monstage/stage_edit_lieu.html', { 'stage': stage })
|
return render(request, 'monstage/stage_edit_lieu.html', { 'stage': stage, 'debug':bullshit })
|
||||||
|
|
||||||
|
def stage_edit_feedback(request, stage_id):
|
||||||
|
stage = get_object_or_404( Stage, pk = stage_id)
|
||||||
|
bullshit = ""
|
||||||
|
if request.POST:
|
||||||
|
pass
|
||||||
|
if stage.profil_user != request.user.profil:
|
||||||
|
return HttpResponseForbidden("Ce stage ne vous appartient pas")
|
||||||
|
return render(request, 'monstage/stage_edit_feedback.html', { 'stage': stage, 'debug':bullshit })
|
||||||
|
|
||||||
def stage_edit(request, stage_id):
|
def stage_edit(request, stage_id):
|
||||||
stage = get_object_or_404( Stage, pk = stage_id)
|
stage = get_object_or_404( Stage, pk = stage_id)
|
||||||
|
|
Loading…
Reference in a new issue