Edition des lieux de stage fonctionnelle
This commit is contained in:
parent
bd953fdbdf
commit
a6bb3eee17
5 changed files with 322 additions and 29 deletions
245
monstage/listepays.py
Normal file
245
monstage/listepays.py
Normal file
|
@ -0,0 +1,245 @@
|
|||
# coding: utf-8
|
||||
|
||||
PAYS_CHOICES = (
|
||||
("AF", u"Afghanistan"),
|
||||
("AL", u"Albanie"),
|
||||
("AQ", u"Antarctique"),
|
||||
("DZ", u"Algérie"),
|
||||
("AS", u"Samoa Américaines"),
|
||||
("AD", u"Andorre"),
|
||||
("AO", u"Angola"),
|
||||
("AG", u"Antigua-et-Barbuda"),
|
||||
("AZ", u"Azerbaïdjan"),
|
||||
("AR", u"Argentine"),
|
||||
("AU", u"Australie"),
|
||||
("AT", u"Autriche"),
|
||||
("BS", u"Bahamas"),
|
||||
("BH", u"Bahreïn"),
|
||||
("BD", u"Bangladesh"),
|
||||
("AM", u"Arménie"),
|
||||
("BB", u"Barbade"),
|
||||
("BE", u"Belgique"),
|
||||
("BM", u"Bermudes"),
|
||||
("BT", u"Bhoutan"),
|
||||
("BO", u"Bolivie"),
|
||||
("BA", u"Bosnie-Herzégovine"),
|
||||
("BW", u"Botswana"),
|
||||
("BV", u"Île Bouvet"),
|
||||
("BR", u"Brésil"),
|
||||
("BZ", u"Belize"),
|
||||
("IO", u"Territoire Britannique de l'Océan Indien"),
|
||||
("SB", u"Îles Salomon"),
|
||||
("VG", u"Îles Vierges Britanniques"),
|
||||
("BN", u"Brunéi Darussalam"),
|
||||
("BG", u"Bulgarie"),
|
||||
("MM", u"Myanmar"),
|
||||
("BI", u"Burundi"),
|
||||
("BY", u"Bélarus"),
|
||||
("KH", u"Cambodge"),
|
||||
("CM", u"Cameroun"),
|
||||
("CA", u"Canada"),
|
||||
("CV", u"Cap-vert"),
|
||||
("KY", u"Îles Caïmanes"),
|
||||
("CF", u"République Centrafricaine"),
|
||||
("LK", u"Sri Lanka"),
|
||||
("TD", u"Tchad"),
|
||||
("CL", u"Chili"),
|
||||
("CN", u"Chine"),
|
||||
("TW", u"Taïwan"),
|
||||
("CX", u"Île Christmas"),
|
||||
("CC", u"Îles Cocos (Keeling)"),
|
||||
("CO", u"Colombie"),
|
||||
("KM", u"Comores"),
|
||||
("YT", u"Mayotte"),
|
||||
("CG", u"République du Congo"),
|
||||
("CD", u"République Démocratique du Congo"),
|
||||
("CK", u"Îles Cook"),
|
||||
("CR", u"Costa Rica"),
|
||||
("HR", u"Croatie"),
|
||||
("CU", u"Cuba"),
|
||||
("CY", u"Chypre"),
|
||||
("CZ", u"République Tchèque"),
|
||||
("BJ", u"Bénin"),
|
||||
("DK", u"Danemark"),
|
||||
("DM", u"Dominique"),
|
||||
("DO", u"République Dominicaine"),
|
||||
("EC", u"Équateur"),
|
||||
("SV", u"El Salvador"),
|
||||
("GQ", u"Guinée Équatoriale"),
|
||||
("ET", u"Éthiopie"),
|
||||
("ER", u"Érythrée"),
|
||||
("EE", u"Estonie"),
|
||||
("FO", u"Îles Féroé"),
|
||||
("FK", u"Îles (malvinas) Falkland"),
|
||||
("GS", u"Géorgie du Sud et les Îles Sandwich du Sud"),
|
||||
("FJ", u"Fidji"),
|
||||
("FI", u"Finlande"),
|
||||
("AX", u"Îles Åland"),
|
||||
("FR", u"France"),
|
||||
("GF", u"Guyane Française"),
|
||||
("PF", u"Polynésie Française"),
|
||||
("TF", u"Terres Australes Françaises"),
|
||||
("DJ", u"Djibouti"),
|
||||
("GA", u"Gabon"),
|
||||
("GE", u"Géorgie"),
|
||||
("GM", u"Gambie"),
|
||||
("PS", u"Territoire Palestinien Occupé"),
|
||||
("DE", u"Allemagne"),
|
||||
("GH", u"Ghana"),
|
||||
("GI", u"Gibraltar"),
|
||||
("KI", u"Kiribati"),
|
||||
("GR", u"Grèce"),
|
||||
("GL", u"Groenland"),
|
||||
("GD", u"Grenade"),
|
||||
("GP", u"Guadeloupe"),
|
||||
("GU", u"Guam"),
|
||||
("GT", u"Guatemala"),
|
||||
("GN", u"Guinée"),
|
||||
("GY", u"Guyana"),
|
||||
("HT", u"Haïti"),
|
||||
("HM", u"Îles Heard et Mcdonald"),
|
||||
("VA", u"Saint-Siège (état de la Cité du Vatican)"),
|
||||
("HN", u"Honduras"),
|
||||
("HK", u"Hong-Kong"),
|
||||
("HU", u"Hongrie"),
|
||||
("IS", u"Islande"),
|
||||
("IN", u"Inde"),
|
||||
("ID", u"Indonésie"),
|
||||
("IR", u"République Islamique d'Iran"),
|
||||
("IQ", u"Iraq"),
|
||||
("IE", u"Irlande"),
|
||||
("IL", u"Israël"),
|
||||
("IT", u"Italie"),
|
||||
("CI", u"Côte d'Ivoire"),
|
||||
("JM", u"Jamaïque"),
|
||||
("JP", u"Japon"),
|
||||
("KZ", u"Kazakhstan"),
|
||||
("JO", u"Jordanie"),
|
||||
("KE", u"Kenya"),
|
||||
("KP", u"République Populaire Démocratique de Corée"),
|
||||
("KR", u"République de Corée"),
|
||||
("KW", u"Koweït"),
|
||||
("KG", u"Kirghizistan"),
|
||||
("LA", u"République Démocratique Populaire Lao"),
|
||||
("LB", u"Liban"),
|
||||
("LS", u"Lesotho"),
|
||||
("LV", u"Lettonie"),
|
||||
("LR", u"Libéria"),
|
||||
("LY", u"Jamahiriya Arabe Libyenne"),
|
||||
("LI", u"Liechtenstein"),
|
||||
("LT", u"Lituanie"),
|
||||
("LU", u"Luxembourg"),
|
||||
("MO", u"Macao"),
|
||||
("MG", u"Madagascar"),
|
||||
("MW", u"Malawi"),
|
||||
("MY", u"Malaisie"),
|
||||
("MV", u"Maldives"),
|
||||
("ML", u"Mali"),
|
||||
("MT", u"Malte"),
|
||||
("MQ", u"Martinique"),
|
||||
("MR", u"Mauritanie"),
|
||||
("MU", u"Maurice"),
|
||||
("MX", u"Mexique"),
|
||||
("MC", u"Monaco"),
|
||||
("MN", u"Mongolie"),
|
||||
("MD", u"République de Moldova"),
|
||||
("MS", u"Montserrat"),
|
||||
("MA", u"Maroc"),
|
||||
("MZ", u"Mozambique"),
|
||||
("OM", u"Oman"),
|
||||
("NA", u"Namibie"),
|
||||
("NR", u"Nauru"),
|
||||
("NP", u"Népal"),
|
||||
("NL", u"Pays-Bas"),
|
||||
("AN", u"Antilles Néerlandaises"),
|
||||
("AW", u"Aruba"),
|
||||
("NC", u"Nouvelle-Calédonie"),
|
||||
("VU", u"Vanuatu"),
|
||||
("NZ", u"Nouvelle-Zélande"),
|
||||
("NI", u"Nicaragua"),
|
||||
("NE", u"Niger"),
|
||||
("NG", u"Nigéria"),
|
||||
("NU", u"Niué"),
|
||||
("NF", u"Île Norfolk"),
|
||||
("NO", u"Norvège"),
|
||||
("MP", u"Îles Mariannes du Nord"),
|
||||
("UM", u"Îles Mineures Éloignées des États-Unis"),
|
||||
("FM", u"États Fédérés de Micronésie"),
|
||||
("MH", u"Îles Marshall"),
|
||||
("PW", u"Palaos"),
|
||||
("PK", u"Pakistan"),
|
||||
("PA", u"Panama"),
|
||||
("PG", u"Papouasie-Nouvelle-Guinée"),
|
||||
("PY", u"Paraguay"),
|
||||
("PE", u"Pérou"),
|
||||
("PH", u"Philippines"),
|
||||
("PN", u"Pitcairn"),
|
||||
("PL", u"Pologne"),
|
||||
("PT", u"Portugal"),
|
||||
("GW", u"Guinée-Bissau"),
|
||||
("TL", u"Timor-Leste"),
|
||||
("PR", u"Porto Rico"),
|
||||
("QA", u"Qatar"),
|
||||
("RE", u"Réunion"),
|
||||
("RO", u"Roumanie"),
|
||||
("RU", u"Fédération de Russie"),
|
||||
("RW", u"Rwanda"),
|
||||
("SH", u"Sainte-Hélène"),
|
||||
("KN", u"Saint-Kitts-et-Nevis"),
|
||||
("AI", u"Anguilla"),
|
||||
("LC", u"Sainte-Lucie"),
|
||||
("PM", u"Saint-Pierre-et-Miquelon"),
|
||||
("VC", u"Saint-Vincent-et-les Grenadines"),
|
||||
("SM", u"Saint-Marin"),
|
||||
("ST", u"Sao Tomé-et-Principe"),
|
||||
("SA", u"Arabie Saoudite"),
|
||||
("SN", u"Sénégal"),
|
||||
("SC", u"Seychelles"),
|
||||
("SL", u"Sierra Leone"),
|
||||
("SG", u"Singapour"),
|
||||
("SK", u"Slovaquie"),
|
||||
("VN", u"Viet Nam"),
|
||||
("SI", u"Slovénie"),
|
||||
("SO", u"Somalie"),
|
||||
("ZA", u"Afrique du Sud"),
|
||||
("ZW", u"Zimbabwe"),
|
||||
("ES", u"Espagne"),
|
||||
("EH", u"Sahara Occidental"),
|
||||
("SD", u"Soudan"),
|
||||
("SR", u"Suriname"),
|
||||
("SJ", u"Svalbard etÎle Jan Mayen"),
|
||||
("SZ", u"Swaziland"),
|
||||
("SE", u"Suède"),
|
||||
("CH", u"Suisse"),
|
||||
("SY", u"République Arabe Syrienne"),
|
||||
("TJ", u"Tadjikistan"),
|
||||
("TH", u"Thaïlande"),
|
||||
("TG", u"Togo"),
|
||||
("TK", u"Tokelau"),
|
||||
("TO", u"Tonga"),
|
||||
("TT", u"Trinité-et-Tobago"),
|
||||
("AE", u"Émirats Arabes Unis"),
|
||||
("TN", u"Tunisie"),
|
||||
("TR", u"Turquie"),
|
||||
("TM", u"Turkménistan"),
|
||||
("TC", u"Îles Turks et Caïques"),
|
||||
("TV", u"Tuvalu"),
|
||||
("UG", u"Ouganda"),
|
||||
("UA", u"Ukraine"),
|
||||
("MK", u"L'ex-République Yougoslave de Macédoine"),
|
||||
("EG", u"Égypte"),
|
||||
("GB", u"Royaume-Uni"),
|
||||
("IM", u"Île de Man"),
|
||||
("TZ", u"République-Unie de Tanzanie"),
|
||||
("US", u"États-Unis"),
|
||||
("VI", u"Îles Vierges des États-Unis"),
|
||||
("BF", u"Burkina Faso"),
|
||||
("UY", u"Uruguay"),
|
||||
("UZ", u"Ouzbékistan"),
|
||||
("VE", u"Venezuela"),
|
||||
("WF", u"Wallis et Futuna"),
|
||||
("WS", u"Samoa"),
|
||||
("YE", u"Yémen"),
|
||||
("CS", u"Serbie-et-Monténégro"),
|
||||
("ZM", u"Zambie"),
|
||||
)
|
20
monstage/migrations/0004_auto_20150614_1517.py
Normal file
20
monstage/migrations/0004_auto_20150614_1517.py
Normal file
File diff suppressed because one or more lines are too long
|
@ -6,6 +6,8 @@ from django.utils.translation import ugettext_lazy as _
|
|||
from django.contrib.gis.db import models as geomodels
|
||||
from django_cas_ng.signals import cas_user_authenticated
|
||||
|
||||
from monstage.listepays import PAYS_CHOICES
|
||||
|
||||
TYPE_STAGE_CHOICES = (
|
||||
('stage', _(u"Stage")),
|
||||
)
|
||||
|
@ -41,7 +43,9 @@ cas_user_authenticated.connect(create_user_profile)
|
|||
class Lieu(models.Model):
|
||||
name = models.CharField(_(u"Nom de l'institution d'accueil"), max_length = 250)
|
||||
ville = models.CharField(_(u"Ville"), max_length = 200)
|
||||
pays = models.CharField(_(u"Pays"), max_length = 200)
|
||||
pays = models.CharField(_(u"Pays"),
|
||||
choices = PAYS_CHOICES,
|
||||
max_length = choices_length (TYPE_STAGE_CHOICES))
|
||||
coord = geomodels.PointField(_(u"Coordonnées"), geography = True)
|
||||
objects = geomodels.GeoManager() # Requis par GeoDjango
|
||||
type_lieu = models.CharField( _(u"Type de structure d'accueil"),
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
function addFieldSet (data) {
|
||||
if (data == undefined) return;
|
||||
var t = $("<div>")
|
||||
t.html(emptyform.replace({% verbatim %}/\{\{ID\}\}/gi{% endverbatim %}, fieldcount));
|
||||
t.html(emptyform.replace(/\{\{ID\}\}/gi, fieldcount));
|
||||
places.append(t);
|
||||
document.getElementById('id_'+fieldcount+'-name').value = data.name;
|
||||
document.getElementById('id_'+fieldcount+'-ville').value = data.ville;
|
||||
|
@ -65,15 +65,14 @@
|
|||
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]) {
|
||||
var obj = gdata.address_components[i];
|
||||
for (var j in obj.types) {
|
||||
switch(obj.types[j]) {
|
||||
case "locality":
|
||||
data["ville"] = txt;
|
||||
data["ville"] = obj.long_name;
|
||||
break;
|
||||
case "country":
|
||||
data["pays"] = txt;
|
||||
data["pays"] = obj.short_name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,26 +77,32 @@ def stage_edit_desc(request, stage_id):
|
|||
class LieuForm(forms.ModelForm):
|
||||
latitude = forms.DecimalField()
|
||||
longitude = forms.DecimalField()
|
||||
delete = forms.BooleanField(help_text=(u'Supprimer ce lieu'))
|
||||
delete.label = ''
|
||||
delete = forms.BooleanField(help_text=(u'Supprimer ce lieu'), required = False, label = '')
|
||||
temp_id = forms.IntegerField(required = False)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
from django.forms.widgets import HiddenInput
|
||||
super(LieuForm, self).__init__(*args, **kwargs)
|
||||
self.fields['latitude'].widget = HiddenInput()
|
||||
self.fields['longitude'].widget = HiddenInput()
|
||||
self.fields['temp_id'].widget = HiddenInput()
|
||||
lieu = kwargs.pop('instance', None)
|
||||
if lieu:
|
||||
self.fields['temp_id'].initial = lieu.id
|
||||
self.fields['latitude'].initial = lieu.coord.coords[0]
|
||||
self.fields['longitude'].initial = lieu.coord.coords[1]
|
||||
|
||||
class Meta:
|
||||
model = Lieu
|
||||
fields = ("name", "ville", "pays")
|
||||
|
||||
def save(self, commit=True):
|
||||
lieu = super(StageLieuForm, self).save(commit=False)
|
||||
def is_to_delete(self):
|
||||
return self.cleaned_data['delete']
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
lieu = super(LieuForm, self).save(commit=False, *args, **kwargs)
|
||||
lieu.coord = GEOSGeometry('POINT(%f %f)' % (self.cleaned_data['latitude'], self.cleaned_data['latitude']), srid=4326)
|
||||
if commit:
|
||||
return lieu.save(commit=True)
|
||||
else:
|
||||
return lieu
|
||||
return lieu.save(*args, **kwargs)
|
||||
|
||||
def stage_edit_lieu(request, stage_id):
|
||||
stage = get_object_or_404( Stage, pk = stage_id)
|
||||
|
@ -105,22 +111,41 @@ def stage_edit_lieu(request, stage_id):
|
|||
return HttpResponseForbidden("Ce stage ne vous appartient pas")
|
||||
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.save()
|
||||
LieuStage.objects.create(lieu = lieu, stage = stage)
|
||||
valid = True
|
||||
lieux = []
|
||||
forms = []
|
||||
for lieustage in stage.lieustage_set.all():
|
||||
bullshit += str(i) + 'a '
|
||||
lieuform = LieuForm(request.POST, instance = lieustage.lieu, prefix = str(i))
|
||||
i = i+1
|
||||
j = str(i)
|
||||
return HttpResponseRedirect(reverse('monstage:stage_edit_feedback', args=(new_stage.id,)))
|
||||
if not lieuform.is_valid():
|
||||
valid = False
|
||||
forms.append(lieuform)
|
||||
continue
|
||||
if lieuform.is_to_delete():
|
||||
lieustage.delete()
|
||||
else:
|
||||
forms.append(lieuform)
|
||||
lieux.append(lieuform.save())
|
||||
while request.POST.get('%d-name' % i, False) and i<20:
|
||||
bullshit += str(i) + 'b '
|
||||
lieuform = LieuForm(request.POST, prefix = str(i))
|
||||
i = i+1
|
||||
if not lieuform.is_valid():
|
||||
bullshit += 'invalid '
|
||||
valid = False
|
||||
forms.append(lieuform)
|
||||
continue
|
||||
if not lieuform.is_to_delete():
|
||||
forms.append(lieuform)
|
||||
lieu = lieuform.save(commit = True)
|
||||
lieux.append(lieu)
|
||||
LieuStage.objects.create(lieu = lieu, stage = stage)
|
||||
# if valid:
|
||||
# return HttpResponseRedirect(reverse('monstage:stage_edit_feedback', args=(new_stage.id,)))
|
||||
else:
|
||||
forms = [LieuForm(instance=lieu, prefix=str(counter)) for counter, lieu in enumerate(stage.lieux.all())]
|
||||
emptyform = LieuForm(prefix='{{ID}}')
|
||||
emptyform = LieuForm(prefix='{{ID}}')
|
||||
return render(request, 'monstage/stage_edit_lieu.html', { 'stage': stage, 'debug': bullshit, 'forms': forms, 'emptyform': addslashes(emptyform.as_p()), 'numforms':len(forms) })
|
||||
|
||||
class StageFeedbackForm(forms.ModelForm):
|
||||
|
|
Loading…
Reference in a new issue