mirror of https://gitlab.crans.org/bde/nk20
add signup view
This commit is contained in:
parent
fbc6570eb6
commit
633663f95d
|
@ -6,7 +6,7 @@ from django.contrib import admin
|
||||||
from django.contrib.auth.admin import UserAdmin
|
from django.contrib.auth.admin import UserAdmin
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
from .forms import CustomUserChangeForm
|
from .forms import ProfileForm
|
||||||
from .models import Club, Membership, Profile, Role
|
from .models import Club, Membership, Profile, Role
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ class CustomUserAdmin(UserAdmin):
|
||||||
inlines = (ProfileInline,)
|
inlines = (ProfileInline,)
|
||||||
list_display = ('username', 'email', 'first_name', 'last_name', 'is_staff')
|
list_display = ('username', 'email', 'first_name', 'last_name', 'is_staff')
|
||||||
list_select_related = ('profile',)
|
list_select_related = ('profile',)
|
||||||
form = CustomUserChangeForm
|
form = ProfileForm
|
||||||
|
|
||||||
def get_inline_instances(self, request, obj=None):
|
def get_inline_instances(self, request, obj=None):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -2,17 +2,13 @@
|
||||||
# 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
|
||||||
|
|
||||||
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):
|
class ProfileForm(forms.ModelForm):
|
||||||
"""
|
class Meta:
|
||||||
Make first name, last name and email required
|
model = Profile
|
||||||
in the default Django Auth User model
|
fields = '__all__'
|
||||||
"""
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
|
@ -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()
|
|
@ -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")
|
||||||
|
]
|
|
@ -7,4 +7,23 @@ 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 .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
|
||||||
|
|
|
@ -16,9 +16,8 @@ urlpatterns = [
|
||||||
# Include Django Contrib and Core routers
|
# Include Django Contrib and Core routers
|
||||||
# admin/login/ is redirected to the non-admin login page
|
# admin/login/ is redirected to the non-admin login page
|
||||||
path('i18n/', include('django.conf.urls.i18n')),
|
path('i18n/', include('django.conf.urls.i18n')),
|
||||||
|
path('accounts/',include('member.urls')),
|
||||||
path('accounts/', include('django.contrib.auth.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/doc/', include('django.contrib.admindocs.urls')),
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
]
|
]
|
||||||
|
|
|
@ -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 %}
|
Loading…
Reference in New Issue