diff options
| author | Claude Paroz <claude@2xlibre.net> | 2012-04-25 19:17:47 +0000 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2012-04-25 19:17:47 +0000 |
| commit | 1858e476721890ce1f47dfa4d2739d9e0f11621b (patch) | |
| tree | f8476bdf1de3cff6217ed4c77428eca3ef86db78 /django/views/generic/simple.py | |
| parent | ea9dc9f4b03ae034c1dc080730422dda7a9c2e47 (diff) | |
Fixed #18033 -- Removed function-based generic views, as per official deprecation timeline. Rest in peace! Thanks Anssi Kääriäinen for the review.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17937 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/views/generic/simple.py')
| -rw-r--r-- | django/views/generic/simple.py | 68 |
1 files changed, 0 insertions, 68 deletions
diff --git a/django/views/generic/simple.py b/django/views/generic/simple.py deleted file mode 100644 index f63860a4cf..0000000000 --- a/django/views/generic/simple.py +++ /dev/null @@ -1,68 +0,0 @@ -from django.template import loader, RequestContext -from django.http import HttpResponse, HttpResponseRedirect, HttpResponsePermanentRedirect, HttpResponseGone -from django.utils.log import getLogger - -import warnings -warnings.warn( - 'Function-based generic views have been deprecated; use class-based views instead.', - DeprecationWarning -) - -logger = getLogger('django.request') - - -def direct_to_template(request, template, extra_context=None, mimetype=None, **kwargs): - """ - Render a given template with any extra URL parameters in the context as - ``{{ params }}``. - """ - if extra_context is None: extra_context = {} - dictionary = {'params': kwargs} - for key, value in extra_context.items(): - if callable(value): - dictionary[key] = value() - else: - dictionary[key] = value - c = RequestContext(request, dictionary) - t = loader.get_template(template) - return HttpResponse(t.render(c), content_type=mimetype) - -def redirect_to(request, url, permanent=True, query_string=False, **kwargs): - """ - Redirect to a given URL. - - The given url may contain dict-style string formatting, which will be - interpolated against the params in the URL. For example, to redirect from - ``/foo/<id>/`` to ``/bar/<id>/``, you could use the following URLconf:: - - urlpatterns = patterns('', - ('^foo/(?P<id>\d+)/$', 'django.views.generic.simple.redirect_to', {'url' : '/bar/%(id)s/'}), - ) - - If the given url is ``None``, a HttpResponseGone (410) will be issued. - - If the ``permanent`` argument is False, then the response will have a 302 - HTTP status code. Otherwise, the status code will be 301. - - If the ``query_string`` argument is True, then the GET query string - from the request is appended to the URL. - - """ - args = request.META.get('QUERY_STRING', '') - - if url is not None: - if kwargs: - url = url % kwargs - - if args and query_string: - url = "%s?%s" % (url, args) - - klass = permanent and HttpResponsePermanentRedirect or HttpResponseRedirect - return klass(url) - else: - logger.warning('Gone: %s', request.path, - extra={ - 'status_code': 410, - 'request': request - }) - return HttpResponseGone() |
