Une interface moche mais complète
This commit is contained in:
parent
2fb603c860
commit
9df6082e16
10 changed files with 110 additions and 33 deletions
|
@ -38,6 +38,7 @@ INSTALLED_APPS = (
|
|||
'django.contrib.staticfiles',
|
||||
'django.contrib.gis',
|
||||
'monstage',
|
||||
'taggit',
|
||||
)
|
||||
|
||||
MIDDLEWARE_CLASSES = (
|
||||
|
|
22
monstage/migrations/0005_stage_thematiques.py
Normal file
22
monstage/migrations/0005_stage_thematiques.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
import taggit.managers
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('taggit', '0001_initial'),
|
||||
('monstage', '0004_auto_20150614_1517'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='stage',
|
||||
name='thematiques',
|
||||
field=taggit.managers.TaggableManager(to='taggit.Tag', through='taggit.TaggedItem', blank=True, help_text='A comma-separated list of tags.', verbose_name='Th\xe9matiques'),
|
||||
preserve_default=True,
|
||||
),
|
||||
]
|
|
@ -6,6 +6,8 @@ from django.utils.translation import ugettext_lazy as _
|
|||
from django.contrib.gis.db import models as geomodels
|
||||
from django_cas_ng.signals import cas_user_authenticated
|
||||
|
||||
from taggit.managers import TaggableManager
|
||||
|
||||
from monstage.listepays import PAYS_CHOICES
|
||||
|
||||
TYPE_STAGE_CHOICES = (
|
||||
|
@ -80,10 +82,10 @@ class Stage(models.Model):
|
|||
start_date = models.DateField(_(u"Date de début"), null = True)
|
||||
end_date = models.DateField(_(u"Date de fin"), null = True)
|
||||
sujet = models.CharField(_(u"Sujet"), max_length = 500)
|
||||
thematiques = TaggableManager(_(u"Thématiques"), blank = True)
|
||||
encadrants = models.CharField(_(u"Encadrants"), max_length = 500, blank = True)
|
||||
lieux = models.ManyToManyField(Lieu, related_name = "stages", through = "LieuStage")
|
||||
matieres = models.ManyToManyField(StageMatiere, related_name = "stages")
|
||||
# TODO : thematiques
|
||||
|
||||
# Avis
|
||||
avis_encadrants = models.TextField(_(u"Avis sur les encadrants"), blank = True)
|
||||
|
|
|
@ -3,8 +3,57 @@
|
|||
{% 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 %}
|
||||
{% if modifiable %}<p><a href="{% url 'monstage:stage_edit_desc' stage.id %}">Modifier la description du stage (sujet, ...)</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>
|
||||
<p>Matières : {% for matiere in stage.matieres.all %}{% if not forloop.first %}, {% endif %}{{ matiere.name }}{% endfor %}</p>
|
||||
<p>Thématiques : {% for tag in stage.thematiques.names %}{% if not forloop.first %}, {% endif %}{{ tag }}{% endfor %}</p>
|
||||
<p>A {% for lieu in stage.lieux.all %}{% if not forloop.first %}{% if forloop.last %} et {% else %}, {% endif %}{% endif %}{{ lieu.name }} ({{ lieu.ville }}){% endfor %}</p>
|
||||
{% if modifiable %}<p><a href="{% url 'monstage:stage_edit_lieu' stage.id %}">Modifier les lieux du stage</a></p>{% endif %}
|
||||
{% if modifiable %}<p><a href="{% url 'monstage:stage_edit_feedback' stage.id %}">Modifier les avis sur le stage</a></p>{% endif %}
|
||||
<h2>Ressenti sur le stage</h2>
|
||||
{% if stage.avis_encadrants %}
|
||||
<h3>Les encadrants</h3>
|
||||
<p>{{ stage.avis_encadrants }}</p>
|
||||
{% endif %}
|
||||
{% if stage.avis_equipe %}
|
||||
<h3>L'équipe</h3>
|
||||
<p>{{ stage.avis_equipe }}</p>
|
||||
{% endif %}
|
||||
{% if stage.avis_stage %}
|
||||
<h3>Le stage en général</h3>
|
||||
<p>{{ stage.avis_stage }}</p>
|
||||
{% endif %}
|
||||
{% if stage.avis_admin %}
|
||||
<h3>L'administratif et le visa</h3>
|
||||
<p>{{ stage.avis_admin }}</p>
|
||||
{% endif %}
|
||||
{% for lieustage in stage.lieustage_set.all %}
|
||||
<h2>La vie à {{ lieustage.lieu.ville }}, {{ lieustage.lieu.get_pays_display }}</h2>
|
||||
{% if lieustage.avis_global %}
|
||||
<h3>Ressenti global du séjour</h3>
|
||||
<p>{{ lieustage.avis_global }}</p>
|
||||
{% endif %}
|
||||
{% if lieustage.avis_lieudevie %}
|
||||
<h3>Mon lieu de vie</h3>
|
||||
<p>{{ lieustage.avis_lieudevie }}</p>
|
||||
{% endif %}
|
||||
{% if lieustage.avis_lieustage %}
|
||||
<h3>Le lieu du stage : {{ lieustage.lieu.name }}</h3>
|
||||
<p>{{ lieustage.avis_lieustage }}</p>
|
||||
{% endif %}
|
||||
{% if lieustage.avis_pratique %}
|
||||
<h3>S'installer / conseils pratiques</h3>
|
||||
<p>{{ lieustage.avis_pratique }}</p>
|
||||
{% endif %}
|
||||
{% if lieustage.avis_visite %}
|
||||
<h3>A voir, à faire aux alentours de {{ lieustage.lieu.ville }}</h3>
|
||||
<p>{{ lieustage.avis_visite }}</p>
|
||||
{% endif %}
|
||||
{% if lieustage.avis_anecdotes %}
|
||||
<h3>Anecdotes</h3>
|
||||
<p>{{ lieustage.avis_anecdotes }}</p>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
{% block content %}
|
||||
<h1>Modifier la description du stage "{{ stage.sujet }}"</h1>
|
||||
<p><a href="{% url 'monstage:stage_edit' stage.id %}">Retour</a></p>
|
||||
<p><a href="{% url 'monstage:stage' stage.id %}">Retour</a></p>
|
||||
<form action="{% url 'monstage:stage_edit_desc' stage.id %}" method="post">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
{% block content %}
|
||||
<h1>Avis sur le stage "{{ stage.sujet }}"</h1>
|
||||
<p><a href="{% url 'monstage:stage_edit' stage.id %}">Retour</a></p>
|
||||
<p><a href="{% url 'monstage:stage' stage.id %}">Retour</a></p>
|
||||
<p>{{ debug }}</p>
|
||||
<form action="{% url 'monstage:stage_edit_feedback' stage.id %}" method="post">
|
||||
{% csrf_token %}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
{% block content %}
|
||||
<h1>Lieux du stage "{{ stage.sujet }}"</h1>
|
||||
<p><a href="{% url 'monstage:stage_edit' stage.id %}">Retour</a></p>
|
||||
<p><a href="{% url 'monstage:stage' stage.id %}">Retour</a></p>
|
||||
<p>{{ debug }}</p>
|
||||
<div id="map_canvas"></div>
|
||||
<input id="geocomplete" type="text" placeholder="Chercher un établissement" />
|
||||
|
|
|
@ -9,7 +9,6 @@ urlpatterns = patterns('',
|
|||
url(r'^api/lieux/candidats/$', views.lieux_candidats, name='lieux_candidats'),
|
||||
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'),
|
||||
|
|
|
@ -54,7 +54,7 @@ def stage(request, stage_id):
|
|||
class StageForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Stage
|
||||
fields = ("type_stage", "start_date", "end_date", "matieres", "sujet", "encadrants")
|
||||
fields = ("type_stage", "start_date", "end_date", "matieres", "sujet", "thematiques", "encadrants")
|
||||
|
||||
@login_required
|
||||
def stage_add(request):
|
||||
|
@ -62,21 +62,28 @@ def stage_add(request):
|
|||
form = StageForm(request.POST)
|
||||
if form.is_valid:
|
||||
new_stage = form.save(commit = False)
|
||||
new_stage.user = request.user.profil
|
||||
new_stage.profil_user = request.user.profil
|
||||
new_stage.save()
|
||||
form.save_m2m()
|
||||
return HttpResponseRedirect(reverse('monstage:stage_edit_lieu', args=(new_stage.id,)))
|
||||
else:
|
||||
form = StageForm()
|
||||
return render(request, 'monstage/stage_add.html', { 'form': form })
|
||||
|
||||
@login_required
|
||||
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 })
|
||||
form = StageForm(request.POST, instance = stage)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
return HttpResponseRedirect(reverse('monstage:stage', args=(stage.id,)))
|
||||
else:
|
||||
form = StageForm(instance = stage)
|
||||
return render(request, 'monstage/stage_edit_desc.html', { 'stage': stage, 'form':form })
|
||||
|
||||
class LieuStageForm(forms.Form):
|
||||
lieu_id = forms.IntegerField(widget = HiddenInput())
|
||||
|
@ -109,7 +116,7 @@ class LieuForm(forms.ModelForm):
|
|||
def save(self, *args, **kwargs):
|
||||
lieu = super(LieuForm, self).save(commit=False, *args, **kwargs)
|
||||
lieu.coord = GEOSGeometry('POINT(%f %f)' % (self.cleaned_data['latitude'], self.cleaned_data['longitude']), srid=4326)
|
||||
return lieu.save(*args, **kwargs)
|
||||
return lieu
|
||||
|
||||
def lieux_candidats(request):
|
||||
if request.GET:
|
||||
|
@ -135,7 +142,8 @@ def stage_edit_lieu(request, stage_id):
|
|||
lieuforms = []
|
||||
deleted = []
|
||||
for i in range(0, int(request.POST['numplaces'])):
|
||||
if request.POST.get('%d-name' % i, False): # Lieu a modifier / créer
|
||||
toSave = False
|
||||
if request.POST.get('%d-name' % i, False): # Lieu à créer
|
||||
bullshit += str(i) + 'a '
|
||||
lieuform = LieuForm(request.POST, prefix = str(i))
|
||||
if not lieuform.is_valid():
|
||||
|
@ -146,12 +154,9 @@ def stage_edit_lieu(request, stage_id):
|
|||
pass
|
||||
else:
|
||||
lieu = lieuform.save()
|
||||
if len(prevLieuxStage) > 0:
|
||||
lieustage = prevLieuxStage.pop(0)
|
||||
lieustage.lieu = lieu
|
||||
lieustage.save()
|
||||
else:
|
||||
LieuStage.objects.create(lieu = lieu, stage = stage)
|
||||
lieu.save()
|
||||
lieuform.save_m2m()
|
||||
toSave = True
|
||||
lieuforms.append(LieuStageForm(initial = {'lieu_id': lieu.id}, prefix = str(i)))
|
||||
elif request.POST.get('%d-lieu_id' % i, False): # Lien vers un lieu déjà existant
|
||||
bullshit += str(i) + 'b '
|
||||
|
@ -167,16 +172,18 @@ def stage_edit_lieu(request, stage_id):
|
|||
else:
|
||||
lieuforms.append(lieuform)
|
||||
lieu = Lieu.objects.get( pk = lieuform.cleaned_data['lieu_id'] )
|
||||
if len(prevLieuxStage) > 0:
|
||||
lieustage = prevLieuxStage.pop(0)
|
||||
lieustage.lieu = lieu
|
||||
lieustage.save()
|
||||
elif len(deleted) > 0:
|
||||
lieustage = deleted.pop(0)
|
||||
lieustage.lieu = lieu
|
||||
lieustage.save()
|
||||
else:
|
||||
LieuStage.objects.create(lieu = lieu, stage = stage)
|
||||
toSave = True
|
||||
if toSave: # Mise à jour des liens lieu - stage
|
||||
if len(prevLieuxStage) > 0:
|
||||
lieustage = prevLieuxStage.pop(0)
|
||||
lieustage.lieu = lieu
|
||||
lieustage.save()
|
||||
elif len(deleted) > 0:
|
||||
lieustage = deleted.pop(0)
|
||||
lieustage.lieu = lieu
|
||||
lieustage.save()
|
||||
else:
|
||||
LieuStage.objects.create(lieu = lieu, stage = stage)
|
||||
if valid:
|
||||
for lieustage in deleted:
|
||||
lieustage.delete()
|
||||
|
@ -218,10 +225,6 @@ 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_edit(request, stage_id):
|
||||
stage = get_object_or_404( Stage, pk = stage_id)
|
||||
return render(request, 'monstage/stage_edit.html', {'stage': stage})
|
||||
|
||||
def detail(request, question_id):
|
||||
question = get_object_or_404(Question, pk=question_id)
|
||||
return render(request, 'monstage/detail.html', {'question': question})
|
|
@ -1,4 +1,5 @@
|
|||
django>=1.7
|
||||
django-cas-ng
|
||||
psycopg2
|
||||
postgis
|
||||
postgis
|
||||
django-taggit
|
Loading…
Reference in a new issue