mirror of
https://github.com/django/django.git
synced 2024-12-23 01:25:58 +00:00
Decorated a few functions.
This commit is contained in:
parent
cbae4d3184
commit
6072de727f
@ -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)
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user