Système de brouillons/publications
This commit is contained in:
parent
0d043cc28c
commit
bdf7702be4
7 changed files with 90 additions and 25 deletions
|
@ -61,24 +61,6 @@ header ul {
|
||||||
background:#eee;
|
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 */
|
/* formulaires */
|
||||||
label {
|
label {
|
||||||
font-weight:bold;
|
font-weight:bold;
|
||||||
|
@ -178,4 +160,39 @@ div#candidats li input {
|
||||||
|
|
||||||
div#candidats #addcandidat {
|
div#candidats #addcandidat {
|
||||||
font-size:20px;
|
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;
|
||||||
}
|
}
|
14
monstage/templates/monstage/forbidden.html
Normal file
14
monstage/templates/monstage/forbidden.html
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
{% extends "skeleton.html" %}
|
||||||
|
{% load staticfiles %}
|
||||||
|
|
||||||
|
{% block extra_head %}
|
||||||
|
<link type="text/css" href="{% static 'index.css' %}" rel="stylesheet" />
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h1>Accès interdit</h1>
|
||||||
|
{% if unpublished %}<p>Le stage n'est pas encore publié</p>
|
||||||
|
{% elif notowned %}<p>Ce stage ne vous appartient pas, vous ne pouvez pas le modifier</p>
|
||||||
|
{% else %}<p>L'accès à ce contenu est interdit</p>
|
||||||
|
{% endblock %}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
<h2>Mes stages</h2>
|
<h2>Mes stages</h2>
|
||||||
<ul>
|
<ul>
|
||||||
{% for stage in stages %}
|
{% for stage in stages %}
|
||||||
<li><a href="{% url 'monstage:stage' stage.id %}">{{ stage.sujet }}</a></li>
|
<li><a href="{% url 'monstage:stage' stage.id %}">{{ stage.sujet }}</a> <span class="published">{{ stage.published|yesno:"(Publié),(Brouillon)" }}</span></li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<li><a href="{% url 'monstage:stage_add' %}">Ajouter un stage</a></li>
|
<li><a href="{% url 'monstage:stage_add' %}">Ajouter un stage</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>Modifier son profil</h1>
|
<h1>Modifier son profil</h1>
|
||||||
<p><a href="{% url 'monstage:index' %}">Retour</a></p>
|
<p><a href="{% url 'monstage:home' %}">Retour</a></p>
|
||||||
<form action="{% url 'monstage:profil_edit' %}" method="post">
|
<form action="{% url 'monstage:profil_edit' %}" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<label for="first_name">Prénom : </label><input type="text" name="first_name" id="first_name" value="{{ user.first_name }}" /> <br/>
|
<label for="first_name">Prénom : </label><input type="text" name="first_name" id="first_name" value="{{ user.first_name }}" /> <br/>
|
||||||
|
|
|
@ -25,7 +25,20 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<p><a href="{% url 'monstage:index' %}">Retour</a></p>
|
<p><a href="{% url 'monstage:home' %}">Retour</a></p>
|
||||||
|
{% if modifiable %}
|
||||||
|
<form action="{% url 'monstage:stage_publish' stage.id %}" method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
<div id="stage_published" class="{{ published|yesno:'published,unpublished' }}">
|
||||||
|
<input type="hidden" name="publishit" value="{{ published|yesno:'no,yes' }}" />
|
||||||
|
{% if published %}
|
||||||
|
<p>Ce stage est publié et visible des autres utilisateurs <input type="submit" value="Masquer" /></p>
|
||||||
|
{% else %}
|
||||||
|
<p>Ce stage est un brouillon invisible des autres utilisateurs <input type="submit" value="Publier" /></p>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
{% endif %}
|
||||||
<h1>{{ stage.sujet }}</h1>
|
<h1>{{ stage.sujet }}</h1>
|
||||||
<div id="stage_present">
|
<div id="stage_present">
|
||||||
<div id="stage_map"></div>
|
<div id="stage_map"></div>
|
||||||
|
|
|
@ -13,5 +13,6 @@ urlpatterns = patterns('',
|
||||||
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/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/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'),
|
url(r'^stage/(?P<stage_id>\d+)/edit/avis/$', views.stage_edit_feedback, name='stage_edit_feedback'),
|
||||||
|
url(r'^stage/(?P<stage_id>\d+)/edit/publish/$', views.stage_publish, name='stage_publish'),
|
||||||
url(r'^recherche/$', views.search, name='search'),
|
url(r'^recherche/$', views.search, name='search'),
|
||||||
)
|
)
|
|
@ -19,6 +19,11 @@ def index(request):
|
||||||
stats = { 'num_stages': Stage.objects.count() }
|
stats = { 'num_stages': Stage.objects.count() }
|
||||||
return render(request, 'monstage/index.html', {'stats': stats})
|
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
|
@login_required
|
||||||
def home(request):
|
def home(request):
|
||||||
stages = request.user.profil.stages.all()
|
stages = request.user.profil.stages.all()
|
||||||
|
@ -53,13 +58,16 @@ def profil_edit(request):
|
||||||
def stage(request, stage_id):
|
def stage(request, stage_id):
|
||||||
stage = get_object_or_404( Stage, pk = stage_id)
|
stage = get_object_or_404( Stage, pk = stage_id)
|
||||||
lieux_latlng = []
|
lieux_latlng = []
|
||||||
|
if not stage.published and not stage.profil_user == request.user.profil:
|
||||||
|
return forbidden(request, 'unpublished')
|
||||||
for lieu in stage.lieux.all():
|
for lieu in stage.lieux.all():
|
||||||
# GEOS Format : (longitude, latitude)
|
# GEOS Format : (longitude, latitude)
|
||||||
lieux_latlng.append("%f, %f" % (lieu.coord.y, lieu.coord.x))
|
lieux_latlng.append("%f, %f" % (lieu.coord.y, lieu.coord.x))
|
||||||
context = {
|
context = {
|
||||||
'stage': stage,
|
'stage': stage,
|
||||||
'modifiable': (stage.profil_user == request.user.profil),
|
'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)
|
return render(request, 'monstage/stage.html', context)
|
||||||
|
|
||||||
|
@ -86,7 +94,7 @@ def stage_add(request):
|
||||||
def stage_edit_desc(request, stage_id):
|
def stage_edit_desc(request, stage_id):
|
||||||
stage = get_object_or_404( Stage, pk = stage_id)
|
stage = get_object_or_404( Stage, pk = stage_id)
|
||||||
if stage.profil_user != request.user.profil:
|
if stage.profil_user != request.user.profil:
|
||||||
return HttpResponseForbidden("Ce stage ne vous appartient pas")
|
return forbidden(request, 'notowned')
|
||||||
bullshit = ""
|
bullshit = ""
|
||||||
if request.POST:
|
if request.POST:
|
||||||
form = StageForm(request.POST, instance = stage)
|
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)
|
stage = get_object_or_404( Stage, pk = stage_id)
|
||||||
bullshit = ''
|
bullshit = ''
|
||||||
if stage.profil_user != request.user.profil:
|
if stage.profil_user != request.user.profil:
|
||||||
return HttpResponseForbidden("Ce stage ne vous appartient pas")
|
return forbidden(request, 'notowned')
|
||||||
if request.POST:
|
if request.POST:
|
||||||
valid = True
|
valid = True
|
||||||
prevLieuxStage = [k for k in stage.lieustage_set.all()]
|
prevLieuxStage = [k for k in stage.lieustage_set.all()]
|
||||||
|
@ -222,7 +230,7 @@ class LieuStageFeedbackForm(forms.ModelForm):
|
||||||
def stage_edit_feedback(request, stage_id):
|
def stage_edit_feedback(request, stage_id):
|
||||||
stage = get_object_or_404( Stage, pk = stage_id)
|
stage = get_object_or_404( Stage, pk = stage_id)
|
||||||
if stage.profil_user != request.user.profil:
|
if stage.profil_user != request.user.profil:
|
||||||
return HttpResponseForbidden("Ce stage ne vous appartient pas")
|
return forbidden(request, 'notowned')
|
||||||
if request.POST:
|
if request.POST:
|
||||||
form_gen = StageFeedbackForm(request.POST, instance = stage, prefix = 'gen')
|
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()]
|
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()]
|
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 })
|
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):
|
def detail(request, question_id):
|
||||||
question = get_object_or_404(Question, pk=question_id)
|
question = get_object_or_404(Question, pk=question_id)
|
||||||
return render(request, 'monstage/detail.html', {'question': question})
|
return render(request, 'monstage/detail.html', {'question': question})
|
||||||
|
|
Loading…
Reference in a new issue