1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2024-12-23 07:52:23 +00:00

add signup view

This commit is contained in:
Pierre-antoine Comby 2019-08-11 16:22:52 +02:00
parent fbc6570eb6
commit 633663f95d
7 changed files with 74 additions and 17 deletions

View File

@ -6,7 +6,7 @@ from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
from .forms import CustomUserChangeForm
from .forms import ProfileForm
from .models import Club, Membership, Profile, Role
@ -22,7 +22,7 @@ class CustomUserAdmin(UserAdmin):
inlines = (ProfileInline,)
list_display = ('username', 'email', 'first_name', 'last_name', 'is_staff')
list_select_related = ('profile',)
form = CustomUserChangeForm
form = ProfileForm
def get_inline_instances(self, request, obj=None):
"""

View File

@ -2,17 +2,13 @@
# Copyright (C) 2018-2019 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
from django.contrib.auth.forms import UserChangeForm
from django.contrib.auth.forms import UserChangeForm, UserCreationForm
from django.contrib.auth.models import User
from django import forms
from .models import Profile
class CustomUserChangeForm(UserChangeForm):
"""
Make first name, last name and email required
in the default Django Auth User model
"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['first_name'].required = True
self.fields['last_name'].required = True
self.fields['email'].required = True
class ProfileForm(forms.ModelForm):
class Meta:
model = Profile
fields = '__all__'

15
apps/member/signals.py Normal file
View File

@ -0,0 +1,15 @@
#!/usr/bin/env python
# -*- mode: python; coding: utf-8 -*-
# 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()

14
apps/member/urls.py Normal file
View File

@ -0,0 +1,14 @@
#!/usr/bin/env python
# -*- mode: python; coding: utf-8 -*-
# Copyright (C) 2018-2019 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
from django.urls import path
from . import views
app_name = 'member'
urlpatterns = [
path('signup/',views.SignUp.as_view(),name="signup")
]

View File

@ -7,4 +7,23 @@ from django.contrib.auth.mixins import LoginRequiredMixin
from django.utils.translation import gettext_lazy as _
from django.views.generic.edit import CreateView
from .models import
from django.contrib.auth.forms import UserCreationForm
from django.urls import reverse_lazy
from .models import Profile
from .forms import ProfileForm
class SignUp(CreateView):
"""
Une vue pour inscrire un utilisateur et lui créer un profile
"""
form_class = ProfileForm
success_url = reverse_lazy('login')
template_name ='member/signup.html'
second_form = UserCreationForm
def get_context_data(self,**kwargs):
context = super(SignUp,self).get_context_data(**kwargs)
context["user_form"] = self.second_form
return context

View File

@ -16,9 +16,8 @@ urlpatterns = [
# Include Django Contrib and Core routers
# admin/login/ is redirected to the non-admin login page
path('i18n/', include('django.conf.urls.i18n')),
path('accounts/',include('member.urls')),
path('accounts/', include('django.contrib.auth.urls')),
path('accounts/profile/',
RedirectView.as_view(pattern_name='index')),
path('admin/doc/', include('django.contrib.admindocs.urls')),
path('admin/', admin.site.urls),
]

View File

@ -0,0 +1,14 @@
<!-- templates/signup.html -->
{% extends 'base.html' %}
{% load crispy_forms_tags %}
{% block title %}Sign Up{% endblock %}
{% block content %}
<h2>Sign up</h2>
<form method="post">
{% csrf_token %}
{{ form.as_p |crispy }}
{{ user_form.as_p |crispy }}
<button type="submit">Sign up</button>
</form>
{% endblock %}