~ubuntu-branches/ubuntu/saucy/python-django/saucy-updates

« back to all changes in this revision

Viewing changes to django/contrib/comments/views/utils.py

  • Committer: Package Import Robot
  • Author(s): Luke Faraone, Jakub Wilk, Luke Faraone
  • Date: 2013-05-09 15:10:47 UTC
  • mfrom: (1.1.21) (4.4.27 sid)
  • Revision ID: package-import@ubuntu.com-20130509151047-aqv8d71oj9wvcv8c
Tags: 1.5.1-2
[ Jakub Wilk ]
* Use canonical URIs for Vcs-* fields.

[ Luke Faraone ]
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
A few bits of helper functions for comment views.
3
3
"""
4
4
 
5
 
import urllib
6
5
import textwrap
7
 
from django.core import urlresolvers
 
6
try:
 
7
    from urllib.parse import urlencode
 
8
except ImportError:     # Python 2
 
9
    from urllib import urlencode
 
10
 
8
11
from django.http import HttpResponseRedirect
9
 
from django.shortcuts import render_to_response
 
12
from django.shortcuts import render_to_response, resolve_url
10
13
from django.template import RequestContext
11
14
from django.core.exceptions import ObjectDoesNotExist
12
15
from django.contrib import comments
13
16
from django.utils.http import is_safe_url
14
17
 
15
 
def next_redirect(request, default, default_view, **get_kwargs):
 
18
def next_redirect(request, fallback, **get_kwargs):
16
19
    """
17
20
    Handle the "where should I go next?" part of comment views.
18
21
 
19
 
    The next value could be a kwarg to the function (``default``), or a
20
 
    ``?next=...`` GET arg, or the URL of a given view (``default_view``). See
 
22
    The next value could be a
 
23
    ``?next=...`` GET arg or the URL of a given view (``fallback``). See
21
24
    the view modules for examples.
22
25
 
23
26
    Returns an ``HttpResponseRedirect``.
24
27
    """
25
 
    next = request.POST.get('next', default)
 
28
    next = request.POST.get('next')
26
29
    if not is_safe_url(url=next, host=request.get_host()):
27
 
        next = urlresolvers.reverse(default_view)
 
30
        next = resolve_url(fallback)
28
31
 
29
32
    if get_kwargs:
30
33
        if '#' in next:
35
38
            anchor = ''
36
39
 
37
40
        joiner = ('?' in next) and '&' or '?'
38
 
        next += joiner + urllib.urlencode(get_kwargs) + anchor
 
41
        next += joiner + urlencode(get_kwargs) + anchor
39
42
    return HttpResponseRedirect(next)
40
43
 
41
44
def confirmation_view(template, doc="Display a confirmation view."):
58
61
    confirmed.__doc__ = textwrap.dedent("""\
59
62
        %s
60
63
 
61
 
        Templates: `%s``
 
64
        Templates: :template:`%s``
62
65
        Context:
63
66
            comment
64
67
                The posted comment