experiENS/avisstage/views.py

93 lines
2.7 KiB
Python
Raw Normal View History

# coding: utf-8
2017-04-04 00:31:50 +02:00
from django.shortcuts import render
2017-04-07 03:01:27 +02:00
from django.views.generic import DetailView
from django.views.generic.edit import UpdateView, CreateView
from django import forms
from django.urls import reverse
from django.contrib.auth.decorators import login_required
from braces.views import LoginRequiredMixin
from avisstage.models import Normalien, Stage, Lieu, AvisLieu, AvisStage
from avisstage.forms import StageForm, LieuForm, AvisStageForm, AvisLieuForm
2017-04-07 03:01:27 +02:00
# Page d'accueil
2017-04-05 00:23:35 +02:00
def index(request):
return render(request, 'avisstage/index.html')
2017-04-07 03:01:27 +02:00
# Espace personnel
@login_required
2017-04-05 00:23:35 +02:00
def perso(request):
return render(request, 'avisstage/perso.html')
2017-04-07 03:01:27 +02:00
# Profil
class ProfilEdit(UpdateView, LoginRequiredMixin):
model = Normalien
fields = ['nom', 'promotion', 'mail']
template_name = 'avisstage/formulaires/profil.html'
def get_object(self):
return self.request.user.profil
def get_context_data(self, **kwargs):
print kwargs
return super(ProfilEdit, self).get_context_data(**kwargs)
def get_success_url(self):
return reverse('avisstage:perso')
class ProfilView(DetailView, LoginRequiredMixin):
model = Normalien
template_name = 'avisstage/detail/profil.html'
def get_object(self):
return Normalien.objects.get(user__username=self.kwargs.get('username'))
# Stages
class StageAjout(CreateView, LoginRequiredMixin):
model = Stage
form_class = StageForm
template_name = 'avisstage/formulaires/stage.html'
def get_form_kwargs(self):
kwargs = super(StageAjout, self).get_form_kwargs()
kwargs.update({'request': self.request})
return kwargs
2017-04-05 00:23:35 +02:00
class StageEdit(UpdateView, LoginRequiredMixin):
model = Stage
form_class = StageForm
template_name = 'avisstage/formulaires/stage.html'
def get_queryset(self):
# Autorise les modifications des seuls stages qu'on "possède"
queryset = super(StageEdit, self).get_queryset()
return queryset.filter(auteur=self.request.user.profil)
def get_form_kwargs(self):
kwargs = super(StageEdit, self).get_form_kwargs()
kwargs.update({'request': self.request})
return kwargs
def get_success_url(self):
return reverse('avisstage:stage', self.instance.id)
2017-04-07 03:01:27 +02:00
class StageView(DetailView, LoginRequiredMixin):
model = Stage
template_name = 'avisstage/detail/stage.html'
# Lieux des stages
class LieuAjout(CreateView, LoginRequiredMixin):
model = Lieu
form_class = LieuForm
template_name = 'avisstage/formulaires/lieu.html'
2017-04-05 00:23:35 +02:00
def recherche(request):
return render(request, 'avisstage/recherche.html')
def feedback(request):
return render(request, 'avisstage/feedback.html')