2014-04-23 04:19:46 +08:00
|
|
|
from functools import partial, update_wrapper
|
|
|
|
|
2015-01-28 20:35:27 +08:00
|
|
|
from django.contrib.auth.decorators import user_passes_test
|
2010-08-14 22:27:35 +08:00
|
|
|
from django.http import HttpResponse
|
2015-12-30 23:51:16 +08:00
|
|
|
from django.urls import reverse_lazy
|
2011-04-29 19:49:59 +08:00
|
|
|
from django.views.generic import RedirectView
|
2010-08-14 22:27:35 +08:00
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2008-08-31 19:11:20 +08:00
|
|
|
def empty_view(request, *args, **kwargs):
|
2010-08-14 22:27:35 +08:00
|
|
|
return HttpResponse('')
|
2008-09-27 14:14:11 +08:00
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2008-09-27 14:14:11 +08:00
|
|
|
def absolute_kwargs_view(request, arg1=1, arg2=2):
|
2010-08-14 22:27:35 +08:00
|
|
|
return HttpResponse('')
|
2010-08-06 21:47:56 +08:00
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2011-05-08 00:59:25 +08:00
|
|
|
def defaults_view(request, arg1, arg2):
|
|
|
|
pass
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2014-04-21 01:12:43 +08:00
|
|
|
def nested_view(request):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2011-06-17 00:41:14 +08:00
|
|
|
def erroneous_view(request):
|
2013-10-18 19:25:30 +08:00
|
|
|
import non_existent # NOQA
|
2011-06-17 00:41:14 +08:00
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2012-09-27 21:06:58 +08:00
|
|
|
def pass_resolver_match_view(request, *args, **kwargs):
|
|
|
|
response = HttpResponse('')
|
|
|
|
response.resolver_match = request.resolver_match
|
|
|
|
return response
|
|
|
|
|
2016-11-13 01:11:23 +08:00
|
|
|
|
2015-04-25 03:51:26 +08:00
|
|
|
uncallable = None # neither a callable nor a string
|
2011-06-17 00:41:14 +08:00
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2017-01-19 15:39:46 +08:00
|
|
|
class ViewClass:
|
2010-08-06 21:47:56 +08:00
|
|
|
def __call__(self, request, *args, **kwargs):
|
2010-08-14 22:27:35 +08:00
|
|
|
return HttpResponse('')
|
2010-08-06 21:47:56 +08:00
|
|
|
|
2016-11-13 01:11:23 +08:00
|
|
|
|
2010-08-06 21:47:56 +08:00
|
|
|
view_class_instance = ViewClass()
|
2010-08-14 22:27:35 +08:00
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2011-05-12 21:24:07 +08:00
|
|
|
class LazyRedirectView(RedirectView):
|
2011-04-29 19:49:59 +08:00
|
|
|
url = reverse_lazy('named-lazy-url-redirected-to')
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2016-04-02 19:18:26 +08:00
|
|
|
@user_passes_test(lambda u: u.is_authenticated, login_url=reverse_lazy('some-login-page'))
|
2011-04-29 19:49:59 +08:00
|
|
|
def login_required_view(request):
|
|
|
|
return HttpResponse('Hello you')
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2010-08-14 22:27:35 +08:00
|
|
|
def bad_view(request, *args, **kwargs):
|
|
|
|
raise ValueError("I don't think I'm getting good value for this view")
|
2014-04-23 04:19:46 +08:00
|
|
|
|
|
|
|
|
|
|
|
empty_view_partial = partial(empty_view, template_name="template.html")
|
2016-01-06 05:47:48 +08:00
|
|
|
empty_view_nested_partial = partial(empty_view_partial, template_name="nested_partial.html")
|
2014-04-23 04:19:46 +08:00
|
|
|
empty_view_wrapped = update_wrapper(
|
|
|
|
partial(empty_view, template_name="template.html"), empty_view,
|
|
|
|
)
|