From 692b64ee84f3a08db44752ac66ccff06c10c0dd7 Mon Sep 17 00:00:00 2001 From: champeno Date: Fri, 12 Jun 2015 20:17:24 +0200 Subject: [PATCH] =?UTF-8?q?D=C3=A9but=20de=20l'interface=20d'ajout=20de=20?= =?UTF-8?q?stages?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- experiENS/settings.py | 2 +- experiENS/urls.py | 7 +- .../migrations/0002_auto_20150612_2003.py | 41 ++++++++++ monstage/models.py | 5 +- monstage/templates/monstage/index.html | 15 ++++ monstage/templates/monstage/profil.html | 19 +++++ monstage/templates/monstage/profil_edit.html | 14 ++++ monstage/templates/monstage/stage.html | 9 +++ monstage/templates/monstage/stage_add.html | 12 +++ .../templates/monstage/stage_edit_lieu.html | 12 +++ monstage/templates/skeleton.html | 10 +++ monstage/urls.py | 13 ++++ monstage/views.py | 78 ++++++++++++++++++- 13 files changed, 228 insertions(+), 9 deletions(-) create mode 100644 monstage/migrations/0002_auto_20150612_2003.py create mode 100644 monstage/templates/monstage/index.html create mode 100644 monstage/templates/monstage/profil.html create mode 100644 monstage/templates/monstage/profil_edit.html create mode 100644 monstage/templates/monstage/stage.html create mode 100644 monstage/templates/monstage/stage_add.html create mode 100644 monstage/templates/monstage/stage_edit_lieu.html create mode 100644 monstage/templates/skeleton.html create mode 100644 monstage/urls.py diff --git a/experiENS/settings.py b/experiENS/settings.py index 36d4f55..993c1f6 100644 --- a/experiENS/settings.py +++ b/experiENS/settings.py @@ -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' diff --git a/experiENS/urls.py b/experiENS/urls.py index 078fad9..293cd8a 100644 --- a/experiENS/urls.py +++ b/experiENS/urls.py @@ -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")), ) diff --git a/monstage/migrations/0002_auto_20150612_2003.py b/monstage/migrations/0002_auto_20150612_2003.py new file mode 100644 index 0000000..284a57c --- /dev/null +++ b/monstage/migrations/0002_auto_20150612_2003.py @@ -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, + ), + ] diff --git a/monstage/models.py b/monstage/models.py index cb41fca..3c6de2b 100644 --- a/monstage/models.py +++ b/monstage/models.py @@ -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" diff --git a/monstage/templates/monstage/index.html b/monstage/templates/monstage/index.html new file mode 100644 index 0000000..d0a4173 --- /dev/null +++ b/monstage/templates/monstage/index.html @@ -0,0 +1,15 @@ +{% extends "skeleton.html" %} + +{% block content %} +

Bonjour {{ user.first_name }} !

+

Modifier mon profil

+

Mes stages

+ + +{% endblock %} + diff --git a/monstage/templates/monstage/profil.html b/monstage/templates/monstage/profil.html new file mode 100644 index 0000000..9a91e33 --- /dev/null +++ b/monstage/templates/monstage/profil.html @@ -0,0 +1,19 @@ +{% extends "skeleton.html" %} + +{% block content %} +

Profil de {{ profil.user.username }}

+

Retour

+

Prénom : {{ profil.user.first_name }}

+

Nom : {{ profil.user.last_name }}

+

Ses stages

+ {% if stages %} + + {% else %} +

Aucun stage pour le moment

+ {% endif %} +{% endblock %} + diff --git a/monstage/templates/monstage/profil_edit.html b/monstage/templates/monstage/profil_edit.html new file mode 100644 index 0000000..fb0ffe3 --- /dev/null +++ b/monstage/templates/monstage/profil_edit.html @@ -0,0 +1,14 @@ +{% extends "skeleton.html" %} + +{% block content %} +

Modifier son profil

+

Retour

+
+ {% csrf_token %} +
+
+ +
+ +{% endblock %} + diff --git a/monstage/templates/monstage/stage.html b/monstage/templates/monstage/stage.html new file mode 100644 index 0000000..56dba48 --- /dev/null +++ b/monstage/templates/monstage/stage.html @@ -0,0 +1,9 @@ +{% extends "skeleton.html" %} + +{% block content %} +

{{ stage.sujet }}

+

Retour

+

Stage de {{ stage.profil_user.user.first_name }} {{ stage.profil_user.user.last_name }}

+

Du {{ stage.start_date }} au {{ stage.end_date }}

+{% endblock %} + diff --git a/monstage/templates/monstage/stage_add.html b/monstage/templates/monstage/stage_add.html new file mode 100644 index 0000000..b426e31 --- /dev/null +++ b/monstage/templates/monstage/stage_add.html @@ -0,0 +1,12 @@ +{% extends "skeleton.html" %} + +{% block content %} +

Ajouter un stage

+

Retour

+
+ {% csrf_token %} + {{ form.as_p }} + +
+{% endblock %} + diff --git a/monstage/templates/monstage/stage_edit_lieu.html b/monstage/templates/monstage/stage_edit_lieu.html new file mode 100644 index 0000000..74b379a --- /dev/null +++ b/monstage/templates/monstage/stage_edit_lieu.html @@ -0,0 +1,12 @@ +{% extends "skeleton.html" %} + +{% block content %} +

Lieux du stage "{{ stage.sujet }}"

+

Retour

+
+ {% csrf_token %} + {{ form.as_p }} + +
+{% endblock %} + diff --git a/monstage/templates/skeleton.html b/monstage/templates/skeleton.html new file mode 100644 index 0000000..bf5c08d --- /dev/null +++ b/monstage/templates/skeleton.html @@ -0,0 +1,10 @@ + + + + ExperiENS + + + + {% block content %}{% endblock %} + + \ No newline at end of file diff --git a/monstage/urls.py b/monstage/urls.py new file mode 100644 index 0000000..47d8069 --- /dev/null +++ b/monstage/urls.py @@ -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\w+)/$', views.profil, name='profil'), + url(r'^profil/edit/$', views.profil_edit, name='profil_edit'), + url(r'^stage/(?P\d+)/$', views.stage, name='stage'), + url(r'^stage/new/$', views.stage_add, name='stage_add'), + url(r'^stage/(?P\d+)/edit/$', views.stage_edit, name='stage_edit'), + url(r'^stage/(?P\d+)/edit/lieu/$', views.stage_edit_lieu, name='stage_edit_lieu'), +) \ No newline at end of file diff --git a/monstage/views.py b/monstage/views.py index 91ea44a..fc75f89 100644 --- a/monstage/views.py +++ b/monstage/views.py @@ -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}) \ No newline at end of file