diff --git a/apps/member/admin.py b/apps/member/admin.py index dc595d7e..f45d5f55 100644 --- a/apps/member/admin.py +++ b/apps/member/admin.py @@ -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): """ diff --git a/apps/member/forms.py b/apps/member/forms.py index 6cc9ca4e..92c98996 100644 --- a/apps/member/forms.py +++ b/apps/member/forms.py @@ -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__' diff --git a/apps/member/signals.py b/apps/member/signals.py new file mode 100644 index 00000000..51751100 --- /dev/null +++ b/apps/member/signals.py @@ -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() diff --git a/apps/member/urls.py b/apps/member/urls.py new file mode 100644 index 00000000..dbb71374 --- /dev/null +++ b/apps/member/urls.py @@ -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") +] diff --git a/apps/member/views.py b/apps/member/views.py index aa693a20..2d080d0a 100644 --- a/apps/member/views.py +++ b/apps/member/views.py @@ -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 diff --git a/note_kfet/urls.py b/note_kfet/urls.py index ea689e1f..40b6f3a6 100644 --- a/note_kfet/urls.py +++ b/note_kfet/urls.py @@ -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), ] diff --git a/templates/member/signup.html b/templates/member/signup.html new file mode 100644 index 00000000..1021b8c0 --- /dev/null +++ b/templates/member/signup.html @@ -0,0 +1,14 @@ + +{% extends 'base.html' %} +{% load crispy_forms_tags %} +{% block title %}Sign Up{% endblock %} + +{% block content %} +