46 lines
1.5 KiB
Python
46 lines
1.5 KiB
Python
# coding: utf-8
|
|
|
|
from django import forms
|
|
from avisstage.models import Normalien, Stage, Lieu, AvisLieu, AvisStage
|
|
from widget import LatLonField
|
|
|
|
|
|
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']
|
|
|
|
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
|
|
fields = ['sujet', 'date_debut', 'date_fin', 'type_stage', 'thematiques', 'matieres', 'encadrants']
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
if "request" in kwargs:
|
|
self.request = kwargs.pop("request")
|
|
super(StageForm, self).__init__(*args, **kwargs)
|
|
|
|
def save(self, commit=True):
|
|
if self.instance.id is None and hasattr(self, 'request'):
|
|
self.instance.auteur = self.request.user.profil
|
|
|
|
stage = super(StageForm, self).save(commit=commit)
|
|
return stage
|
|
|
|
|
|
class LieuForm(forms.ModelForm):
|
|
coord = LatLonField()
|
|
|
|
class Meta:
|
|
model = Lieu
|
|
fields = ['nom', 'type_lieu', 'ville', 'pays', 'coord']
|
|
|