Ajout des avis sur les stages

This commit is contained in:
champeno 2015-06-13 23:02:16 +02:00
parent 1eac90e796
commit eaf2537048
7 changed files with 89 additions and 13 deletions

View file

@ -3,6 +3,7 @@
{% block content %}
<h1>{{ stage.sujet }}</h1>
<p><a href="{% url 'monstage:index' %}">Retour</a></p>
{% if modifiable %}<p><a href="{% url 'monstage:stage_edit' stage.id %}">Modifier</a></p>{% endif %}
<p>Stage de <a href="{% url 'monstage:profil' stage.profil_user.user.username %}">{{ stage.profil_user.user.first_name }} {{ stage.profil_user.user.last_name }}</a></p>
<p>Du {{ stage.start_date }} au {{ stage.end_date }}</p>
{% endblock %}

View file

@ -0,0 +1,10 @@
{% extends "skeleton.html" %}
{% block content %}
<h1>Editer le stage {{ stage.sujet }}</h1>
<p><a href="{% url 'monstage:stage' stage.id %}">Retour</a></p>
<p><a href="{% url 'monstage:stage_edit_desc' stage.id %}">Modifier la description du stage (sujet, ...)</a></p>
<p><a href="{% url 'monstage:stage_edit_lieu' stage.id %}">Modifier les lieux du stage</a></p>
<p><a href="{% url 'monstage:stage_edit_feedback' stage.id %}">Modifier son avis sur le stage</a></p>
{% endblock %}

View file

@ -0,0 +1,12 @@
{% extends "skeleton.html" %}
{% block content %}
<h1>Modifier la description du stage "{{ stage.sujet }}"</h1>
<p><a href="{% url 'monstage:stage_edit' stage.id %}">Retour</a></p>
<form action="{% url 'monstage:stage_edit_desc' stage.id %}" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Enregistrer" />
</form>
{% endblock %}

View file

@ -0,0 +1,23 @@
{% extends "skeleton.html" %}
{% load staticfiles %}
{% block content %}
<h1>Avis sur le stage "{{ stage.sujet }}"</h1>
<p><a href="{% url 'monstage:stage_edit' stage.id %}">Retour</a></p>
<p>{{ debug }}</p>
<form action="{% url 'monstage:stage_edit_feedback' stage.id %}" method="post">
{% csrf_token %}
<div class="avis_gen">
<h2>Le déroulement du stage</h2>
{{ form_gen.as_p }}
</div>
{% for obj in forms_lieux %}
<div class="avis_lieux">
<h2>Avis sur le lieu "{{ obj.1.name }}"</h2>
{{ obj.0.as_p }}
</div>
{% endfor %}
<input type="submit" value="Enregistrer" />
</form>
{% endblock %}

View file

@ -15,7 +15,7 @@
{% block content %}
<h1>Lieux du stage "{{ stage.sujet }}"</h1>
<p><a href="{% url 'monstage:index' %}">Retour</a></p>
<p><a href="{% url 'monstage:stage_edit' stage.id %}">Retour</a></p>
<p>{{ debug }}</p>
<div id="map_canvas"></div>
<input id="geocomplete" type="text" placeholder="Chercher un établissement" />

View file

@ -9,6 +9,7 @@ urlpatterns = patterns('',
url(r'^stage/(?P<stage_id>\d+)/$', views.stage, name='stage'),
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/description/$', views.stage_edit_desc, name='stage_edit_desc'),
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'),
)

View file

@ -40,12 +40,10 @@ def profil_edit(request):
def stage(request, stage_id):
stage = get_object_or_404( Stage, pk = stage_id)
return render(request, 'monstage/stage.html', {'stage': stage})
stage_mod = (stage.profil_user == request.user.profil)
return render(request, 'monstage/stage.html', {'stage': stage, 'modifiable': stage_mod})
class StageForm(forms.ModelForm):
def __init__(self, *args, **kw):
super(StageForm, self).__init__(*args, **kw)
class Meta:
model = Stage
fields = ("type_stage", "start_date", "end_date", "matieres", "sujet", "encadrants")
@ -63,8 +61,19 @@ def stage_add(request):
form = StageForm()
return render(request, 'monstage/stage_add.html', { 'form': form })
def stage_edit_desc(request, stage_id):
stage = get_object_or_404( Stage, pk = stage_id)
if stage.profil_user != request.user.profil:
return HttpResponseForbidden("Ce stage ne vous appartient pas")
bullshit = ""
if request.POST:
pass
return render(request, 'monstage/stage_edit_desc.html', { 'stage': stage, 'debug':bullshit })
def stage_edit_lieu(request, stage_id):
stage = get_object_or_404( Stage, pk = stage_id)
if stage.profil_user != request.user.profil:
return HttpResponseForbidden("Ce stage ne vous appartient pas")
bullshit = ""
if request.POST:
i = 0
@ -81,22 +90,42 @@ def stage_edit_lieu(request, stage_id):
i = i+1
j = str(i)
return HttpResponseRedirect(reverse('monstage:stage_edit_feedback', args=(new_stage.id,)))
if stage.profil_user != request.user.profil:
return HttpResponseForbidden("Ce stage ne vous appartient pas")
return render(request, 'monstage/stage_edit_lieu.html', { 'stage': stage, 'debug':bullshit })
class StageFeedbackForm(forms.ModelForm):
class Meta:
model = Stage
fields = ("avis_encadrants", "avis_equipe", "avis_stage", "avis_admin")
class LieuStageFeedbackForm(forms.ModelForm):
class Meta:
model = LieuStage
fields = ("avis_global", "avis_lieudevie", "avis_lieustage", "avis_pratique", "avis_visite", "avis_anecdotes")
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 })
if request.POST:
form_gen = StageFeedbackForm(request.POST, instance = stage, prefix = 'gen')
forms_lieux = [(LieuStageFeedbackForm(request.POST, instance = lieustage, prefix = lieustage.id), lieustage.lieu) for lieustage in stage.lieustage_set.all()]
valid = form_gen.is_valid()
for (form, _) in forms_lieux:
if not form.is_valid():
valid = False
if valid:
form_gen.save()
for (form, _) in forms_lieux:
form.save()
return HttpResponseRedirect(reverse('monstage:stage', args=(stage.id,)))
else:
form_gen = StageFeedbackForm(instance = stage, prefix = 'gen')
forms_lieux = [(LieuStageFeedbackForm(instance = lieustage, prefix = lieustage.id), lieustage.lieu) for lieustage in stage.lieustage_set.all()]
return render(request, 'monstage/stage_edit_feedback.html', { 'stage': stage, 'form_gen':form_gen, 'forms_lieux':forms_lieux })
def stage_edit(request, stage_id):
stage = get_object_or_404( Stage, pk = stage_id)
return render(request, 'monstage/stage.html', {'stage': stage})
return render(request, 'monstage/stage_edit.html', {'stage': stage})
def detail(request, question_id):
question = get_object_or_404(Question, pk=question_id)