Move profile editing to gestion
This commit is contained in:
parent
815a5f274c
commit
b1cf96d0ae
7 changed files with 52 additions and 36 deletions
21
cof/forms.py
21
cof/forms.py
|
@ -177,27 +177,6 @@ class EventStatusFilterForm(forms.Form):
|
||||||
yield ("has_paid", None, value)
|
yield ("has_paid", None, value)
|
||||||
|
|
||||||
|
|
||||||
class UserProfileForm(forms.ModelForm):
|
|
||||||
first_name = forms.CharField(label=_('Prénom'), max_length=30)
|
|
||||||
last_name = forms.CharField(label=_('Nom'), max_length=30)
|
|
||||||
|
|
||||||
def __init__(self, *args, **kw):
|
|
||||||
super(UserProfileForm, self).__init__(*args, **kw)
|
|
||||||
self.fields['first_name'].initial = self.instance.user.first_name
|
|
||||||
self.fields['last_name'].initial = self.instance.user.last_name
|
|
||||||
|
|
||||||
def save(self, *args, **kw):
|
|
||||||
super(UserProfileForm, self).save(*args, **kw)
|
|
||||||
self.instance.user.first_name = self.cleaned_data.get('first_name')
|
|
||||||
self.instance.user.last_name = self.cleaned_data.get('last_name')
|
|
||||||
self.instance.user.save()
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = CofProfile
|
|
||||||
fields = ["first_name", "last_name", "phone", "mailing_cof",
|
|
||||||
"mailing_bda", "mailing_bda_revente"]
|
|
||||||
|
|
||||||
|
|
||||||
class RegistrationUserForm(forms.ModelForm):
|
class RegistrationUserForm(forms.ModelForm):
|
||||||
def __init__(self, *args, **kw):
|
def __init__(self, *args, **kw):
|
||||||
super(RegistrationUserForm, self).__init__(*args, **kw)
|
super(RegistrationUserForm, self).__init__(*args, **kw)
|
||||||
|
|
13
cof/views.py
13
cof/views.py
|
@ -302,19 +302,6 @@ def survey_status(request, survey_id):
|
||||||
"form": form})
|
"form": form})
|
||||||
|
|
||||||
|
|
||||||
@cof_required
|
|
||||||
def profile(request):
|
|
||||||
success = False
|
|
||||||
if request.method == "POST":
|
|
||||||
form = UserProfileForm(request.POST, instance=request.user.profile)
|
|
||||||
if form.is_valid():
|
|
||||||
form.save()
|
|
||||||
success = True
|
|
||||||
else:
|
|
||||||
form = UserProfileForm(instance=request.user.profile)
|
|
||||||
return render(request, "profile.html", {"form": form, "success": success})
|
|
||||||
|
|
||||||
|
|
||||||
def registration_set_ro_fields(user_form, profile_form):
|
def registration_set_ro_fields(user_form, profile_form):
|
||||||
user_form.fields['username'].widget.attrs['readonly'] = True
|
user_form.fields['username'].widget.attrs['readonly'] = True
|
||||||
profile_form.fields['login_clipper'].widget.attrs['readonly'] = True
|
profile_form.fields['login_clipper'].widget.attrs['readonly'] = True
|
||||||
|
|
|
@ -30,6 +30,8 @@ admin.autodiscover()
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
# Page d'accueil
|
# Page d'accueil
|
||||||
url(r'^$', cof_views.home, name='home'),
|
url(r'^$', cof_views.home, name='home'),
|
||||||
|
# The common views
|
||||||
|
url(r"^$", include("gestion.urls")),
|
||||||
# Le BdA
|
# Le BdA
|
||||||
url(r'^bda/', include('bda.urls')),
|
url(r'^bda/', include('bda.urls')),
|
||||||
# Les exports
|
# Les exports
|
||||||
|
@ -54,7 +56,6 @@ urlpatterns = [
|
||||||
url(r'^login$', cof_views.login, name="cof-login"),
|
url(r'^login$', cof_views.login, name="cof-login"),
|
||||||
url(r'^logout$', cof_views.logout),
|
url(r'^logout$', cof_views.logout),
|
||||||
# Infos persos
|
# Infos persos
|
||||||
url(r'^profile$', cof_views.profile),
|
|
||||||
url(r'^outsider/password-change$', django_views.password_change),
|
url(r'^outsider/password-change$', django_views.password_change),
|
||||||
url(r'^outsider/password-change-done$',
|
url(r'^outsider/password-change-done$',
|
||||||
django_views.password_change_done,
|
django_views.password_change_done,
|
||||||
|
|
19
gestion/forms.py
Normal file
19
gestion/forms.py
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
from django import forms
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
|
from .models import Profile
|
||||||
|
|
||||||
|
|
||||||
|
class UserForm(forms.ModelForm):
|
||||||
|
class Meta:
|
||||||
|
model = User
|
||||||
|
fields = ["first_name", "last_name"]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class ProfileForm(forms.ModelForm):
|
||||||
|
class Meta:
|
||||||
|
model = CofProfile
|
||||||
|
fields = ["phone", "departement"]
|
||||||
|
|
||||||
|
|
10
gestion/urls.py
Normal file
10
gestion/urls.py
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
from django.conf.urls import url
|
||||||
|
|
||||||
|
from . import views
|
||||||
|
|
||||||
|
|
||||||
|
app_name = "gestion"
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
url(r"^profile$", views.profile, name="profile"),
|
||||||
|
]
|
|
@ -1,3 +1,23 @@
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
|
from django.contrib.auth.decorators import login_required
|
||||||
|
|
||||||
# Create your views here.
|
from .forms import ProfileForm, UserForm
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def profile(request):
|
||||||
|
success = False
|
||||||
|
user = request.user
|
||||||
|
if request.method == "POST":
|
||||||
|
user_form = UserForm(request.POST, instance=user)
|
||||||
|
profile_form = ProfileForm(request.POST, instance=user.profile)
|
||||||
|
if all(user_form.is_valid(), profile_form.is_valid()):
|
||||||
|
user_form.save()
|
||||||
|
profile_form.save()
|
||||||
|
success = True
|
||||||
|
else:
|
||||||
|
user_form = UserForm(instance=user)
|
||||||
|
profile_form = ProfileForm(instance=user.profile)
|
||||||
|
return render(request, "gestion/profile.html",
|
||||||
|
{"user_form": user_form, "profile_form": profile_form,
|
||||||
|
"success": success})
|
||||||
|
|
Loading…
Reference in a new issue