diff --git a/monstage/static/style.css b/monstage/static/style.css index a72aa93..5208891 100644 --- a/monstage/static/style.css +++ b/monstage/static/style.css @@ -61,24 +61,6 @@ header ul { background:#eee; } -#stage_present { - display:table; - background: #fff; - border-spacing:20px; - width:100%; -} - -#stage_misc { - display:table-cell; - min-width:300px; -} - -#stage_map { - display:table-cell; - min-width:300px; -} - - /* formulaires */ label { font-weight:bold; @@ -178,4 +160,39 @@ div#candidats li input { div#candidats #addcandidat { font-size:20px; +} + +/* stages */ +#stage_present { + display:table; + background: #fff; + border-spacing:20px; + width:100%; +} + +#stage_misc { + display:table-cell; + min-width:300px; +} + +#stage_map { + display:table-cell; + min-width:300px; +} + +#stage_published.published { + background:#9f9; +} + +#stage_published.unpublished { + background:#f99; +} + +#stage_published input { + display:inline; + margin:0; +} + +#stage_published p { + background:none; } \ No newline at end of file diff --git a/monstage/templates/monstage/forbidden.html b/monstage/templates/monstage/forbidden.html new file mode 100644 index 0000000..1278970 --- /dev/null +++ b/monstage/templates/monstage/forbidden.html @@ -0,0 +1,14 @@ +{% extends "skeleton.html" %} +{% load staticfiles %} + +{% block extra_head %} + +{% endblock %} + +{% block content %} +

Accès interdit

+ {% if unpublished %}

Le stage n'est pas encore publié

+ {% elif notowned %}

Ce stage ne vous appartient pas, vous ne pouvez pas le modifier

+ {% else %}

L'accès à ce contenu est interdit

+{% endblock %} + diff --git a/monstage/templates/monstage/home.html b/monstage/templates/monstage/home.html index d0a4173..0b2391b 100644 --- a/monstage/templates/monstage/home.html +++ b/monstage/templates/monstage/home.html @@ -6,7 +6,7 @@

Mes stages

diff --git a/monstage/templates/monstage/profil_edit.html b/monstage/templates/monstage/profil_edit.html index fb0ffe3..3e78c1e 100644 --- a/monstage/templates/monstage/profil_edit.html +++ b/monstage/templates/monstage/profil_edit.html @@ -2,7 +2,7 @@ {% block content %}

Modifier son profil

-

Retour

+

Retour

{% csrf_token %}
diff --git a/monstage/templates/monstage/stage.html b/monstage/templates/monstage/stage.html index 1d30d0b..da27c4a 100644 --- a/monstage/templates/monstage/stage.html +++ b/monstage/templates/monstage/stage.html @@ -25,7 +25,20 @@ {% endblock %} {% block content %} -

Retour

+

Retour

+ {% if modifiable %} + + {% csrf_token %} +
+ + {% if published %} +

Ce stage est publié et visible des autres utilisateurs

+ {% else %} +

Ce stage est un brouillon invisible des autres utilisateurs

+ {% endif %} +
+
+ {% endif %}

{{ stage.sujet }}

diff --git a/monstage/urls.py b/monstage/urls.py index 4a6126d..cbfd73f 100644 --- a/monstage/urls.py +++ b/monstage/urls.py @@ -13,5 +13,6 @@ urlpatterns = patterns('', 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'), + url(r'^stage/(?P\d+)/edit/publish/$', views.stage_publish, name='stage_publish'), url(r'^recherche/$', views.search, name='search'), ) \ No newline at end of file diff --git a/monstage/views.py b/monstage/views.py index 4be5aa4..cabbc8f 100644 --- a/monstage/views.py +++ b/monstage/views.py @@ -19,6 +19,11 @@ def index(request): stats = { 'num_stages': Stage.objects.count() } return render(request, 'monstage/index.html', {'stats': stats}) +def forbidden(request, type): + context = {} + context[type] = True + return render(request, 'monstage/forbidden.html', context) + @login_required def home(request): stages = request.user.profil.stages.all() @@ -53,13 +58,16 @@ def profil_edit(request): def stage(request, stage_id): stage = get_object_or_404( Stage, pk = stage_id) lieux_latlng = [] + if not stage.published and not stage.profil_user == request.user.profil: + return forbidden(request, 'unpublished') for lieu in stage.lieux.all(): # GEOS Format : (longitude, latitude) lieux_latlng.append("%f, %f" % (lieu.coord.y, lieu.coord.x)) context = { 'stage': stage, 'modifiable': (stage.profil_user == request.user.profil), - 'lieux_latlng': lieux_latlng + 'lieux_latlng': lieux_latlng, + 'published':stage.published, } return render(request, 'monstage/stage.html', context) @@ -86,7 +94,7 @@ def stage_add(request): 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") + return forbidden(request, 'notowned') bullshit = "" if request.POST: form = StageForm(request.POST, instance = stage) @@ -150,7 +158,7 @@ def stage_edit_lieu(request, stage_id): stage = get_object_or_404( Stage, pk = stage_id) bullshit = '' if stage.profil_user != request.user.profil: - return HttpResponseForbidden("Ce stage ne vous appartient pas") + return forbidden(request, 'notowned') if request.POST: valid = True prevLieuxStage = [k for k in stage.lieustage_set.all()] @@ -222,7 +230,7 @@ class LieuStageFeedbackForm(forms.ModelForm): def stage_edit_feedback(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") + return forbidden(request, 'notowned') 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()] @@ -240,6 +248,18 @@ def stage_edit_feedback(request, stage_id): 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_publish(request, stage_id): + stage = get_object_or_404( Stage, pk = stage_id) + if request.POST: + publishit = request.POST.get('publishit', False) + if publishit == "yes": + stage.published = True + stage.save() + elif publishit == "no": + stage.published = False + stage.save() + return HttpResponseRedirect(reverse('monstage:stage', args=(stage_id,))) + def detail(request, question_id): question = get_object_or_404(Question, pk=question_id) return render(request, 'monstage/detail.html', {'question': question})