diff --git a/monstage/templates/monstage/stage.html b/monstage/templates/monstage/stage.html index 56dba48..d9b5e6f 100644 --- a/monstage/templates/monstage/stage.html +++ b/monstage/templates/monstage/stage.html @@ -3,6 +3,7 @@ {% block content %}

{{ stage.sujet }}

Retour

+ {% if modifiable %}

Modifier

{% endif %}

Stage de {{ stage.profil_user.user.first_name }} {{ stage.profil_user.user.last_name }}

Du {{ stage.start_date }} au {{ stage.end_date }}

{% endblock %} diff --git a/monstage/templates/monstage/stage_edit.html b/monstage/templates/monstage/stage_edit.html new file mode 100644 index 0000000..21f5a13 --- /dev/null +++ b/monstage/templates/monstage/stage_edit.html @@ -0,0 +1,10 @@ +{% extends "skeleton.html" %} + +{% block content %} +

Editer le stage {{ stage.sujet }}

+

Retour

+

Modifier la description du stage (sujet, ...)

+

Modifier les lieux du stage

+

Modifier son avis sur le stage

+{% endblock %} + diff --git a/monstage/templates/monstage/stage_edit_desc.html b/monstage/templates/monstage/stage_edit_desc.html new file mode 100644 index 0000000..06e00f6 --- /dev/null +++ b/monstage/templates/monstage/stage_edit_desc.html @@ -0,0 +1,12 @@ +{% extends "skeleton.html" %} + +{% block content %} +

Modifier la description du stage "{{ stage.sujet }}"

+

Retour

+
+ {% csrf_token %} + {{ form.as_p }} + +
+{% endblock %} + diff --git a/monstage/templates/monstage/stage_edit_feedback.html b/monstage/templates/monstage/stage_edit_feedback.html new file mode 100644 index 0000000..781b252 --- /dev/null +++ b/monstage/templates/monstage/stage_edit_feedback.html @@ -0,0 +1,23 @@ +{% extends "skeleton.html" %} +{% load staticfiles %} + +{% block content %} +

Avis sur le stage "{{ stage.sujet }}"

+

Retour

+

{{ debug }}

+
+ {% csrf_token %} +
+

Le déroulement du stage

+ {{ form_gen.as_p }} +
+ {% for obj in forms_lieux %} +
+

Avis sur le lieu "{{ obj.1.name }}"

+ {{ obj.0.as_p }} +
+ {% endfor %} + +
+{% endblock %} + diff --git a/monstage/templates/monstage/stage_edit_lieu.html b/monstage/templates/monstage/stage_edit_lieu.html index 1c0fd61..0b5213b 100644 --- a/monstage/templates/monstage/stage_edit_lieu.html +++ b/monstage/templates/monstage/stage_edit_lieu.html @@ -15,7 +15,7 @@ {% block content %}

Lieux du stage "{{ stage.sujet }}"

-

Retour

+

Retour

{{ debug }}

diff --git a/monstage/urls.py b/monstage/urls.py index 9b9b326..dd77010 100644 --- a/monstage/urls.py +++ b/monstage/urls.py @@ -9,6 +9,7 @@ urlpatterns = patterns('', url(r'^stage/(?P\d+)/$', views.stage, name='stage'), url(r'^stage/new/$', views.stage_add, name='stage_add'), url(r'^stage/(?P\d+)/edit/$', views.stage_edit, name='stage_edit'), + url(r'^stage/(?P\d+)/edit/description/$', views.stage_edit_desc, name='stage_edit_desc'), url(r'^stage/(?P\d+)/edit/lieu/$', views.stage_edit_lieu, name='stage_edit_lieu'), url(r'^stage/(?P\d+)/edit/avis/$', views.stage_edit_feedback, name='stage_edit_feedback'), ) \ No newline at end of file diff --git a/monstage/views.py b/monstage/views.py index ee91e64..5fcc359 100644 --- a/monstage/views.py +++ b/monstage/views.py @@ -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)