ó
ø¢TQc           @   s
  d  d l  m Z d  d l m Z d  d l m Z d  d l m Z d  d l m	 Z	 d  d l
 m Z d  d l m Z d  d l m Z d  d	 l m Z d  d
 l m Z e e d d ƒ Z d e j f d „  ƒ  YZ e d e f d „  ƒ  Yƒ Z e d e j f d „  ƒ  Yƒ Z d S(   iÿÿÿÿ(   t   settings(   t   CommentManager(   t   generic(   t   ContentType(   t   Site(   t   urlresolvers(   t   models(   t   ugettext_lazy(   t   timezone(   t   python_2_unicode_compatiblet   COMMENT_MAX_LENGTHi¸  t   BaseCommentAbstractModelc           B   s‡   e  Z d  Z e j e d e d ƒ d d ƒZ e j e d ƒ ƒ Z	 e
 j d d d d	 ƒ Z e j e ƒ Z d
 d d „  ƒ  YZ d „  Z RS(   s]   
    An abstract base class that any custom comment models probably should
    subclass.
    t   verbose_names   content typet   related_names   content_type_set_for_%(class)ss	   object IDt   ct_fieldt   content_typet   fk_fieldt	   object_pkt   Metac           B   s   e  Z e Z RS(    (   t   __name__t
   __module__t   Truet   abstract(    (    (    s7   ../Django//lib/python/django/contrib/comments/models.pyR      s   c         C   s   t  j d d |  j |  j f ƒS(   sK   
        Get a URL suitable for redirecting to the content object.
        s   comments-url-redirectt   args(   R   t   reverset   content_type_idR   (   t   self(    (    s7   ../Django//lib/python/django/contrib/comments/models.pyt   get_content_object_url"   s    (    (   R   R   t   __doc__R   t
   ForeignKeyR   t   _R   t	   TextFieldR   R   t   GenericForeignKeyt   content_objectR   t   siteR   R   (    (    (    s7   ../Django//lib/python/django/contrib/comments/models.pyR      s   	t   Commentc        
   B   s  e  Z d  Z e j e j d e d ƒ d e d e d d ƒZ	 e j
 e d ƒ d d	 d e ƒZ e j e d
 ƒ d e ƒZ e j e d ƒ d e ƒZ e j e d ƒ d e ƒZ e j e d ƒ d d' ƒZ e j e d ƒ d e d e ƒZ e j e d ƒ d e d e d ƒ ƒZ e j e d ƒ d e d e d ƒ ƒZ e ƒ  Z d d( d „  ƒ  YZ d „  Z d „  Z  d „  Z! e" e! d e! j ƒZ# d „  Z$ d „  Z% e" e$ e% d d ƒZ& d „  Z' d „  Z( e" e' e( d d  ƒZ) d! „  Z* d" „  Z+ e" e* e+ d d# ƒZ, d$ d% „ Z- d& „  Z. RS()   s+   
    A user comment about some object.
    R   t   usert   blankt   nullR   s   %(class)s_commentss   user's namet
   max_lengthi2   s   user's email addresss
   user's URLt   comments   date/time submittedt   defaults
   IP addresss	   is publict	   help_textsI   Uncheck this box to make the comment effectively disappear from the site.s
   is removedst   Check this box if the comment is inappropriate. A "This comment has been removed" message will be displayed instead.R   c           B   s5   e  Z d  Z d Z d g Z e d ƒ Z e d ƒ Z RS(   t   django_commentst   submit_datet   can_moderates   Can moderate commentsR(   t   comments(   s   submit_date(   R-   s   Can moderate comments(   R   R   t   db_tablet   orderingt   permissionsR   R   t   verbose_name_plural(    (    (    s7   ../Django//lib/python/django/contrib/comments/models.pyR   K   s
   	c         C   s   d |  j  |  j d  f S(   Ns	   %s: %s...i2   (   t   nameR(   (   R   (    (    s7   ../Django//lib/python/django/contrib/comments/models.pyt   __str__R   s    c         O   s>   |  j  d  k r! t j ƒ  |  _  n  t t |  ƒ j | | Ž  d  S(   N(   R,   t   NoneR   t   nowt   superR#   t   save(   R   R   t   kwargs(    (    s7   ../Django//lib/python/django/contrib/comments/models.pyR8   U   s    c         C   s²   t  |  d ƒ s« i |  j d 6|  j d 6|  j d 6} |  j rŸ |  j } | j r^ | j | d <n  | j ƒ  r€ |  j j ƒ  | d <qŸ |  j sŸ | j ƒ  | d <qŸ n  | |  _	 n  |  j	 S(   sß   
        Get a dictionary that pulls together information about the poster
        safely for both authenticated and non-authenticated comments.

        This dict will have ``name``, ``email``, and ``url`` fields.
        t	   _userinfoR3   t   emailt   url(
   t   hasattrt	   user_namet
   user_emailt   user_urlt   user_idR$   R;   t   get_full_namet   get_usernameR:   (   R   t   userinfot   u(    (    s7   ../Django//lib/python/django/contrib/comments/models.pyt   _get_userinfoZ   s    

				t   docc         C   s   |  j  d S(   NR3   (   RD   (   R   (    (    s7   ../Django//lib/python/django/contrib/comments/models.pyt	   _get_namew   s    c         C   s+   |  j  r t t d ƒ ƒ ‚ n  | |  _ d  S(   NsP   This comment was posted by an authenticated user and thus the name is read-only.(   RA   t   AttributeErrorR   R>   (   R   t   val(    (    s7   ../Django//lib/python/django/contrib/comments/models.pyt	   _set_namez   s    	s,   The name of the user who posted this commentc         C   s   |  j  d S(   NR;   (   RD   (   R   (    (    s7   ../Django//lib/python/django/contrib/comments/models.pyt
   _get_email   s    c         C   s+   |  j  r t t d ƒ ƒ ‚ n  | |  _ d  S(   NsQ   This comment was posted by an authenticated user and thus the email is read-only.(   RA   RI   R   R?   (   R   RJ   (    (    s7   ../Django//lib/python/django/contrib/comments/models.pyt
   _set_email„   s    	s-   The email of the user who posted this commentc         C   s   |  j  d S(   NR<   (   RD   (   R   (    (    s7   ../Django//lib/python/django/contrib/comments/models.pyt   _get_url‹   s    c         C   s   | |  _  d  S(   N(   R@   (   R   RJ   (    (    s7   ../Django//lib/python/django/contrib/comments/models.pyt   _set_urlŽ   s    s1   The URL given by the user who posted this comments   #c%(id)sc         C   s   |  j  ƒ  | |  j S(   N(   R   t   __dict__(   R   t   anchor_pattern(    (    s7   ../Django//lib/python/django/contrib/comments/models.pyt   get_absolute_url’   s    c         C   sU   i |  j  p |  j d 6|  j d 6|  j d 6|  j j d 6|  j ƒ  d 6} t d ƒ | S(   sH   
        Return this comment as plain text.  Useful for emails.
        R$   t   dateR(   t   domainR<   sE   Posted by %(user)s at %(date)s

%(comment)s

http://%(domain)s%(url)s(   R$   R3   R,   R(   R"   RT   RR   R   (   R   t   d(    (    s7   ../Django//lib/python/django/contrib/comments/models.pyt   get_as_text•   s    

N(    (/   R   R   R   R   R   R    t   AUTH_USER_MODELR   R   R$   t	   CharFieldR>   t
   EmailFieldR?   t   URLFieldR@   R   R
   R(   t   DateTimeFieldR5   R,   t   IPAddressFieldt
   ip_addresst   BooleanFieldt	   is_publict   Falset
   is_removedR   t   objectsR   R4   R8   RF   t   propertyRD   RH   RK   R3   RL   RM   R;   RN   RO   R<   RR   RV   (    (    (    s7   ../Django//lib/python/django/contrib/comments/models.pyR#   ,   s<   !!										t   CommentFlagc           B   sÆ   e  Z d  Z e j e j d e d ƒ d d ƒZ e j e	 d e d ƒ d d ƒZ
 e j e d ƒ d d	 d
 e ƒZ e j e d ƒ d d ƒZ d Z d Z d Z d d d „  ƒ  YZ d „  Z d „  Z RS(   sÐ  
    Records a flag on a comment. This is intentionally flexible; right now, a
    flag could be:

        * A "removal suggestion" -- where a user suggests a comment for (potential) removal.

        * A "moderator deletion" -- used when a moderator deletes a comment.

    You can (ab)use this model to add other flags, if needed. However, by
    design users are only allowed to flag a comment with a given flag once;
    if you want rating look elsewhere.
    R   R$   R   t   comment_flagsR(   t   flagst   flagR'   i   t   db_indexRS   R)   s   removal suggestions   moderator deletions   moderator approvalR   c           B   s/   e  Z d  Z d g Z e d ƒ Z e d ƒ Z RS(   t   django_comment_flagsR$   R(   Rg   s   comment flags   comment flags(   s   users   comments   flag(   R   R   R/   t   unique_togetherR   R   R2   (    (    (    s7   ../Django//lib/python/django/contrib/comments/models.pyR   »   s   	c         C   s    d |  j  |  j |  j j ƒ  f S(   Ns   %s flag of comment ID %s by %s(   Rg   t
   comment_idR$   RC   (   R   (    (    s7   ../Django//lib/python/django/contrib/comments/models.pyR4   Á   s    c         O   s>   |  j  d  k r! t j ƒ  |  _  n  t t |  ƒ j | | Ž  d  S(   N(   t	   flag_dateR5   R   R6   R7   Rd   R8   (   R   R   R9   (    (    s7   ../Django//lib/python/django/contrib/comments/models.pyR8   Å   s    N(    (   R   R   R   R   R   R    RW   R   R$   R#   R(   RX   R   Rg   R[   R5   Rl   t   SUGGEST_REMOVALt   MODERATOR_DELETIONt   MODERATOR_APPROVALR   R4   R8   (    (    (    s7   ../Django//lib/python/django/contrib/comments/models.pyRd   £   s   $!!	N(   t   django.confR    t    django.contrib.comments.managersR   t   django.contrib.contenttypesR   t"   django.contrib.contenttypes.modelsR   t   django.contrib.sites.modelsR   t   django.coreR   t	   django.dbR   t   django.utils.translationR   R   t   django.utilsR   t   django.utils.encodingR	   t   getattrR
   t   ModelR   R#   Rd   (    (    (    s7   ../Django//lib/python/django/contrib/comments/models.pyt   <module>   s   v