mirror of https://gitlab.crans.org/bde/nk20
fix sign up forms
This commit is contained in:
parent
633663f95d
commit
4a52272558
|
@ -12,3 +12,4 @@ class ProfileForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Profile
|
model = Profile
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
exclude = ['user']
|
||||||
|
|
|
@ -138,11 +138,11 @@ class Membership(models.Model):
|
||||||
verbose_name_plural = _('memberships')
|
verbose_name_plural = _('memberships')
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=settings.AUTH_USER_MODEL)
|
# @receiver(post_save, sender=settings.AUTH_USER_MODEL)
|
||||||
def save_user_profile(instance, created, **_kwargs):
|
# def save_user_profile(instance, created, **_kwargs):
|
||||||
"""
|
# """
|
||||||
Hook to save an user profile when an user is updated
|
# Hook to save an user profile when an user is updated
|
||||||
"""
|
# """
|
||||||
if created:
|
# if created:
|
||||||
Profile.objects.create(user=instance)
|
# Profile.objects.create(user=instance)
|
||||||
instance.profile.save()
|
# instance.profile.save()
|
||||||
|
|
|
@ -4,12 +4,3 @@
|
||||||
# Copyright (C) 2018-2019 by BDE ENS Paris-Saclay
|
# Copyright (C) 2018-2019 by BDE ENS Paris-Saclay
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# 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()
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.views.generic.edit import CreateView
|
from django.views.generic.edit import CreateView
|
||||||
|
from django.http import HttpResponseRedirect
|
||||||
from django.contrib.auth.forms import UserCreationForm
|
from django.contrib.auth.forms import UserCreationForm
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
from .models import Profile
|
from .models import Profile
|
||||||
|
@ -27,3 +27,12 @@ class SignUp(CreateView):
|
||||||
context["user_form"] = self.second_form
|
context["user_form"] = self.second_form
|
||||||
|
|
||||||
return context
|
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)
|
||||||
|
|
|
@ -7,8 +7,8 @@
|
||||||
<h2>Sign up</h2>
|
<h2>Sign up</h2>
|
||||||
<form method="post">
|
<form method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{{ form.as_p |crispy }}
|
{{ user_form|crispy }}
|
||||||
{{ user_form.as_p |crispy }}
|
{{ form|crispy }}
|
||||||
<button type="submit">Sign up</button>
|
<button type="submit">Sign up</button>
|
||||||
</form>
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Loading…
Reference in New Issue