Removed 'change password' link next to the current user's name and added a few view to handle the current user's password, details and editing
This commit is contained in:
@@ -1,6 +1,19 @@
|
||||
import tempfile
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from common.conf import settings as common_settings
|
||||
from navigation.api import register_links
|
||||
|
||||
TEMPORARY_DIRECTORY = common_settings.TEMPORARY_DIRECTORY \
|
||||
if common_settings.TEMPORARY_DIRECTORY else tempfile.mkdtemp()
|
||||
|
||||
|
||||
def has_usable_password(context):
|
||||
return context['request'].user.has_usable_password
|
||||
|
||||
password_change_view = {'text': _(u'change password'), 'view': 'password_change_view', 'famfam': 'computer_key', 'condition': has_usable_password}
|
||||
current_user_details = {'text': _(u'user details'), 'view': 'current_user_details', 'famfam': 'vcard'}
|
||||
current_user_edit = {'text': _(u'edit details'), 'view': 'current_user_edit', 'famfam': 'vcard_edit'}
|
||||
|
||||
register_links(['current_user_details', 'current_user_edit', 'password_change_view'], [current_user_details, current_user_edit, password_change_view], menu_name='secondary_menu')
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from django import forms
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
from common.utils import return_attrib
|
||||
from common.widgets import DetailSelectMultiple, PlainWidget
|
||||
@@ -92,3 +93,22 @@ class ChoiceForm(forms.Form):
|
||||
self.fields['selection'].widget.attrs.update({'size': 14, 'class': 'choice_form'})
|
||||
|
||||
selection = forms.MultipleChoiceField()
|
||||
|
||||
|
||||
class UserForm_view(DetailForm):
|
||||
"""
|
||||
Form used to display an user's public details
|
||||
"""
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ('username', 'first_name', 'last_name', 'email', 'is_staff', 'is_superuser', 'last_login', 'date_joined', 'groups')
|
||||
|
||||
|
||||
class UserForm(forms.ModelForm):
|
||||
"""
|
||||
Form used to edit an user's mininal fields by the user himself
|
||||
"""
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ('first_name', 'last_name')
|
||||
|
||||
|
||||
@@ -7,6 +7,9 @@ urlpatterns = patterns('common.views',
|
||||
url(r'^about/$', direct_to_template, {'template': 'about.html'}, 'about'),
|
||||
url(r'^password/change/done/$', 'password_change_done', (), name='password_change_done'),
|
||||
url(r'^object/multiple/action/$', 'multi_object_action_view', (), name='multi_object_action_view'),
|
||||
|
||||
url(r'^user/$', 'current_user_details', (), 'current_user_details'),
|
||||
url(r'^user/edit/$', 'current_user_edit', (), 'current_user_edit'),
|
||||
)
|
||||
|
||||
urlpatterns += patterns('',
|
||||
|
||||
@@ -5,8 +5,9 @@ from django.shortcuts import render_to_response
|
||||
from django.template import RequestContext
|
||||
from django.contrib import messages
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.core.urlresolvers import reverse
|
||||
|
||||
from common.forms import ChoiceForm
|
||||
from common.forms import ChoiceForm, UserForm, UserForm_view
|
||||
|
||||
|
||||
def password_change_done(request):
|
||||
@@ -131,3 +132,43 @@ def assign_remove(request, left_list, right_list, add_method, remove_method, lef
|
||||
|
||||
return render_to_response('generic_form.html', context,
|
||||
context_instance=RequestContext(request))
|
||||
|
||||
|
||||
def current_user_details(request):
|
||||
"""
|
||||
Display the current user's details
|
||||
"""
|
||||
form = UserForm_view(instance=request.user)
|
||||
|
||||
return render_to_response(
|
||||
'generic_form.html', {
|
||||
'form': form,
|
||||
'title': _(u'current user details'),
|
||||
'read_only': True,
|
||||
},
|
||||
context_instance=RequestContext(request))
|
||||
|
||||
|
||||
def current_user_edit(request):
|
||||
"""
|
||||
Allow an user to edit his own details
|
||||
"""
|
||||
|
||||
next = request.POST.get('next', request.GET.get('next', request.META.get('HTTP_REFERER', reverse('current_user_details'))))
|
||||
|
||||
if request.method == 'POST':
|
||||
form = UserForm(instance=request.user, data=request.POST)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
messages.success(request, _(u'Current user\'s details updated.'))
|
||||
return HttpResponseRedirect(next)
|
||||
else:
|
||||
form = UserForm(instance=request.user)
|
||||
|
||||
return render_to_response(
|
||||
'generic_form.html', {
|
||||
'form': form,
|
||||
'next': next,
|
||||
'title': _(u'edit current user details'),
|
||||
},
|
||||
context_instance=RequestContext(request))
|
||||
|
||||
@@ -115,9 +115,7 @@
|
||||
{% trans "Anonymous" %}
|
||||
{% else %}
|
||||
{{ user.get_full_name|default:user }}
|
||||
{% if user.has_usable_password %}
|
||||
<a href="{% url password_change_view %}">({% trans "New password" %})</a>
|
||||
{% endif %}
|
||||
<a href="{% url current_user_details %}" title="{% trans 'User details' %}"><span class="famfam active famfam-vcard"></span></a>
|
||||
{% endif %}
|
||||
</li>
|
||||
|
||||
@@ -179,11 +177,13 @@
|
||||
{% if side_bar_search and not web_theme_hide_menus %}
|
||||
{% with "true" as side_bar %}
|
||||
{% with "true" as form_hide_required_text %}
|
||||
{% with "" as read_only %}
|
||||
{% with "" as object %}
|
||||
{% search_form %}
|
||||
{% endwith %}
|
||||
{% endwith %}
|
||||
{% endwith %}
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
|
||||
{% get_object_navigation_links "secondary_menu" as object_navigation_links %}
|
||||
|
||||
Reference in New Issue
Block a user