mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-05 01:16:27 +00:00
Crée une vue permetant d'editer un user existant
This commit is contained in:
parent
e08adf5833
commit
b3872eb0c6
3 changed files with 15 additions and 4 deletions
|
@ -9,6 +9,6 @@
|
||||||
<form class="form" method="post">
|
<form class="form" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{% bootstrap_form userform %}
|
{% bootstrap_form userform %}
|
||||||
{% bootstrap_button "Créer" button_type="submit" icon="star" %}
|
{% bootstrap_button "Créer ou modifier" button_type="submit" icon="star" %}
|
||||||
</form>
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
|
@ -4,5 +4,6 @@ from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^new_user/$', views.new_user, name='new_user'),
|
url(r'^new_user/$', views.new_user, name='new_user'),
|
||||||
|
url(r'^edit_info/(?P<userid>[0-9]+)$', views.edit_info, name='edit_info'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ from django.shortcuts import render_to_response, get_object_or_404
|
||||||
from django.core.context_processors import csrf
|
from django.core.context_processors import csrf
|
||||||
from django.template import Context, RequestContext, loader
|
from django.template import Context, RequestContext, loader
|
||||||
|
|
||||||
from users.models import UserForm, InfoForm
|
from users.models import User, UserForm, InfoForm, PasswordForm, StateForm
|
||||||
|
|
||||||
|
|
||||||
def form(ctx, template, request):
|
def form(ctx, template, request):
|
||||||
|
@ -19,7 +19,17 @@ def new_user(request):
|
||||||
user = InfoForm(request.POST)
|
user = InfoForm(request.POST)
|
||||||
if user.is_valid():
|
if user.is_valid():
|
||||||
user.save()
|
user.save()
|
||||||
return form({'userform': user}, 'users/new_user.html', request)
|
return form({'userform': user}, 'users/user.html', request)
|
||||||
else:
|
else:
|
||||||
user = InfoForm()
|
user = InfoForm()
|
||||||
return form({'userform': user}, 'users/new_user.html', request)
|
return form({'userform': user}, 'users/user.html', request)
|
||||||
|
|
||||||
|
def edit_info(request, userid):
|
||||||
|
try:
|
||||||
|
user = User.objects.get(pk=userid)
|
||||||
|
except User.DoesNotExist:
|
||||||
|
user = None
|
||||||
|
user = InfoForm(request.POST or None, instance=user)
|
||||||
|
if user.is_valid():
|
||||||
|
user.save()
|
||||||
|
return form({'userform': user}, 'users/user.html', request)
|
||||||
|
|
Loading…
Reference in a new issue