From 6072de727f0ffa7bf0aa67aadba5d4589561974d Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Mon, 14 Nov 2016 12:20:44 -0500 Subject: [PATCH] Decorated a few functions. --- django/utils/text.py | 5 +++-- tests/test_client/views.py | 7 ++----- tests/test_client_regress/views.py | 4 ++-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/django/utils/text.py b/django/utils/text.py index ec7af5389c..4f8ef9b31b 100644 --- a/django/utils/text.py +++ b/django/utils/text.py @@ -20,10 +20,11 @@ if six.PY2: from django.utils.encoding import force_unicode # NOQA -# Capitalizes the first letter of a string. +@keep_lazy_text def capfirst(x): + """Capitalize the first letter of a string.""" return x and force_text(x)[0].upper() + force_text(x)[1:] -capfirst = keep_lazy_text(capfirst) + # Set up regular expressions re_words = re.compile(r'<.*?>|((?:\w[-\w]*|&.*?;)+)', re.U | re.S) diff --git a/tests/test_client/views.py b/tests/test_client/views.py index 41106d78ff..c1841c3c44 100644 --- a/tests/test_client/views.py +++ b/tests/test_client/views.py @@ -213,24 +213,21 @@ def formset_view(request): return HttpResponse(t.render(c)) +@login_required def login_protected_view(request): "A simple view that is login protected." t = Template('This is a login protected test. Username is {{ user.username }}.', name='Login Template') c = Context({'user': request.user}) return HttpResponse(t.render(c)) -login_protected_view = login_required(login_protected_view) +@login_required(redirect_field_name='redirect_to') def login_protected_view_changed_redirect(request): "A simple view that is login protected with a custom redirect field set" t = Template('This is a login protected test. Username is {{ user.username }}.', name='Login Template') c = Context({'user': request.user}) - return HttpResponse(t.render(c)) -login_protected_view_changed_redirect = ( - login_required(redirect_field_name="redirect_to")(login_protected_view_changed_redirect) -) def _permission_protected_view(request): diff --git a/tests/test_client_regress/views.py b/tests/test_client_regress/views.py index 20431a3c2a..a50b0e1ed3 100644 --- a/tests/test_client_regress/views.py +++ b/tests/test_client_regress/views.py @@ -28,10 +28,10 @@ def staff_only_view(request): raise CustomTestException() +@login_required def get_view(request): "A simple login protected view" return HttpResponse("Hello world") -get_view = login_required(get_view) def request_data(request, template='base.html', data='sausage'): @@ -67,10 +67,10 @@ def nested_view(request): return render(request, 'base.html', {'nested': 'yes'}) +@login_required def login_protected_redirect_view(request): "A view that redirects all requests to the GET view" return HttpResponseRedirect('/get_view/') -login_protected_redirect_view = login_required(login_protected_redirect_view) def redirect_to_self_with_changing_query_view(request):