diff --git a/apps/member/forms.py b/apps/member/forms.py index 92c98996..748e7d09 100644 --- a/apps/member/forms.py +++ b/apps/member/forms.py @@ -12,3 +12,4 @@ class ProfileForm(forms.ModelForm): class Meta: model = Profile fields = '__all__' + exclude = ['user'] diff --git a/apps/member/models.py b/apps/member/models.py index dbe0ad07..87c5582b 100644 --- a/apps/member/models.py +++ b/apps/member/models.py @@ -138,11 +138,11 @@ class Membership(models.Model): verbose_name_plural = _('memberships') -@receiver(post_save, sender=settings.AUTH_USER_MODEL) -def save_user_profile(instance, created, **_kwargs): - """ - Hook to save an user profile when an user is updated - """ - if created: - Profile.objects.create(user=instance) - instance.profile.save() +# @receiver(post_save, sender=settings.AUTH_USER_MODEL) +# def save_user_profile(instance, created, **_kwargs): +# """ +# Hook to save an user profile when an user is updated +# """ +# if created: +# Profile.objects.create(user=instance) +# instance.profile.save() diff --git a/apps/member/signals.py b/apps/member/signals.py index 51751100..6688516b 100644 --- a/apps/member/signals.py +++ b/apps/member/signals.py @@ -4,12 +4,3 @@ # Copyright (C) 2018-2019 by BDE ENS Paris-Saclay # SPDX-License-Identifier: GPL-3.0-or-later - -def save_user_profile(instance, created, **_kwargs): - """ - Hook to create and save a note when an user is updated - """ - if created: - from .models import Profile - Profile.objects.create(user=instance) - instance.note.save() diff --git a/apps/member/views.py b/apps/member/views.py index 2d080d0a..cc2d2b3f 100644 --- a/apps/member/views.py +++ b/apps/member/views.py @@ -6,7 +6,7 @@ from django.contrib.auth.mixins import LoginRequiredMixin from django.utils.translation import gettext_lazy as _ from django.views.generic.edit import CreateView - +from django.http import HttpResponseRedirect from django.contrib.auth.forms import UserCreationForm from django.urls import reverse_lazy from .models import Profile @@ -27,3 +27,12 @@ class SignUp(CreateView): context["user_form"] = self.second_form return context + + def form_valid(self, form): + user_form = UserCreationForm(self.request.POST) + if user_form.is_valid(): + user = user_form.save() + user_profile = form.save(commit=False) # do not save to db + user_profile.user = user + user_profile.save() + return super().form_valid(form) diff --git a/templates/member/signup.html b/templates/member/signup.html index 1021b8c0..67a85674 100644 --- a/templates/member/signup.html +++ b/templates/member/signup.html @@ -7,8 +7,8 @@