2018-01-31 09:15:51 +00:00
|
|
|
from django.contrib.auth.models import User, Group
|
2018-01-31 12:01:04 +00:00
|
|
|
from django.views.generic import CreateView, UpdateView
|
2018-01-31 09:15:51 +00:00
|
|
|
from django.urls import reverse, reverse_lazy
|
|
|
|
from django.shortcuts import get_object_or_404
|
2018-01-14 12:19:11 +00:00
|
|
|
|
2018-01-31 10:53:37 +00:00
|
|
|
from .models import UserProfile, SchoolProfile
|
2018-01-31 09:15:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
class CreateUser(CreateView):
|
|
|
|
model = User
|
|
|
|
fields = [
|
|
|
|
'first_name',
|
|
|
|
'last_name',
|
|
|
|
'email',
|
|
|
|
'username',
|
|
|
|
'password',
|
|
|
|
]
|
|
|
|
template_name = 'edit.html'
|
|
|
|
|
|
|
|
def get_success_url(self):
|
|
|
|
return reverse(
|
|
|
|
'users:create-userprofile',
|
|
|
|
kwargs={'pk': self.object.pk}
|
|
|
|
)
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
context['title'] = "Inscription"
|
|
|
|
context['validate'] = "S'inscrire"
|
|
|
|
return context
|
|
|
|
|
|
|
|
|
|
|
|
class CreateUserProfile(CreateView):
|
|
|
|
model = UserProfile
|
|
|
|
fields = ['school']
|
|
|
|
template_name = 'edit.html'
|
|
|
|
|
|
|
|
success_url = reverse_lazy('home')
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
context['title'] = "Choix de l'école"
|
|
|
|
context['validate'] = "Choisir"
|
|
|
|
return context
|
|
|
|
|
|
|
|
def form_valid(self, form):
|
|
|
|
form.instance.user = get_object_or_404(User, pk=self.kwargs['pk'])
|
|
|
|
return super(CreateUserProfile, self).form_valid(form)
|
2018-01-31 10:53:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
class CreateSchool(CreateView):
|
|
|
|
model = Group
|
2018-01-31 12:01:04 +00:00
|
|
|
fields = ['name']
|
2018-01-31 10:53:37 +00:00
|
|
|
template_name = 'edit.html'
|
2018-01-31 12:01:04 +00:00
|
|
|
success_url = reverse_lazy('settings:index')
|
2018-01-31 10:53:37 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
context['title'] = "Création de l'école"
|
|
|
|
context['validate'] = "Créer"
|
|
|
|
return context
|
|
|
|
|
|
|
|
def form_valid(self, form):
|
|
|
|
response = super(CreateSchool, self).form_valid(form)
|
|
|
|
profile = SchoolProfile()
|
|
|
|
profile.group = form.instance
|
|
|
|
profile.save()
|
|
|
|
return response
|
2018-01-31 12:01:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EditSchool(UpdateView):
|
|
|
|
model = Group
|
|
|
|
fields = ['name']
|
|
|
|
template_name = 'edit.html'
|
|
|
|
success_url = reverse_lazy('settings:index')
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
context['title'] = "Édition de l'école"
|
|
|
|
context['validate'] = "Modifier"
|
|
|
|
return context
|