Commit b3872eb0 authored by chirac's avatar chirac

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

parent e08adf58
......@@ -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 %}
......@@ -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'),
]
......@@ -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)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment