Début de l'interface d'ajout de stages

This commit is contained in:
champeno 2015-06-12 20:17:24 +02:00
parent 45a009d9d5
commit 692b64ee84
13 changed files with 228 additions and 9 deletions

View file

@ -79,7 +79,7 @@ DATABASES = {
# Internationalization
# https://docs.djangoproject.com/en/1.7/topics/i18n/
LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = 'fr-fr'
TIME_ZONE = 'UTC'

View file

@ -2,9 +2,8 @@ from django.conf.urls import patterns, include, url
from django.contrib import admin
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'experiENS.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^accounts/login/$', 'django_cas_ng.views.login', name = "cas_login_view"),
url(r'^accounts/logout/$', 'django_cas_ng.views.logout'),
url(r'^', include('monstage.urls', namespace="monstage")),
)

View file

@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('monstage', '0001_initial'),
]
operations = [
migrations.AlterModelOptions(
name='lieu',
options={'verbose_name': 'Lieu', 'verbose_name_plural': 'Lieux'},
),
migrations.AlterModelOptions(
name='lieustage',
options={'verbose_name': 'Avis sur un lieu de stage', 'verbose_name_plural': 'Avis sur un lieu de stage'},
),
migrations.AlterModelOptions(
name='stage',
options={'verbose_name': 'Stage', 'verbose_name_plural': 'Stages'},
),
migrations.RenameField(
model_name='stage',
old_name='user',
new_name='profil_user',
),
migrations.RemoveField(
model_name='stagematiere',
name='users',
),
migrations.AddField(
model_name='stage',
name='matieres',
field=models.ManyToManyField(related_name='stages', to='monstage.StageMatiere'),
preserve_default=True,
),
]

View file

@ -66,7 +66,7 @@ class StageMatiere(models.Model):
return self.name
class Stage(models.Model):
user = models.ForeignKey(Normalien, related_name = "stages")
profil_user = models.ForeignKey(Normalien, related_name = "stages")
published = models.BooleanField(_("Visible publiquement"), default = False)
type_stage = models.CharField (_(u"Type"),
default = "stage",
@ -78,6 +78,7 @@ class Stage(models.Model):
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)
@ -86,7 +87,7 @@ class Stage(models.Model):
avis_admin = models.TextField(_(u"Visa et administratif"), blank = True)
def __unicode__(self):
return u"%s : %s" % (self.user.profil.username, self.sujet)
return u"%s : %s" % (self.profil_user.user.username, self.sujet)
class Meta:
verbose_name = "Stage"

View file

@ -0,0 +1,15 @@
{% extends "skeleton.html" %}
{% block content %}
<h1>Bonjour {{ user.first_name }} !</h1>
<p><a href="{% url 'monstage:profil_edit' %}">Modifier mon profil</a></p>
<h2>Mes stages</h2>
<ul>
{% for stage in stages %}
<li><a href="{% url 'monstage:stage' stage.id %}">{{ stage.sujet }}</a></li>
{% endfor %}
<li><a href="{% url 'monstage:stage_add' %}">Ajouter un stage</a></li>
</ul>
{% endblock %}

View file

@ -0,0 +1,19 @@
{% extends "skeleton.html" %}
{% block content %}
<h1>Profil de {{ profil.user.username }}</h1>
<p><a href="{% url 'monstage:index' %}">Retour</a></p>
<p>Prénom : {{ profil.user.first_name }}</p>
<p>Nom : {{ profil.user.last_name }}</p>
<h2>Ses stages</h2>
{% if stages %}
<ul>
{% for stage in stages %}
<li><a href="{% url 'monstage:stage' stage.id %}">{{ stage.sujet }}</a></li>
{% endfor %}
</ul>
{% else %}
<p>Aucun stage pour le moment</p>
{% endif %}
{% endblock %}

View file

@ -0,0 +1,14 @@
{% extends "skeleton.html" %}
{% block content %}
<h1>Modifier son profil</h1>
<p><a href="{% url 'monstage:index' %}">Retour</a></p>
<form action="{% url 'monstage:profil_edit' %}" method="post">
{% 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="last_name">Nom : </label><input type="text" name="last_name" id="last_name" value="{{ user.last_name }}" /> <br/>
<input type="submit" value="Enregistrer" />
</form>
{% endblock %}

View file

@ -0,0 +1,9 @@
{% extends "skeleton.html" %}
{% block content %}
<h1>{{ stage.sujet }}</h1>
<p><a href="{% url 'monstage:index' %}">Retour</a></p>
<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>
{% endblock %}

View file

@ -0,0 +1,12 @@
{% extends "skeleton.html" %}
{% block content %}
<h1>Ajouter un stage</h1>
<p><a href="{% url 'monstage:index' %}">Retour</a></p>
<form action="{% url 'monstage:stage_add' %}" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Etape suivante" />
</form>
{% endblock %}

View file

@ -0,0 +1,12 @@
{% extends "skeleton.html" %}
{% block content %}
<h1>Lieux du stage "{{ stage.sujet }}"</h1>
<p><a href="{% url 'monstage:index' %}">Retour</a></p>
<form action="{% url 'monstage:stage_add' %}" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Etape suivante" />
</form>
{% endblock %}

View file

@ -0,0 +1,10 @@
<!doctype html>
<html>
<head>
<title>ExperiENS</title>
</head>
<body>
{% block content %}{% endblock %}
</body>
</html>

13
monstage/urls.py Normal file
View file

@ -0,0 +1,13 @@
from django.conf.urls import patterns, url
from monstage import views
urlpatterns = patterns('',
url(r'^$', views.index, name='index'),
url(r'^profil/show/(?P<profil_id>\w+)/$', views.profil, name='profil'),
url(r'^profil/edit/$', views.profil_edit, name='profil_edit'),
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/lieu/$', views.stage_edit_lieu, name='stage_edit_lieu'),
)

View file

@ -1,3 +1,77 @@
from django.shortcuts import render
from django.shortcuts import get_object_or_404, render
from django.contrib.auth.decorators import login_required
from django.http import HttpResponseRedirect, HttpResponse, HttpResponseForbidden
from django.core.urlresolvers import reverse
from django import forms
# Create your views here.
from monstage.models import *
@login_required
def index(request):
stages = Stage.objects.filter( profil_user = request.user.profil )
return render(request, 'monstage/index.html', {"stages" : stages})
#
# Utilisateurs et profils
#
def profil(request, profil_id):
user = get_object_or_404( User, username = profil_id )
profil = user.profil
stages = Stage.objects.filter( profil_user = profil )
return render(request, 'monstage/profil.html', {'profil': profil, 'stages': stages})
@login_required
def profil_edit(request):
if request.POST:
user = request.user
user.first_name = request.POST['first_name']
user.last_name = request.POST['last_name']
user.save()
return HttpResponseRedirect(reverse('monstage:profil', args=(request.user.username,)))
else:
(profil, _) = Normalien.objects.get_or_create( user = request.user )
return render(request, 'monstage/profil_edit.html', {'normalien': profil})
#
# Stages
#
def stage(request, stage_id):
stage = get_object_or_404( Stage, pk = stage_id)
return render(request, 'monstage/stage.html', {'stage': stage})
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")
@login_required
def stage_add(request):
if request.POST:
form = StageForm(request.POST)
if form.is_valid:
new_stage = form.save(commit = False)
new_stage.user = request.user.profil
new_stage.save()
return HttpResponseRedirect(reverse('monstage:stage_edit_lieu', args=(new_stage.id,)))
else:
form = StageForm()
return render(request, 'monstage/stage_add.html', { 'form': form })
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")
return render(request, 'monstage/stage_edit_lieu.html', { 'stage': stage })
def stage_edit(request, stage_id):
stage = get_object_or_404( Stage, pk = stage_id)
return render(request, 'monstage/stage.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})