8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-04 17:06:27 +00:00

Crée une vue permetant d'editer un user existant

This commit is contained in:
chirac 2016-07-01 18:22:52 +02:00
parent e08adf5833
commit b3872eb0c6
3 changed files with 15 additions and 4 deletions

View file

@ -9,6 +9,6 @@
<form class="form" method="post">
{% csrf_token %}
{% bootstrap_form userform %}
{% bootstrap_button "Créer" button_type="submit" icon="star" %}
{% bootstrap_button "Créer ou modifier" button_type="submit" icon="star" %}
</form>
{% endblock %}

View file

@ -4,5 +4,6 @@ from . import views
urlpatterns = [
url(r'^new_user/$', views.new_user, name='new_user'),
url(r'^edit_info/(?P<userid>[0-9]+)$', views.edit_info, name='edit_info'),
]

View file

@ -6,7 +6,7 @@ from django.shortcuts import render_to_response, get_object_or_404
from django.core.context_processors import csrf
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):
@ -19,7 +19,17 @@ def new_user(request):
user = InfoForm(request.POST)
if user.is_valid():
user.save()
return form({'userform': user}, 'users/new_user.html', request)
return form({'userform': user}, 'users/user.html', request)
else:
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)