2017-04-13 13:35:48 +02:00
|
|
|
# coding: utf-8
|
|
|
|
|
|
|
|
from django import forms
|
|
|
|
from avisstage.models import Normalien, Stage, Lieu, AvisLieu, AvisStage
|
|
|
|
from widget import LatLonField
|
|
|
|
|
2017-04-13 22:50:00 +02:00
|
|
|
|
|
|
|
class AvisStageForm(forms.ModelForm):
|
|
|
|
class Meta:
|
|
|
|
model = AvisStage
|
|
|
|
fields = ['chapo', 'avis_ambiance', 'avis_sujet', 'avis_admin', 'les_plus', 'les_moins']
|
|
|
|
|
|
|
|
class AvisLieuForm(forms.ModelForm):
|
|
|
|
class Meta:
|
|
|
|
model = AvisLieu
|
|
|
|
fields = ['lieu', 'chapo', 'avis_lieustage', 'avis_pratique', 'avis_tourisme', 'les_plus', 'les_moins']
|
|
|
|
|
2017-04-13 13:35:48 +02:00
|
|
|
class StageForm(forms.ModelForm):
|
|
|
|
date_widget = forms.DateInput(attrs={"class":"datepicker"})
|
|
|
|
date_debut = forms.DateField(input_formats=["%d/%m/%Y"], widget=date_widget)
|
|
|
|
date_fin = forms.DateField(input_formats=["%d/%m/%Y"], widget=date_widget)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Stage
|
2017-04-13 22:50:00 +02:00
|
|
|
fields = ['sujet', 'date_debut', 'date_fin', 'type_stage', 'thematiques', 'matieres', 'encadrants']
|
2017-04-13 13:35:48 +02:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
if "request" in kwargs:
|
|
|
|
self.request = kwargs.pop("request")
|
|
|
|
super(StageForm, self).__init__(*args, **kwargs)
|
2017-04-13 22:50:00 +02:00
|
|
|
|
2017-04-13 13:35:48 +02:00
|
|
|
def save(self, commit=True):
|
2017-04-13 22:50:00 +02:00
|
|
|
if self.instance.id is None and hasattr(self, 'request'):
|
2017-04-13 13:35:48 +02:00
|
|
|
self.instance.auteur = self.request.user.profil
|
|
|
|
|
2017-04-13 22:50:00 +02:00
|
|
|
stage = super(StageForm, self).save(commit=commit)
|
|
|
|
return stage
|
2017-04-13 13:35:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
class LieuForm(forms.ModelForm):
|
|
|
|
coord = LatLonField()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Lieu
|
|
|
|
fields = ['nom', 'type_lieu', 'ville', 'pays', 'coord']
|
|
|
|
|