ó
A()Qc           @   sÉ   d  Z  d d l Z y d d l m Z Wn! e k
 rI d d l m Z n Xd d l m Z d d l m	 Z	 m
 Z
 d d l m Z d d l m Z d d l m Z d d	 l m Z d
 „  Z d d „ Z d S(   s3   
A few bits of helper functions for comment views.
iÿÿÿÿN(   t	   urlencode(   t   HttpResponseRedirect(   t   render_to_responset   resolve_url(   t   RequestContext(   t   ObjectDoesNotExist(   t   comments(   t   is_safe_urlc         K   s¾   |  j  j d ƒ } t d | d |  j ƒ  ƒ s< t | ƒ } n  | r´ d | k r{ | j d d ƒ } | d } d | d } n d } d | k r“ d	 p– d } | | t | ƒ | 7} n  t | ƒ S(
   sú   
    Handle the "where should I go next?" part of comment views.

    The next value could be a
    ``?next=...`` GET arg or the URL of a given view (``fallback``). See
    the view modules for examples.

    Returns an ``HttpResponseRedirect``.
    t   nextt   urlt   hostt   #i   i    t    t   ?t   &(   t   POSTt   getR   t   get_hostR   t   rsplitR    R   (   t   requestt   fallbackt
   get_kwargsR   t   tmpt   anchort   joiner(    (    s<   ../Django//lib/python/django/contrib/comments/views/utils.pyt   next_redirect   s    

s   Display a confirmation view.c            s/   ‡  f d †  } t  j d | ˆ  f ƒ | _ | S(   sf   
    Confirmation view generator for the "comment was
    posted/flagged/deleted/approved" views.
    c            sx   d  } d |  j k rX y& t j ƒ  j j d |  j d ƒ } WqX t t f k
 rT qX Xn  t ˆ  i | d 6d t	 |  ƒ ƒS(   Nt   ct   pkt   commentt   context_instance(
   t   Nonet   GETR   t	   get_modelt   objectsR   R   t
   ValueErrorR   R   (   R   R   (   t   template(    s<   ../Django//lib/python/django/contrib/comments/views/utils.pyt	   confirmed1   s    &s           %s

        Templates: :template:`%s``
        Context:
            comment
                The posted comment
        (   t   textwrapt   dedentt   __doc__(   R#   t   docR$   (    (   R#   s<   ../Django//lib/python/django/contrib/comments/views/utils.pyt   confirmation_view,   s    (   R'   R%   t   urllib.parseR    t   ImportErrort   urllibt   django.httpR   t   django.shortcutsR   R   t   django.templateR   t   django.core.exceptionsR   t   django.contribR   t   django.utils.httpR   R   R)   (    (    (    s<   ../Django//lib/python/django/contrib/comments/views/utils.pyt   <module>   s   	