Fix bug of empty names in users

This commit is contained in:
Grégory Soutadé 2012-12-24 15:40:11 +01:00
parent 933035314b
commit f0f32d31cc
3 changed files with 7 additions and 3 deletions

View File

@ -11,6 +11,10 @@
<input type="submit" name="edit" value="Edit" /><input type="submit" name="cancel" value="Cancel" />
</form>
{% else %}
<form action="/user/edit/{{ user_to_edit.id }}" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" name="cancel" value="Cancel" />
</form>
{% endif %}
{% endblock %}

View File

@ -5,10 +5,10 @@
<b>Any user available</b><br/><br/>
{% else %}
{% for user in users %}
{% if user.first_name|length != 0 or user.last_name|length != 0%}
{% if user.first_name != "" or user.last_name != "" %}
<li><a href="/user/{{ user.id }}">{{ user.first_name }} {{ user.last_name }}</a></li>
{% else %}
<li><a href="/user/{{ user.id }}">{{ user.login }}</a></li>
<li><a href="/user/{{ user.id }}">{{ user.username }}</a></li>
{% endif %}
{% endfor %}
{% endif %}

View File

@ -150,7 +150,7 @@ def edit_user(request, user_id):
if request.method == 'POST': # If the form has been submitted...
if int(user_id) != int(request.user.id) and (not request.user.is_superuser):
return HttpResponseRedirect('/user/' + str(user_id))
return HttpResponseRedirect('/user')
if 'edit' in request.POST:
form = UserForm(request.POST, instance=user, initial={'password':''}) # A form bound to the POST data
if form.is_valid(): # All validation rules pass