site_tps/users/views.py
2018-01-31 11:17:31 +01:00

48 lines
1.3 KiB
Python

from django.contrib.auth.models import User, Group
from django.views.generic import CreateView
from django.urls import reverse, reverse_lazy
from django.shortcuts import get_object_or_404
from .models import UserProfile
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)