mirror of https://gitlab.crans.org/bde/nk20
add a profile_update view
This commit is contained in:
parent
e80163ce4d
commit
b9c3ab5ea8
|
@ -16,5 +16,6 @@ urlpatterns = [
|
||||||
path('club/<int:pk>/add_member/',views.ClubAddMemberView.as_view(),name="club_add_member"),
|
path('club/<int:pk>/add_member/',views.ClubAddMemberView.as_view(),name="club_add_member"),
|
||||||
path('club/create/',views.ClubCreateView.as_view(),name="club_create"),
|
path('club/create/',views.ClubCreateView.as_view(),name="club_create"),
|
||||||
path('user/',views.UserListView.as_view(),name="user_list"),
|
path('user/',views.UserListView.as_view(),name="user_list"),
|
||||||
path('user/<int:pk>',views.UserDetailView.as_view(),name="user_detail")
|
path('user/<int:pk>',views.UserDetailView.as_view(),name="user_detail"),
|
||||||
|
path('user/<int:pk>/update',views.UserUpdateView.as_view(),name="user_update_profile"),
|
||||||
]
|
]
|
||||||
|
|
|
@ -5,7 +5,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 import CreateView, ListView, DetailView
|
from django.views.generic import CreateView, ListView, DetailView, UpdateView
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
from django.contrib.auth.forms import UserCreationForm
|
from django.contrib.auth.forms import UserCreationForm
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
@ -49,6 +49,33 @@ class UserCreateView(CreateView):
|
||||||
profile.save()
|
profile.save()
|
||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
|
||||||
|
class UserUpdateView(LoginRequiredMixin,UpdateView):
|
||||||
|
model = User
|
||||||
|
fields = ['first_name','last_name','username','email']
|
||||||
|
template_name = 'member/profile_update.html'
|
||||||
|
|
||||||
|
second_form = ProfileForm
|
||||||
|
def get_context_data(self,**kwargs):
|
||||||
|
context = super().get_context_data(**kwargs)
|
||||||
|
context["profile_form"] = self.second_form(instance=context['user'].profile)
|
||||||
|
|
||||||
|
return context
|
||||||
|
|
||||||
|
def form_valid(self, form):
|
||||||
|
profile_form = ProfileForm(data=self.request.POST,instance=self.request.user.profile)
|
||||||
|
if form.is_valid() and profile_form.is_valid():
|
||||||
|
user = form.save()
|
||||||
|
profile = profile_form.save(commit=False)
|
||||||
|
profile.user = user
|
||||||
|
profile.save()
|
||||||
|
return super().form_valid(form)
|
||||||
|
|
||||||
|
def get_success_url(self, **kwargs):
|
||||||
|
if kwargs:
|
||||||
|
return reverse_lazy('member:user_detail', kwargs = {'pk': kwargs['id']})
|
||||||
|
else:
|
||||||
|
return reverse_lazy('member:user_detail', args = (self.object.id,))
|
||||||
|
|
||||||
class UserDetailView(LoginRequiredMixin,DetailView):
|
class UserDetailView(LoginRequiredMixin,DetailView):
|
||||||
"""
|
"""
|
||||||
Affiche les informations sur un utilisateur, sa note, ses clubs ...
|
Affiche les informations sur un utilisateur, sa note, ses clubs ...
|
||||||
|
|
|
@ -22,10 +22,12 @@
|
||||||
<dt class="col-6 col-md-3">{% trans 'balance'|capfirst %}</dt>
|
<dt class="col-6 col-md-3">{% trans 'balance'|capfirst %}</dt>
|
||||||
<dd class="col-6 col-md-3">{{ object.user.note.balance | pretty_money }}</dd>
|
<dd class="col-6 col-md-3">{{ object.user.note.balance | pretty_money }}</dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
<center>
|
||||||
|
<a class="btn btn-primary" href="{% url 'member:user_update_profile' object.pk %}">{% trans 'Update Profile' %}</a>
|
||||||
|
<a class="btn btn-primary" href="{% url 'password_change' %}">{% trans 'Change password' %}</a>
|
||||||
|
</center>
|
||||||
|
|
||||||
<a class="btn btn-primary" href="{% url 'password_change' %}">{% trans 'Change password' %}</a>
|
<div class="accordion" id="accordionProfile">
|
||||||
|
|
||||||
<div class="accordion" id="accordionExample">
|
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-header" id="headingOne">
|
<div class="card-header" id="headingOne">
|
||||||
<h5 class="mb-0">
|
<h5 class="mb-0">
|
||||||
|
@ -35,7 +37,7 @@
|
||||||
</h5>
|
</h5>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordionExample">
|
<div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordionProfile">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
{% render_table club_list %}
|
{% render_table club_list %}
|
||||||
</div>
|
</div>
|
||||||
|
@ -49,7 +51,7 @@
|
||||||
</button>
|
</button>
|
||||||
</h5>
|
</h5>
|
||||||
</div>
|
</div>
|
||||||
<div id="collapseTwo" class="collapse" aria-labelledby="headingTwo" data-parent="#accordionExample">
|
<div id="collapseTwo" class="collapse" aria-labelledby="headingTwo" data-parent="#accordionProfile">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
{% render_table history_list %}
|
{% render_table history_list %}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
<!doctype html>
|
||||||
|
{% extends "base.html" %}
|
||||||
|
{% load crispy_forms_tags %}
|
||||||
|
{% load i18n static pretty_money django_tables2 %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<form method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ form|crispy }}
|
||||||
|
{{ profile_form|crispy }}
|
||||||
|
<button class="btn btn-link" type="submit">
|
||||||
|
{% trans "Save Changes" %}
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{% endblock %}
|
Loading…
Reference in New Issue