diff --git a/avisstage/models.py b/avisstage/models.py index b8f4b4c..eb2565d 100644 --- a/avisstage/models.py +++ b/avisstage/models.py @@ -9,7 +9,7 @@ from django.template.defaultfilters import slugify from django.contrib.gis.db import models as geomodels from django.forms.widgets import DateInput from django.urls import reverse - +from django.utils import timezone from taggit_autosuggest.managers import TaggableManager from tinymce.models import HTMLField as RichTextField @@ -130,6 +130,8 @@ class Stage(models.Model): # Misc auteur = models.ForeignKey(Normalien, related_name="stages") public = models.BooleanField(u"Visible publiquement", default=False) + date_creation = models.DateTimeField(u"Créé le", default=timezone.now) + date_maj = models.DateTimeField(u"Mis à jour le", default=timezone.now) # Caractéristiques du stage sujet = models.CharField(u"Sujet", max_length=500) diff --git a/avisstage/sass/screen.scss b/avisstage/sass/screen.scss index bc7c3ff..5b23694 100644 --- a/avisstage/sass/screen.scss +++ b/avisstage/sass/screen.scss @@ -189,6 +189,12 @@ article.stage { text-shadow: -3px 3px 0 rgba(#000, 0.1); //margin-right: 25px; } + + #stage-map { + height: 300px; + width: 100%; + } + section { background: #eee; padding: 14px; @@ -302,6 +308,24 @@ article.stage { } } +.edit-box { + background: #eee; + margin: 10px; + padding: 10px 20px; + text-align: center; + + &.public { + background: lighten($vert, 40%); + border: 1px solid $vert * 0.7; + } + + &.prive { + background: lighten($rouge, 40%); + border: 1px solid $rouge * 0.7; + } + +} + .article-wrapper { display: table; .toc-wrapper, article { @@ -355,6 +379,21 @@ input[type='text'], input[type='password'], textarea, select { } } +input[type="submit"] { + background-color: $fond; + color: #fff; + border: 1px solid $fond * 0.7; + border-radius: 5px; + padding: 8px 12px; + display: block; + margin-left: auto; + margin-right: 0; +} + +p input[type="submit"] { + display:inline-block; +} + select { -moz-appearance: none; @@ -522,6 +561,17 @@ div.as-results { overflow: auto; } + + .window-closer { + position: absolute; + top: 0; + right: 0; + padding: 12px; + z-index: 3; + &:after { + content: "×"; + } + } } .lieu-ui { @@ -537,3 +587,21 @@ div.as-results { #avis_lieu_vide { display:none; } + +a.lieu-change { + color:#fff; + background: $compl; + overflow: hidden; + display: inline-block; + max-width: 250px; + text-overflow: ellipsis; + white-space: nowrap; + padding: 5px; + border-radius: 5px; + margin-right: 7px; + + &.ajout:before { + content: "+"; + margin-right: 5px; + } +} diff --git a/avisstage/static/css/screen.css b/avisstage/static/css/screen.css index 8860e04..131c92b 100644 --- a/avisstage/static/css/screen.css +++ b/avisstage/static/css/screen.css @@ -247,30 +247,35 @@ article.stage h3 { color: #000; text-shadow: -3px 3px 0 rgba(0, 0, 0, 0.1); } -/* line 192, ../../sass/screen.scss */ +/* line 193, ../../sass/screen.scss */ +article.stage #stage-map { + height: 300px; + width: 100%; +} +/* line 198, ../../sass/screen.scss */ article.stage section { background: #eee; padding: 14px; max-width: 600px; margin: 30px auto; } -/* line 198, ../../sass/screen.scss */ +/* line 204, ../../sass/screen.scss */ article.stage section:first-child { margin-top: 0; } -/* line 200, ../../sass/screen.scss */ +/* line 206, ../../sass/screen.scss */ article.stage section:first-child h3 { margin-top: 0; } -/* line 205, ../../sass/screen.scss */ +/* line 211, ../../sass/screen.scss */ article.stage section.misc { padding-top: 0; } -/* line 207, ../../sass/screen.scss */ +/* line 213, ../../sass/screen.scss */ article.stage section.misc ul.infos { margin: 0 -3px; } -/* line 210, ../../sass/screen.scss */ +/* line 216, ../../sass/screen.scss */ article.stage section.misc ul.infos li { display: inline-block; padding: 5px; @@ -280,42 +285,42 @@ article.stage section.misc ul.infos li { font-size: 0.9em; border-radius: 4px; } -/* line 219, ../../sass/screen.scss */ +/* line 225, ../../sass/screen.scss */ article.stage section.misc ul.infos li.thematique { background-color: #28BF8A; } -/* line 222, ../../sass/screen.scss */ +/* line 228, ../../sass/screen.scss */ article.stage section.misc ul.infos li.matiere { background-color: #E80051; } -/* line 229, ../../sass/screen.scss */ +/* line 235, ../../sass/screen.scss */ article.stage section .chapo, article.stage section .avis-texte { margin-bottom: 15px; background: #fff; padding: 20px; } -/* line 234, ../../sass/screen.scss */ +/* line 240, ../../sass/screen.scss */ article.stage section .chapo { font-size: 1.1em; font-weight: 500; font-variant: small-caps; } -/* line 239, ../../sass/screen.scss */ +/* line 245, ../../sass/screen.scss */ article.stage section .avis-texte { border-left: 1px solid #ccc; padding-left: 15px; } -/* line 244, ../../sass/screen.scss */ +/* line 250, ../../sass/screen.scss */ article.stage section .plusmoins { max-width: 600px; margin: 15px auto; } -/* line 248, ../../sass/screen.scss */ +/* line 254, ../../sass/screen.scss */ article.stage section .plusmoins > div { display: table; width: 100%; } -/* line 252, ../../sass/screen.scss */ +/* line 258, ../../sass/screen.scss */ article.stage section .plusmoins > div:before { content: " "; width: 100px; @@ -324,83 +329,101 @@ article.stage section .plusmoins > div:before { text-align: right; padding-right: 12px; } -/* line 261, ../../sass/screen.scss */ +/* line 267, ../../sass/screen.scss */ article.stage section .plusmoins > div > *, article.stage section .plusmoins > div:before { display: table-cell; } -/* line 265, ../../sass/screen.scss */ +/* line 271, ../../sass/screen.scss */ article.stage section .plusmoins > div > div { padding: 15px; color: #fff; } -/* line 268, ../../sass/screen.scss */ +/* line 274, ../../sass/screen.scss */ article.stage section .plusmoins > div > div h4 { font-weight: normal; margin-left: -5px; font-size: 0.9em; opacity: 0.9; } -/* line 274, ../../sass/screen.scss */ +/* line 280, ../../sass/screen.scss */ article.stage section .plusmoins > div > div p { font-weight: bold; margin: 2px; } -/* line 282, ../../sass/screen.scss */ +/* line 288, ../../sass/screen.scss */ article.stage section .plusmoins .plus > div { background: #23cc56; } -/* line 285, ../../sass/screen.scss */ +/* line 291, ../../sass/screen.scss */ article.stage section .plusmoins .plus:before { content: "Les +"; vertical-align: bottom; color: #1b9f43; } -/* line 292, ../../sass/screen.scss */ +/* line 298, ../../sass/screen.scss */ article.stage section .plusmoins .moins > div { background: #af1822; } -/* line 295, ../../sass/screen.scss */ +/* line 301, ../../sass/screen.scss */ article.stage section .plusmoins .moins:before { content: "Les -"; vertical-align: top; color: #88131b; } -/* line 305, ../../sass/screen.scss */ +/* line 311, ../../sass/screen.scss */ +.edit-box { + background: #eee; + margin: 10px; + padding: 10px 20px; + text-align: center; +} +/* line 317, ../../sass/screen.scss */ +.edit-box.public { + background: #dcfae5; + border: 1px solid #1b9f43; +} +/* line 322, ../../sass/screen.scss */ +.edit-box.prive { + background: #f5b4b9; + border: 1px solid #88131b; +} + +/* line 329, ../../sass/screen.scss */ .article-wrapper { display: table; } -/* line 307, ../../sass/screen.scss */ +/* line 331, ../../sass/screen.scss */ .article-wrapper .toc-wrapper, .article-wrapper article { display: table-cell; vertical-align: top; } -/* line 311, ../../sass/screen.scss */ +/* line 335, ../../sass/screen.scss */ .article-wrapper .toc-wrapper { max-width: 250px; width: 25%; } -/* line 315, ../../sass/screen.scss */ +/* line 339, ../../sass/screen.scss */ .article-wrapper .toc { position: -webkit-sticky; position: sticky; top: 0; } -/* line 319, ../../sass/screen.scss */ +/* line 343, ../../sass/screen.scss */ .article-wrapper .toc a { color: inherit; font-weight: normal; } -/* line 326, ../../sass/screen.scss */ +/* line 350, ../../sass/screen.scss */ .article-wrapper .toc .toc-h3 a { font-weight: 300; } -/* line 329, ../../sass/screen.scss */ +/* line 353, ../../sass/screen.scss */ .article-wrapper .toc .toc-active a { color: #E80051; } -/* line 338, ../../sass/screen.scss */ +/* line 362, ../../sass/screen.scss */ input, textarea, select, div.tinymce { background: #fff; font-size: 1em; @@ -410,19 +433,36 @@ input, textarea, select, div.tinymce { padding: 5px; } -/* line 347, ../../sass/screen.scss */ +/* line 371, ../../sass/screen.scss */ input[type='text'], input[type='password'], textarea, select { border: none; border-bottom: 1px solid #E80051; width: 100%; transition: border 1s ease-out, background 1s ease-out; } -/* line 353, ../../sass/screen.scss */ +/* line 377, ../../sass/screen.scss */ input[type='text']:focus, input[type='password']:focus, textarea:focus, select:focus { background-color: #ffe8f0; } -/* line 359, ../../sass/screen.scss */ +/* line 382, ../../sass/screen.scss */ +input[type="submit"] { + background-color: #E80051; + color: #fff; + border: 1px solid #a20039; + border-radius: 5px; + padding: 8px 12px; + display: block; + margin-left: auto; + margin-right: 0; +} + +/* line 393, ../../sass/screen.scss */ +p input[type="submit"] { + display: inline-block; +} + +/* line 398, ../../sass/screen.scss */ select { -moz-appearance: none; appearance: none; @@ -431,7 +471,7 @@ select { cursor: pointer; } -/* line 367, ../../sass/screen.scss */ +/* line 406, ../../sass/screen.scss */ textarea, div.tinymce { border: none; border-left: 1px solid #E80051; @@ -440,26 +480,26 @@ textarea, div.tinymce { transition: border 1s ease-out, background 1s ease-out; } -/* line 375, ../../sass/screen.scss */ +/* line 414, ../../sass/screen.scss */ div.tinymce.mce-edit-focus { background-color: #ffe8f0; outline: none; } -/* line 380, ../../sass/screen.scss */ +/* line 419, ../../sass/screen.scss */ textarea { height: 200px; resize: vertical; } -/* line 386, ../../sass/screen.scss */ +/* line 425, ../../sass/screen.scss */ form .field { margin: 5px 0; display: flex; background: #fff; padding: 10px; } -/* line 392, ../../sass/screen.scss */ +/* line 431, ../../sass/screen.scss */ form .field label, form .field .label { display: inline-block; width: 250px; @@ -468,33 +508,33 @@ form .field label, form .field .label { padding-top: 5px; flex-shrink: 0; } -/* line 400, ../../sass/screen.scss */ +/* line 439, ../../sass/screen.scss */ form .field label { font-family: Podkova, serif; font-weight: bold; } -/* line 404, ../../sass/screen.scss */ +/* line 443, ../../sass/screen.scss */ form .field .help_text { font-style: italic; font-size: 0.9em; } -/* line 408, ../../sass/screen.scss */ +/* line 447, ../../sass/screen.scss */ form .field .input { display: inline-block; flex-grow: 1; margin-right: 10px; } -/* line 417, ../../sass/screen.scss */ +/* line 456, ../../sass/screen.scss */ ul.as-selections { display: flex; flex-wrap: wrap; } -/* line 421, ../../sass/screen.scss */ +/* line 460, ../../sass/screen.scss */ ul.as-selections li { display: inline-block; } -/* line 425, ../../sass/screen.scss */ +/* line 464, ../../sass/screen.scss */ ul.as-selections .as-selection-item { padding: 0 5px; background: #28BF8A; @@ -503,57 +543,57 @@ ul.as-selections .as-selection-item { border-radius: 2px; font-weight: 500; } -/* line 433, ../../sass/screen.scss */ +/* line 472, ../../sass/screen.scss */ ul.as-selections .as-selection-item a.as-close { color: #fff; -webkit-cursor: pointer; cursor: pointer; margin-right: 5px; } -/* line 440, ../../sass/screen.scss */ +/* line 479, ../../sass/screen.scss */ ul.as-selections .as-selection-item.selected { background: #E80051; } -/* line 445, ../../sass/screen.scss */ +/* line 484, ../../sass/screen.scss */ ul.as-selections .as-original { flex-grow: 1; min-width: 200px; } -/* line 449, ../../sass/screen.scss */ +/* line 488, ../../sass/screen.scss */ ul.as-selections .as-original input { width: 100%; } -/* line 455, ../../sass/screen.scss */ +/* line 494, ../../sass/screen.scss */ div.as-results { position: relative; } -/* line 457, ../../sass/screen.scss */ +/* line 496, ../../sass/screen.scss */ div.as-results ul { position: absolute; width: 100%; background: #fff; border: 1px solid #ff82ae; } -/* line 464, ../../sass/screen.scss */ +/* line 503, ../../sass/screen.scss */ div.as-results ul li { padding: 3px 5px; } -/* line 470, ../../sass/screen.scss */ +/* line 509, ../../sass/screen.scss */ div.as-results ul li.as-result-item.active { background: #ebfbf5; } -/* line 475, ../../sass/screen.scss */ +/* line 514, ../../sass/screen.scss */ div.as-results ul li.as-message { font-style: italic; } -/* line 482, ../../sass/screen.scss */ +/* line 521, ../../sass/screen.scss */ #map_addlieu { height: 500px; } -/* line 486, ../../sass/screen.scss */ +/* line 525, ../../sass/screen.scss */ .window { display: none; position: fixed; @@ -564,11 +604,11 @@ div.as-results ul li.as-message { left: 0; z-index: 10; } -/* line 496, ../../sass/screen.scss */ +/* line 535, ../../sass/screen.scss */ .window.visible { display: block; } -/* line 500, ../../sass/screen.scss */ +/* line 539, ../../sass/screen.scss */ .window .window-bg { background: #000; opacity: 0.7; @@ -579,7 +619,7 @@ div.as-results ul li.as-message { top: 0; z-index: -1; } -/* line 511, ../../sass/screen.scss */ +/* line 550, ../../sass/screen.scss */ .window .window-content { position: relative; margin: 0 auto; @@ -593,18 +633,49 @@ div.as-results ul li.as-message { max-height: 100%; overflow: auto; } +/* line 565, ../../sass/screen.scss */ +.window .window-closer { + position: absolute; + top: 0; + right: 0; + padding: 12px; + z-index: 3; +} +/* line 571, ../../sass/screen.scss */ +.window .window-closer:after { + content: "×"; +} -/* line 528, ../../sass/screen.scss */ +/* line 578, ../../sass/screen.scss */ .lieu-ui .map { height: 400px; width: 100%; } -/* line 532, ../../sass/screen.scss */ +/* line 582, ../../sass/screen.scss */ .lieu-ui .hidden { display: none; } -/* line 537, ../../sass/screen.scss */ +/* line 587, ../../sass/screen.scss */ #avis_lieu_vide { display: none; } + +/* line 591, ../../sass/screen.scss */ +a.lieu-change { + color: #fff; + background: #28BF8A; + overflow: hidden; + display: inline-block; + max-width: 250px; + text-overflow: ellipsis; + white-space: nowrap; + padding: 5px; + border-radius: 5px; + margin-right: 7px; +} +/* line 603, ../../sass/screen.scss */ +a.lieu-change.ajout:before { + content: "+"; + margin-right: 5px; +} diff --git a/avisstage/static/js/select_lieu.js b/avisstage/static/js/select_lieu.js index 7cd6962..3ebbb36 100644 --- a/avisstage/static/js/select_lieu.js +++ b/avisstage/static/js/select_lieu.js @@ -7,12 +7,16 @@ function SelectLieuWidget(STATIC_ROOT, API_LIEU, target, callback) { var ui_ready = false; var lieux_db = {}; var message_el = $el.find(".lieu-message"); + var closer = $el.find(".window-closer"); form_el.detach(); form_el.on("submit", nouveauLieu); function initUI(){ $.each(ui_el.children(), function(i, item){$(item).remove();}); + + closer.on("click", closeWidget).attr("href", "javascript:void(0);"); + $el.find(".window-bg").on("click", closeWidget); var map_el = $("
", {class: "map"}); input = $("", @@ -37,6 +41,12 @@ function SelectLieuWidget(STATIC_ROOT, API_LIEU, target, callback) { map.panTo(lieu.coord); lieuSurCarte(lieu, greenIcon); } + + function handleLieuOrigine(data) { + lieux_db[data.id] = data; + setLieuOrigine(data); + askForSuggestions(data.coord); + } this.showWidget = function(lieu_id) { $el.addClass("visible").removeClass("ajout"); @@ -51,21 +61,20 @@ function SelectLieuWidget(STATIC_ROOT, API_LIEU, target, callback) { $el.find("h3").text("Modifier le lieu"); if(lieux_db[lieu_id] === undefined) { $.getJSON(API_LIEU + lieu_id + "/?format=json", - function(data) { - lieux_db[data.id] = data; - setLieuOrigine(data); - askForSuggestions(data.coord); - }); + handleLieuOrigine); ui_el.addClass("hidden"); } else { - setLieuOrigine(lieux_db[lieu_id]); + handleLieuOrigine(lieux_db[lieu_id]); } } } - this.closeWidget = function() { + function closeWidget () { $el.removeClass("visible"); } + + this.closeWidget = closeWidget; + // Icones function makeIcon(couleur){ diff --git a/avisstage/templates/avisstage/detail/stage.html b/avisstage/templates/avisstage/detail/stage.html index 2662da7..66fdd57 100644 --- a/avisstage/templates/avisstage/detail/stage.html +++ b/avisstage/templates/avisstage/detail/stage.html @@ -3,15 +3,53 @@ {% block extra_head %} + + + {% endblock %} {% block content %}

{{ object.sujet }}

{% if object.auteur == user.profil %} -

Modifier ce stage

+
+

Modifier ce stage

+
+ {% csrf_token %} + {% if object.public %} +

Ce stage est visible publiquement.

+ {% else %} +

Ce stage n'est qu'un brouillon, vous seul pouvez le voir.

+ {% endif %} +
+
{% endif %}
@@ -21,7 +59,25 @@

À propos du stage

-

{{ object.auteur.nom }} a fait ce stage du {{ object.date_debut }} au {{ object.date_fin }}, supervisé par {{ object.encadrants }}

+ {% if object.lieux %} +
+ + {% endif %} +

{{ object.auteur.nom }} a fait ce {{ object.get_type_stage_display|lower }} du {{ object.date_debut }} au {{ object.date_fin }}, supervisé par {{ object.encadrants }}

    {% for matiere in object.matieres.all %}
  • {{ matiere.nom }}
  • @@ -35,7 +91,7 @@ {% include "avisstage/detail/avis.html" with avis=object.avis_stage titre="Avis sur le stage" %} {% for avis in object.avislieu_set.all %} - {% include "avisstage/detail/avis.html" with avis=avis titre="Avis sur le lieu" %} + {% include "avisstage/detail/avis.html" with avis=avis titre=avis.lieu %} {% endfor %}
diff --git a/avisstage/templates/avisstage/formulaires/lieu_raw.html b/avisstage/templates/avisstage/formulaires/lieu_raw.html index 8753fb1..64255c4 100644 --- a/avisstage/templates/avisstage/formulaires/lieu_raw.html +++ b/avisstage/templates/avisstage/formulaires/lieu_raw.html @@ -1,16 +1,7 @@ {% load staticfiles %} -

Ajouter un lieu

-
+ +

Ajouter un lieu

{% csrf_token %} - - {% block extra_head %} - - - - - - {% endblock %} -

@@ -28,140 +19,4 @@
{% endfor %} - diff --git a/avisstage/templates/avisstage/formulaires/stage.html b/avisstage/templates/avisstage/formulaires/stage.html index 825f3c3..985c41f 100644 --- a/avisstage/templates/avisstage/formulaires/stage.html +++ b/avisstage/templates/avisstage/formulaires/stage.html @@ -122,6 +122,7 @@ lieu_select.closeWidget(); } + // À l'envoi du formulaire $("#stageform").submit(function() { $.each(txtr, function(i, item) { @@ -144,50 +145,55 @@
{% csrf_token %} {# Général #} -

Informations générales

- {{ form.non_field_errors }} - {% for field in form %} - {{ field.errors }} -
- -
- {{ field }} - {% if field.help_text %} -

{{ field.help_text }}

- {% endif %} -
-
- {% endfor %} - {# Lieux #} -
- -
-
- {% for fform in avis_lieu_formset %} - {{ fform.instance.lieu }} - {% endfor %} - Ajouter un lieu -
-
-
- - {# Avis - général #} -

Commentaires sur le stage

- {{ avis_stage_form.non_field_errors }} - {% for field in avis_stage_form %} - {{ field.errors }} -
-
+
+

Informations générales

+ {{ form.non_field_errors }} + {% for field in form %} + {{ field.errors }} +
- {% if field.help_text %} -

{{ field.help_text }}

- {% endif %} +
+ {{ field }} + {% if field.help_text %} +

{{ field.help_text }}

+ {% endif %} +
+ {% endfor %} + {# Lieux #} +
+
- {{ field }} +
+ {% for fform in avis_lieu_formset %} + {{ fform.instance.lieu }} + {% endfor %} + Ajouter un lieu +
- {% endfor %} + +
+
+ {# Avis - général #} +

Commentaires sur le stage

+ {{ avis_stage_form.non_field_errors }} + {% for field in avis_stage_form %} + {{ field.errors }} +
+
+ + {% if field.help_text %} +

{{ field.help_text }}

+ {% endif %} +
+
+ {{ field }} +
+
+ {% endfor %} + +
{{ avis_lieu_formset.management_form }}
{% for fform in avis_lieu_formset %} @@ -195,6 +201,7 @@

Commentaire sur le lieu "{{ fform.instance.lieu }}"

{{ fform.non_field_errors }} {% for field in fform.hidden_fields %} + {{ field.errors }} {{ field }} {% endfor %} {% for field in fform.visible_fields %} diff --git a/avisstage/templates/avisstage/perso.html b/avisstage/templates/avisstage/perso.html index 960ce31..1df92b4 100644 --- a/avisstage/templates/avisstage/perso.html +++ b/avisstage/templates/avisstage/perso.html @@ -9,7 +9,7 @@

Mes stages

    {% for stage in user.profil.stages.all %} -
  • +
  • {{ stage.sujet }} diff --git a/avisstage/urls.py b/avisstage/urls.py index b77e93d..bf4aafa 100644 --- a/avisstage/urls.py +++ b/avisstage/urls.py @@ -10,7 +10,8 @@ urlpatterns = [ url(r'^perso/$', views.perso, name='perso'), url(r'^stage/nouveau/$', views.manage_stage, name='stage_ajout'), url(r'^stage/(?P\w+)/$', views.StageView.as_view(), name='stage'), - url(r'^stage/(?P\w+)/edit/$', views.manage_stage, name='stage_edit'), + url(r'^stage/(?P\w+)/edit/$', views.manage_stage, name='stage_edit'), + url(r'^stage/(?P\w+)/publication/$', views.publier_stage, name='stage_publication'), url(r'^lieu/ajout/$', views.LieuAjout.as_view(), name='lieu_ajout'), url(r'^profil/show/(?P\w+)/$', views.ProfilView.as_view(), diff --git a/avisstage/views.py b/avisstage/views.py index f0686b2..3d65f8d 100644 --- a/avisstage/views.py +++ b/avisstage/views.py @@ -1,6 +1,6 @@ # coding: utf-8 -from django.shortcuts import render, redirect +from django.shortcuts import render, redirect, get_object_or_404 from django.views.generic import DetailView from django.views.generic.edit import UpdateView, CreateView @@ -8,7 +8,7 @@ from django import forms from django.urls import reverse from django.contrib.auth.decorators import login_required from braces.views import LoginRequiredMixin -from django.http import JsonResponse +from django.http import JsonResponse, HttpResponseForbidden from avisstage.models import Normalien, Stage, Lieu, AvisLieu, AvisStage from avisstage.forms import StageForm, LieuForm, AvisStageForm, AvisLieuForm @@ -47,13 +47,13 @@ class ProfilView(DetailView, LoginRequiredMixin): # Stages @login_required -def manage_stage(request, id_stage=None): - if id_stage is None: +def manage_stage(request, pk=None): + if pk is None: stage = Stage(auteur=request.user.profil) avis_stage = AvisStage(stage=stage) c_del = False else: - stage = Stage.objects.filter(auteur=request.user.profil).get(pk=id_stage) + stage = Stage.objects.filter(auteur=request.user.profil).get(pk=pk) avis_stage, _ = AvisStage.objects.get_or_create(stage=stage) c_del = True @@ -82,7 +82,7 @@ def manage_stage(request, id_stage=None): return render(request, "avisstage/formulaires/stage.html", {'form': form, 'avis_stage_form': avis_stage_form, 'avis_lieu_formset': avis_lieu_formset, - 'creation': id_stage is None}) + 'creation': pk is None}) class StageView(DetailView, LoginRequiredMixin): model = Stage @@ -109,7 +109,20 @@ class LieuAjout(CreateView, LoginRequiredMixin): "errors": form.errors}) else: super(LieuAjout, self).form_valid(form) - + +@login_required +def publier_stage(request, pk): + if request.method != "POST": + return HttpResponseForbidden() + stage = get_object_or_404(Stage, pk=pk) + if stage.auteur != request.user.profil: + return HttpResponseForbidden() + if "publier" in request.POST: + stage.public = True + else: + stage.public = False + stage.save() + return redirect(reverse("avisstage:stage", kwargs={"pk": pk})) def recherche(request): return render(request, 'avisstage/recherche.html')