Editing of user info

This commit is contained in:
Michal Čihař 2012-03-02 16:38:41 +01:00
parent 8a7a537bd0
commit 67c2342488
3 changed files with 28 additions and 4 deletions

View File

@ -1,7 +1,17 @@
from django import forms from django import forms
from accounts.models import Profile from accounts.models import Profile
from django.contrib.auth.models import User
class ProfileForm(forms.ModelForm): class ProfileForm(forms.ModelForm):
class Meta: class Meta:
model = Profile model = Profile
class UserForm(forms.ModelForm):
class Meta:
model = User
fields = [
'first_name',
'last_name',
'email',
]

View File

@ -1,13 +1,21 @@
from django.shortcuts import render_to_response from django.shortcuts import render_to_response
from django.template import RequestContext from django.template import RequestContext
from accounts.forms import ProfileForm from accounts.forms import ProfileForm, UserForm
def profile(request): def profile(request):
if request.method == 'POST': if request.method == 'POST':
form = ProfileForm(request.POST) form = ProfileForm(request.POST, instance = request.user.get_profile())
userform = UserForm(request.POST, instance = request.user)
if form.is_valid() and userform.is_valid():
form.save()
userform.save()
else: else:
form = ProfileForm(instance = request.user.get_profile()) form = ProfileForm(instance = request.user.get_profile())
userform = UserForm(instance = request.user)
return render_to_response('profile.html', RequestContext(request, {'form': form})) return render_to_response('profile.html', RequestContext(request, {
'form': form,
'userform': userform,
}))

View File

@ -4,7 +4,7 @@
{% block content %} {% block content %}
{% if form.errors %} {% if form.errors or userform.errors %}
<div class="ui-widget"> <div class="ui-widget">
<div style="padding: 0pt 0.7em;" class="ui-state-error ui-corner-all"> <div style="padding: 0pt 0.7em;" class="ui-state-error ui-corner-all">
<p><span style="float: left; margin-right: 0.3em;" class="ui-icon ui-icon-alert"></span> <p><span style="float: left; margin-right: 0.3em;" class="ui-icon ui-icon-alert"></span>
@ -23,6 +23,12 @@
</table> </table>
</fieldset> </fieldset>
<fieldset> <fieldset>
<legend>{% trans "Account" %}</legend>
<table>
{{ userform.as_table }}
</table>
</fieldset>
<fieldset>
<legend>{% trans "Password" %}</legend> <legend>{% trans "Password" %}</legend>
{% url 'django.contrib.auth.views.password_change' as pw_url %} {% url 'django.contrib.auth.views.password_change' as pw_url %}
{% blocktrans %}You can change password on <a href="{{ pw_url }}">separate page</a>.{% endblocktrans %} {% blocktrans %}You can change password on <a href="{{ pw_url }}">separate page</a>.{% endblocktrans %}