Ñò
©ÃãMc        	   @   sä   d  d k  l Z d  d k l Z l Z l Z d  d k l Z l Z d  d k	 l
 Z
 d  d k l Z d  d k l Z d e f d „  ƒ  YZ d	 „  Z d
 „  Z d „  Z e d ƒ Z d „  Z d „  Z d „  Z d e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t
   attrgetter(   t   connectionst   transactiont   IntegrityError(   t   signalst   sql(   t   GET_ITERATOR_CHUNK_SIZE(   t
   SortedDict(   t   wrapst   ProtectedErrorc           B   s   e  Z d  „  Z RS(   c         C   s    | |  _  t i |  | | ƒ d  S(   N(   t   protected_objectsR   t   __init__(   t   selft   msgR
   (    (    sC   /usr/local/lib/python2.6/dist-packages/django/db/models/deletion.pyR      s    	(   t   __name__t
   __module__R   (    (    (    sC   /usr/local/lib/python2.6/dist-packages/django/db/models/deletion.pyR	   
   s   c         C   sb   |  i  | d | i i d | i d | i ƒ| i o) t | i i o |  i | d  | ƒ n d  S(   Nt   sourcet   source_attrt   nullable(
   t   collectt   relt   tot   namet   nullR   t   featurest   can_defer_constraint_checkst   add_field_updatet   None(   t	   collectort   fieldt   sub_objst   using(    (    sC   /usr/local/lib/python2.6/dist-packages/django/db/models/deletion.pyt   CASCADE   s    c         C   s6   t  d | i i i | d i i | i f | ƒ ‚ d  S(   Nso   Cannot delete some instances of model '%s' because they are referenced through a protected foreign key: '%s.%s'i    (   R	   R   R   R   t	   __class__R   (   R   R   R   R   (    (    sC   /usr/local/lib/python2.6/dist-packages/django/db/models/deletion.pyt   PROTECT   s    #c            s3   t  ˆ  ƒ o ‡  f d †  } n ‡  f d †  } | S(   Nc            s   |  i  | ˆ  ƒ  | ƒ d  S(   N(   R   (   R   R   R   R   (   t   value(    sC   /usr/local/lib/python2.6/dist-packages/django/db/models/deletion.pyt   set_on_delete#   s    c            s   |  i  | ˆ  | ƒ d  S(   N(   R   (   R   R   R   R   (   R#   (    sC   /usr/local/lib/python2.6/dist-packages/django/db/models/deletion.pyR$   &   s    (   t   callable(   R#   R$   (    (   R#   sC   /usr/local/lib/python2.6/dist-packages/django/db/models/deletion.pyt   SET!   s    c         C   s   |  i  | | i ƒ  | ƒ d  S(   N(   R   t   get_default(   R   R   R   R   (    (    sC   /usr/local/lib/python2.6/dist-packages/django/db/models/deletion.pyt   SET_DEFAULT.   s    c         C   s   d  S(   N(    (   R   R   R   R   (    (    sC   /usr/local/lib/python2.6/dist-packages/django/db/models/deletion.pyt
   DO_NOTHING2   s    c            s   t  ˆ  ƒ ‡  f d †  ƒ } | S(   Nc            s¤   t  i d |  i ƒ p t  i d |  i ƒ t } n t } zE ˆ  |  | | Ž | o t  i d |  i ƒ n t  i d |  i ƒ Wd  | o t  i d |  i ƒ n Xd  S(   NR   (	   R   t
   is_managedR   t   enter_transaction_managementt   Truet   Falset   committ   commit_unless_managedt   leave_transaction_management(   R   t   argst   kwargst   forced_managed(   t   func(    sC   /usr/local/lib/python2.6/dist-packages/django/db/models/deletion.pyt	   decorated7   s    
(   R   (   R4   R5   (    (   R4   sC   /usr/local/lib/python2.6/dist-packages/django/db/models/deletion.pyt   force_managed6   s    t	   Collectorc           B   sw   e  Z d  „  Z d	 e e d „ Z d „  Z d „  Z d	 e e d	 e d „ Z	 d „  Z
 d „  Z d „  Z e d „  ƒ Z RS(
   c         C   s1   | |  _  h  |  _ h  |  _ h  |  _ h  |  _ d  S(   N(   R   t   datat   batchest   field_updatest   dependencies(   R   R   (    (    sC   /usr/local/lib/python2.6/dist-packages/django/db/models/deletion.pyR   K   s
    				c   	      C   sÇ   | p g  Sg  } | d i  } |  i i | t ƒ  ƒ } x, | D]$ } | | j o | i | ƒ q> q> W| i | ƒ | d j	 oC | o; | o | | } } n |  i i | t ƒ  ƒ i | ƒ n | S(   s9  
        Adds 'objs' to the collection of objects to be deleted.  If the call is
        the result of a cascade, 'source' should be the model that caused it,
        and 'nullable' should be set to True if the relation can be null.

        Returns a list of all objects that were not already collected.
        i    N(	   R!   R8   t
   setdefaultt   sett   appendt   updateR   R;   t   add(	   R   t   objsR   R   t   reverse_dependencyt   new_objst   modelt	   instancest   obj(    (    sC   /usr/local/lib/python2.6/dist-packages/django/db/models/deletion.pyR@   S   s     #c         C   s/   |  i  i | h  ƒ i | t ƒ  ƒ i | ƒ d S(   s–   
        Schedules a batch delete. Every instance of 'model' that is related to
        an instance of 'obj' through 'field' will be deleted.
        N(   R9   R<   R=   R?   (   R   RD   R   RA   (    (    sC   /usr/local/lib/python2.6/dist-packages/django/db/models/deletion.pyt	   add_batchm   s    c         C   sN   | p d S| d i  } |  i i | h  ƒ i | | f t ƒ  ƒ i | ƒ d S(   s‰   
        Schedules a field update. 'objs' must be a homogenous iterable
        collection of model instances (e.g. a QuerySet).
        Ni    (   R!   R:   R<   R=   R?   (   R   R   R#   RA   RD   (    (    sC   /usr/local/lib/python2.6/dist-packages/django/db/models/deletion.pyR   t   s    	c         C   sº  |  i  | | | d | ƒ} | p d S| d i } xƒ | i i i ƒ  D]o \ }	 }
 |
 o\ g  } | D] } | t | |
 i ƒ qe ~ } |  i | d | d |
 i i	 d t
 d t ƒqG qG W| oõ xŒ | i i d t ƒ D]u } | i } | i i i o |  i | i | | ƒ q× |  i | | ƒ } | p q× n | i i |  | | |  i ƒ q× Wxc | i i D]Q } | i i p> | i | |  i ƒ } |  i | d | d | i i	 d t ƒq]q]Wn d S(	   s  
        Adds 'objs' to the collection of objects to be deleted as well as all
        parent instances.  'objs' must be a homogenous iterable collection of
        model instances (e.g. a QuerySet).  If 'collect_related' is True,
        related objects will be handled by their respective on_delete handler.

        If the call is the result of a cascade, 'source' should be the model
        that caused it and 'nullable' should be set to True, if the relation
        can be null.

        If 'reverse_dependency' is True, 'source' will be deleted before the
        current model, rather than after. (Needed for cascading to parent
        models, the one case in which the cascade follows the forwards
        direction of an FK rather than the reverse direction.)
        RB   Ni    R   R   t   collect_relatedt   include_hiddenR   (   R@   R!   t   _metat   parentst	   iteritemst   getattrR   R   R   t   related_nameR-   R,   t   get_all_related_objectsR   RD   t   auto_createdRG   t   related_objectst	   on_deleteR   t   many_to_manyt   throught   bulk_related_objects(   R   RA   R   R   RH   R   RB   RC   RD   t   parent_modelt   ptrt   _[1]RF   t   parent_objst   relatedR   R   t   relation(    (    sC   /usr/local/lib/python2.6/dist-packages/django/db/models/deletion.pyR   €   s>    	 - 	  c         C   s0   | i  i i |  i ƒ i h | d | i i 6  S(   s_   
        Gets a QuerySet of objects related to ``objs`` via the relation ``related``.

        s   %s__in(   RD   t   _base_managerR   t   filterR   R   (   R   RZ   RA   (    (    sC   /usr/local/lib/python2.6/dist-packages/django/db/models/deletion.pyRQ   ¸   s    c         c   s@   x9 |  i  i ƒ  D]( \ } } x | D] } | | f Vq# Wq Wd  S(   N(   R8   RL   (   R   RD   RE   RF   (    (    sC   /usr/local/lib/python2.6/dist-packages/django/db/models/deletion.pyt   instances_with_modelÁ   s
      c         C   sè   g  } |  i  i ƒ  } x• t | ƒ t | ƒ j  o{ t } xb | D]Z } | | j o q> n |  i i | ƒ } | o | i | ƒ p | i | ƒ t } q> q> W| p d  Sq Wt	 g  } | D] } | | |  i  | f q» ~ ƒ |  _  d  S(   N(
   R8   t   keyst   lenR-   R;   t   gett
   differenceR>   R,   R   (   R   t   sorted_modelst   modelst   foundRD   R;   RX   (    (    sC   /usr/local/lib/python2.6/dist-packages/django/db/models/deletion.pyt   sortÆ   s"      

c         C   s8  x< |  i  i ƒ  D]+ \ } } t | d t d ƒ ƒ|  i  | <q W|  i ƒ  xM |  i ƒ  D]? \ } } | i i p& t i	 i
 d | d | d |  i ƒ qV qV Wx |  i i ƒ  D]| \ } } t i | ƒ } x^ | i ƒ  D]P \ \ } } } | i g  } | D] } | | i qô ~ h | | i 6|  i ƒ qÑ Wq© Wx! |  i  i ƒ  D] } | i ƒ  q9Wx} |  i i ƒ  D]l \ } }	 t i | ƒ } xN |	 i ƒ  D]@ \ } } | i g  }
 | D] } |
 | i q¢~
 |  i | ƒ q…Wq]Wxc |  i  i ƒ  D]R \ } } t i | ƒ } g  } | D] } | | i q~ } | i | |  i ƒ qÝWxM |  i ƒ  D]? \ } } | i i p& t i i
 d | d | d |  i ƒ q@q@Wxd |  i i ƒ  D]S \ } } xD | i ƒ  D]6 \ \ } } } x! | D] } t | | i | ƒ qÅWq¬Wq“WxG |  i  i ƒ  D]6 \ } } x' | D] } t | | i i i d  ƒ qWqúWd  S(   Nt   keyt   pkt   sendert   instanceR   (   R8   t   itemst   sortedR    Rf   R^   RJ   RP   R   t
   pre_deletet   sendR   R:   RL   R   t   UpdateQueryt   update_batchRh   R   t
   itervaluest   reverseR9   t   DeleteQueryt   delete_batcht   post_deletet   setattrt   attnameR   (   R   RD   RE   RF   t   instances_for_fieldvaluest   queryR   R#   RX   R9   t   _[2]t   _[3]t   pk_listRj   (    (    sC   /usr/local/lib/python2.6/dist-packages/django/db/models/deletion.pyt   delete×   s^     #
   '   < $      N(   R   R   R   R   R-   R@   RG   R   R,   R   RQ   R^   Rf   R6   R}   (    (    (    sC   /usr/local/lib/python2.6/dist-packages/django/db/models/deletion.pyR7   J   s   				7				N(   t   operatorR    t	   django.dbR   R   R   t   django.db.modelsR   R   t   django.db.models.sql.constantsR   t   django.utils.datastructuresR   t   django.utils.functionalR   R	   R    R"   R&   R   t   SET_NULLR(   R)   R6   t   objectR7   (    (    (    sC   /usr/local/lib/python2.6/dist-packages/django/db/models/deletion.pyt   <module>   s   				
			