
0_c           @  s  d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l m Z d  d l m	 Z	 m
 Z
 m Z d  d l m Z d  d l m Z d  d l m Z d  d l m Z m Z d  d	 l m Z m Z m Z d  d
 l m Z d  d l m Z d  d l m Z m Z m  Z  m! Z! m" Z" m# Z# m$ Z$ m% Z% d  d l& m' Z' d  d l( m) Z) m* Z* m+ Z+ m, Z, d  d l- m. Z. d  d l/ m0 Z0 m1 Z1 m2 Z2 d  d l3 m4 Z4 d  d l5 m6 Z6 d  d l7 m8 Z8 m9 Z9 d  d l: m; Z; m< Z< m= Z= m> Z> m? Z? d  d l@ mA ZA mB ZB d  d lC mD ZD d  d lE mF ZF d  d lG mH ZH mI ZI d  d lJ mK ZK d  d lL mM ZM d  d lN mO ZO d  d lP mQ ZQ mR ZR d  d lS mT ZT d  d lU mV ZV mW ZW d  d lX mY ZY d  d  lZ m[ Z[ m\ Z\ m] Z] d  d! l^ m_ Z` ma Za d  d" lb mc Zc d  d# ld me Ze d$ Zf d% Zg d& d' f \ Zh Zi d(   Zj d)   Zk d* el f d+     YZm i i e jn d, 6e jo d- 6e0 jp 6i e jq d- 6e0 jr 6i e js d- 6e0 jt 6i e ju d- 6e0 jv 6i e jw d- 6e0 jx 6i e jy d- 6e0 jz 6i e j{ d- 6e0 j| 6i e j} d- 6e0 j~ 6i e j d- 6e0 j 6i e j d- 6e0 j 6i e j d- 6e0 j 6Z eO ec  Z d. eM j e j  f d/     YZ eR d0 e f d1     Y Z d2 e f d3     YZ d4 e f d5     YZ d6 e f d7     YZ d S(8   i(   t   unicode_literalsN(   t   OrderedDict(   t   partialt   reducet   update_wrapper(   t   forms(   t   settings(   t   messages(   t   helperst   widgets(   t   BaseModelAdminCheckst   InlineModelAdminCheckst   ModelAdminChecks(   t   DisallowedModelAdminToField(   t   add_preserved_filters(   t   NestedObjectst   construct_change_messaget   flatten_fieldsetst   get_deleted_objectst   lookup_needs_distinctt   model_format_dictt   quotet   unquote(   t   get_permission_codename(   t   FieldDoesNotExistt
   FieldErrort   PermissionDeniedt   ValidationError(   t	   Paginator(   t   modelst   routert   transaction(   t
   LOOKUP_SEP(   t   BLANK_CHOICE_DASH(   t   DELETION_FIELD_NAMEt	   all_valid(   t   BaseInlineFormSett   inlineformset_factoryt   modelform_defines_fieldst   modelform_factoryt   modelformset_factory(   t   CheckboxSelectMultiplet   SelectMultiple(   t   HttpResponseRedirect(   t   HttpResponseBase(   t   SimpleTemplateResponset   TemplateResponse(   t   reverse(   t   six(   t   method_decorator(   t
   force_textt   python_2_unicode_compatible(   t   format_html(   t	   urlencodet   urlquote(   t	   mark_safe(   t   capfirstt   format_lazyt   get_text_list(   t   ugettextt	   ungettext(   t   csrf_protect(   t   RedirectViewu   _popupu	   _to_fieldi   i   c         C  s&   d d l  m } | j j |  d t S(   Ni(   t   ContentTypet   for_concrete_model(   t"   django.contrib.contenttypes.modelsR?   t   objectst   get_for_modelt   False(   t   objR?   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   get_content_type_for_model<   s    c         C  s   |  t  k r d Sd S(   Nu	   radiolistu   radiolist inline(   t   VERTICAL(   t   radio_style(    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   get_ul_classC   s    t   IncorrectLookupParametersc           B  s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyRJ   G   s   u
   form_classu   widgett   BaseModelAdminc           B  sI  e  Z d  Z d Z d Z d Z d Z e j	 Z
 d Z d Z i  Z i  Z i  Z d Z d Z e Z e Z e Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d d  Z d	   Z d d
  Z  d d  Z! d d  Z" d   Z# d d  Z$ d d  Z% d   Z& d   Z' d   Z( d   Z) d d  Z* d d  Z+ d   Z, RS(   u8   Functionality common to both ModelAdmin and InlineAdmin.c         K  s   |  j    j |  |  S(   N(   t   checks_classt   check(   t   selft   kwargs(    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyRO   u   s    c         C  sU   t  j t  } x6 |  j j   D]% \ } } | j | i   j |  q W| |  _ d  S(   N(   t   copyt   deepcopyt   FORMFIELD_FOR_DBFIELD_DEFAULTSt   formfield_overridest   itemst
   setdefaultt   update(   RP   t	   overridest   kt   v(    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   __init__x   s    c         K  s  | j  r |  j | | |  St | t j  s@ t | t j  rf| j |  j k rn t |  j | j |  } n  t | t j  r |  j	 | | |  } n* t | t j  r |  j
 | | |  } n  | rb| j |  j k rb|  j j j | j j  } i  } | r;| j d | j |  d | j |  d | j |   n  t j | j | j |  j |  | _ n  | SxR | j j   D]A } | |  j k rvt t j |  j |  |  } | j |   SqvW| j |   S(   u   
        Hook for specifying the form Field instance for a given database Field
        instance.

        If kwargs are given, they're passed to the form Field's constructor.
        t   can_add_relatedt   can_change_relatedt   can_delete_related(   t   choicest   formfield_for_choice_fieldt
   isinstanceR   t   ManyToManyFieldt
   ForeignKeyt	   __class__RU   t   dictt   formfield_for_foreignkeyt   formfield_for_manytomanyt   namet   raw_id_fieldst
   admin_sitet	   _registryt   gett   remote_fieldt   modelRX   t   has_add_permissiont   has_change_permissiont   has_delete_permissionR	   t   RelatedFieldWidgetWrappert   widgett   mroRR   RS   t	   formfield(   RP   t   db_fieldt   requestRQ   Rv   t   related_modeladmint   wrapper_kwargst   klass(    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   formfield_for_dbfield   s2    		$	!c         K  s   | j  |  j k r d | k rN t j d i t |  j | j   d 6 | d <n  d | k r | j d | j d d t d  f g  | d <q n  | j |   S(	   uR   
        Get a form Field for a database Field that has declared choices.
        u   widgett   attrsu   classu   choicest   include_blankt   blank_choiceu    u   None(	   Ri   t   radio_fieldsR	   t   AdminRadioSelectRI   t   get_choicest   blankt   _Rv   (   RP   Rw   Rx   RQ   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyRa      s    $		"c         C  st   |  j  j j | j j  } | d k	 rp | j |  } | d k	 rp | d k rp | j j j j |  j	 |   Sn  d S(   u   
        If the ModelAdmin specifies ordering, the queryset should respect that
        ordering.  Otherwise don't specify the queryset, let the field decide
        (returns None in that case).
        N(    (
   Rk   Rl   Rm   Rn   Ro   t   Nonet   get_orderingt   _default_managert   usingt   order_by(   RP   t   dbRw   Rx   t   related_admint   ordering(    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   get_field_queryset   s    "c         K  s   | j  d  } | j |  j k rF t j | j |  j d | | d <na | j |  j k r t j d i t	 |  j | j  d 6 | d <| j
 r t d  n d	 | d <n  d | k r |  j | | |  } | d	 k	 r | | d <q n  | j |   S(
   u4   
        Get a form Field for a ForeignKey.
        u   usingR   u   widgetR}   u   classu   Noneu   empty_labelu   querysetN(   Rm   Ri   Rj   R	   t   ForeignKeyRawIdWidgetRn   Rk   R   R   RI   R   R   R   R   Rv   (   RP   Rw   Rx   RQ   R   t   queryset(    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyRg      s    %!"c   	      K  sW  | j  j j j s d S| j d  } | j |  j k r\ t j	 | j  |  j
 d | | d <nM | j t |  j  t |  j  k r t j | j | j |  j k  | d <n  d | k r |  j | | |  } | d k	 r | | d <q n  | j |   } t | j t  rSt | j t  rSt d  } | j } | rGt d | |  n | | _ n  | S(   u9   
        Get a form Field for a ManyToManyField.
        u   usingR   u   widgetu   querysetuD   Hold down "Control", or "Command" on a Mac, to select more than one.u   {} {}N(   Rn   t   throught   _metat   auto_createdR   Rm   Ri   Rj   R	   t   ManyToManyRawIdWidgetRk   t   listt   filter_verticalt   filter_horizontalt   FilteredSelectMultiplet   verbose_nameR   Rv   Rb   Rt   R*   R)   R   t	   help_textR9   (	   RP   Rw   Rx   RQ   R   R   t
   form_fieldt   msgR   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyRh      s&    %%%	$c         C  s|   | d  k s |  j r d  St |  j  r6 |  j |  S|  j rx t | d  rx t d d i t |  j d 6| j d 6Sd  S(   Nu   get_absolute_urlu   admin:view_on_siteRQ   u   content_type_idu	   object_id(   R   t   view_on_sitet   callablet   hasattrR/   RF   t   pk(   RP   RE   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   get_view_on_site_url	  s    c         C  s6   y t  |  j  SWn t k
 r1 t  |  j j  SXd S(   uP   
        Return the empty_value_display set on ModelAdmin or AdminSite.
        N(   R7   t   empty_value_displayt   AttributeErrorRk   (   RP   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   get_empty_value_display  s    c         C  s   |  j  S(   u.   
        Hook for specifying exclude.
        (   t   exclude(   RP   Rx   RE   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   get_exclude  s    c         C  s   |  j  S(   u-   
        Hook for specifying fields.
        (   t   fields(   RP   Rx   RE   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt
   get_fields%  s    c         C  s0   |  j  r |  j  Sd i |  j | |  d 6f g S(   u0   
        Hook for specifying fieldsets.
        u   fieldsN(   t	   fieldsetsR   R   (   RP   Rx   RE   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   get_fieldsets+  s    	c         C  s   |  j  p d S(   u5   
        Hook for specifying field ordering.
        (    (   R   (   RP   Rx   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyR   3  s    c         C  s   |  j  S(   u=   
        Hook for specifying custom readonly fields.
        (   t   readonly_fields(   RP   Rx   RE   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   get_readonly_fields9  s    c         C  s   |  j  S(   uA   
        Hook for specifying custom prepopulated fields.
        (   t   prepopulated_fields(   RP   Rx   RE   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   get_prepopulated_fields?  s    c         C  s=   |  j  j j   } |  j |  } | r9 | j |   } n  | S(   u   
        Returns a QuerySet of all model instances that can be edited by the
        admin site. This is used by changelist_view.
        (   Ro   R   t   get_querysetR   R   (   RP   Rx   t   qsR   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyR   E  s
    c         C  s  d d l  m } |  j } xn | j j D]` } t |  rD |   } n  x? t j |  j   D]( \ } } | | k rZ | | k rZ t	 SqZ Wq& Wg  } d  }	 x | j t  D] }
 y | j j |
  } Wn t k
 r Pn X|	 s |	 j r| |	 j   d j k r| j |
  n  t | d d   s&Pn  | }	 | j   d j j } q Wt |  d k r\t	 St j |  } |  j g } xx |  j D]m } t | t  rt | |  r| j | j  qt | t t f  r| j | d  q| j |  qW| | k S(   Ni(   t   SimpleListFilteru   get_path_infoi   i    (   t   django.contrib.admin.filtersR   Ro   R   t   related_fkey_lookupsR   R	   t   url_params_from_lookup_dictRV   t   TrueR   t   splitR    t	   get_fieldR   t   is_relationt   get_path_infot   target_fieldst   appendt   getattrt   to_optst   lent   joint   date_hierarchyt   list_filterRb   t   typet
   issubclasst   parameter_nameR   t   tuple(   RP   t   lookupt   valueR   Ro   t	   fk_lookupRZ   R[   t   relation_partst
   prev_fieldt   partt   fieldt   clean_lookupt   valid_lookupst   filter_item(    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   lookup_allowedQ  sB    	"c           sO  |  j  j } y | j |  } Wn t k
 r3 t SX| j rA t Sx' | j D] } | j   | k rK t SqK Wt	   } xQ |  j
 j j   D]= \ } } | j |  x! | j D] }	 | j |	 j   q Wq Wd   | j d t  D }
 xd |
 D]\ } | j   | j j } t   f d   | D  r t | d  r | j   | k r t Sq Wt S(   u   
        Returns True if the model associated with this admin should be
        allowed to be referenced by the specified field.
        c         s  s(   |  ] } | j  r | j r | Vq d  S(   N(   R   t   concrete(   t   .0t   f(    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pys	   <genexpr>  s    t   include_hiddenc         3  s   |  ] } t  |    Vq d  S(   N(   R   (   R   Ro   (   t   related_model(    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pys	   <genexpr>  s    u   get_related_field(   Ro   R   R   R   RD   t   primary_keyR   t   many_to_manyt   m2m_target_field_namet   setRk   Rl   RV   t   addt   inlinesR   R   R   Rn   t   anyR   t   get_related_field(   RP   Rx   t   to_fieldt   optsR   R   t   registered_modelsRo   t   admint   inlinet   related_objectst   related_objectRn   (    (   R   s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   to_field_allowed  s0    			c         C  s5   |  j  } t d |  } | j j d | j | f  S(   u   
        Returns True if the given request has permission to add an object.
        Can be overridden by the user in subclasses.
        u   addu   %s.%s(   R   R   t   usert   has_permt	   app_label(   RP   Rx   R   t   codename(    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyRp     s    	c         C  s5   |  j  } t d |  } | j j d | j | f  S(   u  
        Returns True if the given request has permission to change the given
        Django model instance, the default implementation doesn't examine the
        `obj` parameter.

        Can be overridden by the user in subclasses. In such case it should
        return True if the given request has permission to change the `obj`
        model instance. If `obj` is None, this should return True if the given
        request has permission to change *any* object of the given type.
        u   changeu   %s.%s(   R   R   R   R   R   (   RP   Rx   RE   R   R   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyRq     s    	c         C  s5   |  j  } t d |  } | j j d | j | f  S(   u  
        Returns True if the given request has permission to change the given
        Django model instance, the default implementation doesn't examine the
        `obj` parameter.

        Can be overridden by the user in subclasses. In such case it should
        return True if the given request has permission to delete the `obj`
        model instance. If `obj` is None, this should return True if the given
        request has permission to delete *any* object of the given type.
        u   deleteu   %s.%s(   R   R   R   R   R   (   RP   Rx   RE   R   R   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyRr     s    	c         C  s   | j  j |  j j  S(   u  
        Returns True if the given request has any permission in the given
        app label.

        Can be overridden by the user in subclasses. In such case it should
        return True if the given request has permission to view the module on
        the admin index page and access the module's index page. Overriding it
        does not restrict access to the add, change or delete views. Use
        `ModelAdmin.has_(add|change|delete)_permission` for that.
        (   R   t   has_module_permsR   R   (   RP   Rx   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   has_module_permission  s    (    N(    (    (    (-   RK   RL   t   __doc__Rj   R   R   R   R   R   t	   ModelFormt   formR   R   R   R   RU   R   R   R   R   t   show_full_result_countR
   RN   RO   R\   R|   Ra   R   Rg   Rh   R   R   R   R   R   R   R   R   R   R   R   Rp   Rq   Rr   R   (    (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyRM   b   sL   				8									3	-		t
   ModelAdminc           B  sG  e  Z d  Z dA Z dB Z dC Z e Z d Z d Z	 dD Z
 dE Z dF Z e Z e Z e Z e Z e Z g  Z dF Z dF Z dF Z dF Z dF Z dF Z dF Z g  Z e j Z  e Z! e Z" e Z# e$ Z% d   Z& d   Z' dF d  Z( d   Z) e* d    Z+ e* d	    Z, d
   Z- dF d  Z. dF d  Z/ d   Z0 dF d  Z1 d   Z2 d   Z3 dF d  Z4 d e d  Z5 d   Z6 d   Z7 d   Z8 d   Z9 e: d  e9 _; d   Z< e= d  Z> d   Z? d   Z@ d   ZA d   ZB d   ZC d    ZD d!   ZE d"   ZF e d#  ZG eH jI d$ e d%  ZJ d&   ZK d'   ZL d(   ZM d)   ZN d*   ZO e e d$ dF d+  ZP dF d,  ZQ d-   ZR d.   ZS d/   ZT d0   ZU d1   ZV d2   ZW dF d3  ZX d4   ZY d5   ZZ e[ dF d$ dF d6   Z\ d7   Z] d$ dF d8  Z^ d$ dF d9  Z_ d:   Z` d;   Za e[ dF d<   Zb e[ dF d=   Zc d>   Zd dF d?  Ze d@   Zf RS(G   uC   Encapsulates all admin options and functionality for a given model.u   __str__id   i   c         C  s5   | |  _  | j |  _ | |  _ t t |   j   d  S(   N(   Ro   R   R   Rk   t   superR   R\   (   RP   Ro   Rk   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyR\     s    		c         C  s   d |  j  j j |  j j f S(   Nu   %s.%s(   Ro   R   R   Re   RK   (   RP   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   __str__  s    c         C  s   g  } x |  j  D] } | |  j |  j  } | r | j |  pa | j | |  pa | j | |  sj q n  | j |  s d | _ q n  | j |  q W| S(   Ni    (   R   Ro   Rk   Rp   Rq   Rr   t   max_numR   (   RP   Rx   RE   t   inline_instancest   inline_classR   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   get_inline_instances  s    c           s  d d l  m }   f d   }   j j j   j j j f } | d |   j  d d | | d |   j  d d | | d	 |   j  d d
 | | d |   j	  d d | | d |   j
  d d | | d | t j d d   j j f |    g } | S(   Ni(   t   urlc           s(      f d   }  | _  t |    S(   Nc            s     j  j   |  |   S(   N(   Rk   t
   admin_view(   t   argsRQ   (   RP   t   view(    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   wrapper'  s    (   t   model_adminR   (   R   R   (   RP   (   R   s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   wrap&  s    	u   ^$Ri   u   %s_%s_changelistu   ^add/$u	   %s_%s_addu   ^(.+)/history/$u   %s_%s_historyu   ^(.+)/delete/$u   %s_%s_deleteu   ^(.+)/change/$u   %s_%s_changeu   ^(.+)/$t   pattern_nameu   %s:%s_%s_change(   t   django.conf.urlsR   Ro   R   R   t
   model_namet   changelist_viewt   add_viewt   history_viewt   delete_viewt   change_viewR>   t   as_viewRk   Ri   (   RP   R   R   t   infot   urlpatterns(    (   RP   s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   get_urls#  s    #c         C  s
   |  j    S(   N(   R  (   RP   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   urls;  s    c      	   C  sj   t  j r d n d } d d | d d d | d d	 | d
 | g } t j d g  | D] } d | ^ qS  S(   Nu    u   .minu   core.jsu   vendor/jquery/jquery%s.jsu   jquery.init.jsu   admin/RelatedObjectLookups.jsu   actions%s.jsu	   urlify.jsu   prepopulate%s.jsu   vendor/xregexp/xregexp%s.jst   jsu   admin/js/%s(   R   t   DEBUGR   t   Media(   RP   t   extraR
  R   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   media?  s    c         C  s4   i |  j  |  d 6|  j |  d 6|  j |  d 6S(   u   
        Returns a dict of all perms for this model. This dict has the keys
        ``add``, ``change``, and ``delete`` mapping to the True/False for each
        of those actions.
        u   addu   changeu   delete(   Rp   Rq   Rr   (   RP   Rx   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   get_model_permsN  s    c         C  sK   |  j  r |  j  S|  j | | d d  } t | j  t |  j | |   S(   NR   (   R   t   get_formR   R   t   base_fieldsR   (   RP   Rx   RE   R   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyR   Z  s    	c           s  d | k r | j  d  } n t   j | |   }   j | |  } | d	 k rZ g  n	 t |  }   j | |  } | j |  | d	 k r t   j	 d  r   j	 j
 j r | j   j	 j
 j  n  | p d	 } t   f d   | D  } t   j	 j   j	 f |  }	 i |	 d 6| d 6| d 6t   j d | d 6}
 |
 j |  |
 d d	 k rt |
 d  rt j |
 d <n  y t   j |
  SWn/ t k
 r} t d |   j j f   n Xd	 S(
   uw   
        Returns a Form class for use in the admin add view. This is used by
        add_view and change_view.
        u   fieldsu   _metac         3  s-   |  ]# } |   j  j k r | d  f Vq d  S(   N(   R   t   declared_fieldsR   (   R   R   (   RP   (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pys	   <genexpr>w  s    u   formu   excludeRx   u   formfield_callbacku:   %s. Check fields/fieldsets/exclude attributes of class %s.N(   t   popR   R   R   R   R   R   t   extendR   R   R   R   R   R   RK   R   R|   RX   R&   R   t
   ALL_FIELDSR'   Ro   R   Re   (   RP   Rx   RE   RQ   R   t   excludedR   R   t	   new_attrsR   t   defaultst   e(    (   RP   s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyR  `  s6    -!c         K  s   d d l  m } | S(   uN   
        Returns the ChangeList class for use on the changelist page.
        i(   t
   ChangeList(   t   django.contrib.admin.views.mainR  (   RP   Rx   RQ   R  (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   get_changelist  s    c         C  s   |  j  |  } | j } | d k r0 | j j n | j j |  } y* | j |  } | j i | | j 6  SWn | j	 t
 t f k
 r d SXd S(   u   
        Returns an instance matching the field and value provided, the primary
        key is used if no field is provided. Returns ``None`` if no match is
        found or the object_id fails validation.
        N(   R   Ro   R   R   R   R   t	   to_pythonRm   Ri   t   DoesNotExistR   t
   ValueError(   RP   Rx   t	   object_idt
   from_fieldR   Ro   R   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt
   get_object  s    	*c         K  st   i t  |  j d | d 6} | j |  | j d  d k rd t | j d   rd t j | d <n  t |  j	 |  S(   uU   
        Returns a Form class for use in the Formset on the changelist page.
        Rx   u   formfield_callbacku   fieldsu   formN(
   R   R|   RX   Rm   R   R&   R   R  R'   Ro   (   RP   Rx   RQ   R  (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   get_changelist_form  s    +c         K  sT   i t  |  j d | d 6} | j |  t |  j |  j |  d d d |  j | S(   uj   
        Returns a FormSet class for use on the changelist page if list_editable
        is used.
        Rx   u   formfield_callbackR  i    R   (   R   R|   RX   R(   Ro   R#  t   list_editable(   RP   Rx   RQ   R  (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   get_changelist_formset  s    c         c  s8   x1 |  j  | |  D] } | j | |  | f Vq Wd S(   u@   
        Yields formsets and the corresponding inlines.
        N(   R   t   get_formset(   RP   Rx   RE   R   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   get_formsets_with_inlines  s    i    c         C  s   |  j  | | | |  S(   N(   t	   paginator(   RP   Rx   R   t   per_paget   orphanst   allow_empty_first_page(    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   get_paginator  s    c         C  s_   d d l  m } m } | j j d | j j d t |  j d | j d t |  d | d |  S(	   u   
        Log that an object has been successfully added.

        The default implementation creates an admin LogEntry object.
        i(   t   LogEntryt   ADDITIONt   user_idt   content_type_idR   t   object_reprt   action_flagt   change_message(	   t   django.contrib.admin.modelsR-  R.  RB   t
   log_actionR   R   RF   R2   (   RP   Rx   t   objectt   messageR-  R.  (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   log_addition  s    	c         C  s_   d d l  m } m } | j j d | j j d t |  j d | j d t |  d | d |  S(	   u   
        Log that an object has been successfully changed.

        The default implementation creates an admin LogEntry object.
        i(   R-  t   CHANGER/  R0  R   R1  R2  R3  (	   R4  R-  R9  RB   R5  R   R   RF   R2   (   RP   Rx   R6  R7  R-  R9  (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt
   log_change  s    	c         C  sS   d d l  m } m } | j j d | j j d t |  j d | j d | d |  S(   u   
        Log that an object will be deleted. Note that this method must be
        called before the deletion.

        The default implementation creates an admin LogEntry object.
        i(   R-  t   DELETIONR/  R0  R   R1  R2  (   R4  R-  R;  RB   R5  R   R   RF   (   RP   Rx   R6  R1  R-  R;  (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   log_deletion  s    	c         C  s   t  j j t  j t | j   S(   uE   
        A list_display column containing a checkbox widget.
        (   R   t   checkboxt   rendert   ACTION_CHECKBOX_NAMER2   R   (   RP   RE   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   action_checkbox  s    u,   <input type="checkbox" id="action-toggle" />c           s    j  d k s t | j k r% t   Sg  } xN   j j  D]@ \ } } t | d | j d d   } | j | | | f  q8 Wx_   j	 j
   d d d  D]A } t | d g   } | s q n  | j   f d   | D  q Wt d |  } t d   | D  } | S(	   u   
        Return a dictionary mapping the names of all actions for this
        ModelAdmin to a tuple of (callable, name, description) for each action.
        u   short_descriptionu   _u    Niu   actionsc         3  s   |  ] }   j  |  Vq d  S(   N(   t
   get_action(   R   t   action(   RP   (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pys	   <genexpr>  s    c         s  s-   |  ]# \ } } } | | | | f f Vq d  S(   N(    (   R   t   funcRi   t   desc(    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pys	   <genexpr>   s   (   t   actionsR   t   IS_POPUP_VARt   GETR   Rk   R   t   replaceR   Re   Ru   R  t   filter(   RP   Rx   RE  Ri   RC  t   descriptionR{   t   class_actions(    (   RP   s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   get_actions  s     #!c         C  s`   g  | } xO t  j |  j |   D]5 \ } } } | | t |  j  f } | j |  q# W| S(   uy   
        Return a list of choices for use in a form object.  Each choice is a
        tuple (name, description).
        (   R0   t
   itervaluesRL  R   R   R   (   RP   Rx   t   default_choicesR`   RC  Ri   RJ  t   choice(    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   get_action_choices&  s
    
(c         C  s   t  |  r | } | j } nR t |  j |  rE t |  j |  } n+ y |  j j |  } Wn t k
 ro d SXt | d  r | j	 } n t
 | j d d   } | | | f S(   u   
        Return a given action from a parameter, which can either be a callable,
        or the name of a method on the ModelAdmin.  Return is a tuple of
        (callable, name, description).
        u   short_descriptionu   _u    N(   R   RK   R   Re   R   Rk   RA  t   KeyErrorR   t   short_descriptionR8   RH  (   RP   RB  RC  RJ  (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyRA  1  s    c         C  s   |  j  S(   ud   
        Return a sequence containing the fields to be displayed on the
        changelist.
        (   t   list_display(   RP   Rx   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   get_list_displayO  s    c         C  s8   |  j  s |  j  d k s | r& |  j  St |  d  Sd S(   u   
        Return a sequence containing the fields to be displayed as links
        on the changelist. The list_display parameter is the list of fields
        returned by get_list_display().
        i   N(   t   list_display_linksR   R   (   RP   Rx   RS  (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   get_list_display_linksV  s    c         C  s   |  j  S(   u   
        Returns a sequence containing the fields to be displayed as filters in
        the right sidebar of the changelist page.
        (   R   (   RP   Rx   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   get_list_filterb  s    c         C  s   |  j  S(   uu   
        Returns a list of fields to add to the select_related() part of the
        changelist items query.
        (   t   list_select_related(   RP   Rx   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   get_list_select_relatedi  s    c         C  s   |  j  S(   u{   
        Returns a sequence containing the fields to be searched whenever
        somebody submits a search query.
        (   t   search_fields(   RP   Rx   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   get_search_fieldsp  s    c         C  s   d   } t  } |  j |  } | r | r g  | D] } | t |   ^ q1 } xX | j   D]J }	 g  | D] }
 t j i |	 |
 6  ^ qi } | j t t j	 |   } q\ W| s x- | D]" } t
 |  j |  r t } Pq q Wq n  | | f S(   u   
        Returns a tuple containing a queryset to implement the search,
        and a boolean indicating if the results may contain duplicates.
        c         S  s]   |  j  d  r d |  d S|  j  d  r6 d |  d S|  j  d  rQ d |  d Sd |  Sd  S(	   Nu   ^u   %s__istartswithi   u   =u
   %s__iexactu   @u
   %s__searchu   %s__icontains(   t
   startswith(   t
   field_name(    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   construct_search}  s    (   RD   R[  t   strR   R   t   QRI  R   t   operatort   or_R   R   R   (   RP   Rx   R   t   search_termR^  t   use_distinctRZ  t   search_fieldt   orm_lookupst   bitt
   orm_lookupt
   or_queriest   search_spec(    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   get_search_resultsw  s     	
"&c         C  s   | j  } |  j r | r |  j j } d | j | j f } d | j | j f } | | k rn | j j	   } n | j j
 d  } | r t	 i | d 6 Sn  d S(   u<   
        Returns the preserved filters querystring.
        u   %s:%su   admin:%s_%s_changelistu   _changelist_filtersu    (   t   resolver_matcht   preserve_filtersRo   R   t   app_namet   url_nameR   R   RG  R5   Rm   (   RP   Rx   t   matchR   t   current_urlt   changelist_urlt   preserved_filters(    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   get_preserved_filters  s    	c         C  s   t  | | |  S(   uV   
        Construct a JSON structure describing changes from a changed object.
        (   R   (   RP   Rx   R   t   formsetsR   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyR     s    u    c         C  s   t  | t  s y t t j | j    } Wq t k
 r t j j j   } d j	 d   | D  } t
 d | | f   q Xn  t j | | | d | d | d S(   u  
        Send a message to the user. The default implementation
        posts a message using the django.contrib.messages backend.

        Exposes almost the same API as messages.add_message(), but accepts the
        positional arguments in a different order to maintain backwards
        compatibility. For convenience, it accepts the `level` argument as
        a string rather than the usual level number.
        u   , c         s  s   |  ] } d  | Vq d S(   u   `%s`N(    (   R   t   l(    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pys	   <genexpr>  s    u7   Bad message level string: `%s`. Possible values are: %st
   extra_tagst   fail_silentlyN(   Rb   t   intR   R   t	   constantst   upperR   t   DEFAULT_TAGSt   valuesR   R  t   add_message(   RP   Rx   R7  t   levelRw  Rx  t   levelst   levels_repr(    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   message_user  s    c         C  s   | j  d t  S(   u   
        Given a ModelForm return an unsaved instance. ``change`` is True if
        the object is being changed, and False if it's being added.
        t   commit(   t   saveRD   (   RP   Rx   R   t   change(    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt	   save_form  s    c         C  s   | j    d S(   uA   
        Given a model instance save it to the database.
        N(   R  (   RP   Rx   RE   R   R  (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt
   save_model  s    c         C  s   | j    d S(   uE   
        Given a model instance delete it from the database.
        N(   t   delete(   RP   Rx   RE   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   delete_model  s    c         C  s   | j    d S(   uB   
        Given an inline formset save it to the database.
        N(   R  (   RP   Rx   R   t   formsetR  (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   save_formset  s    c         C  s8   | j    x' | D] } |  j | | | d | q Wd S(   uO  
        Given the ``HttpRequest``, the parent ``ModelForm`` instance, the
        list of inline formsets and a boolean value based on whether the
        parent is being added or changed, save the related objects to the
        database. Note that at this point save_form() and save_model() have
        already been called.
        R  N(   t   save_m2mR  (   RP   Rx   R   Ru  R  R  (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   save_related  s    
c         C  so  |  j  j } | j } |  j |  }	 t i |	 d 6| d 6|  } |  j |  }
 | j i | d 6| d 6|  j |  d 6|  j | |  d 6|  j	 | |  d 6t
 d 6|
 d  k	 d	 6|
 d
 6| d 6| d 6t |  j   j d 6|  j d 6|  j d 6t d 6t d 6| d 6 | r'|  j d  k	 r'|  j } n	 |  j } |  j j | _ t | | phd | | j f d | d g |  S(   Nu   preserved_filtersu   optsu   addu   changeu   has_add_permissionu   has_change_permissionu   has_delete_permissionu   has_file_fieldu   has_absolute_urlu   absolute_urlu   form_urlu   content_type_idu   save_asu   save_on_topu   to_field_varu   is_popup_varu	   app_labelu   admin/%s/%s/change_form.htmlu   admin/%s/change_form.htmlu   admin/change_form.html(   Ro   R   R   Rt  R   R   RX   Rp   Rq   Rr   R   R   RF   R   t   save_ast   save_on_topt   TO_FIELD_VARRF  t   add_form_templatet   change_form_templateRk   Ri   t   current_appR.   R   (   RP   Rx   t   contextR   R  t   form_urlRE   R   R   Rs  t   view_on_site_urlt   form_template(    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   render_change_form  s>    		

	c         C  s  | j  } | j   } |  j |  } t d | j | j f d t |  f d |  j j } |  j	 | |  r t
 d t |  |  } n t |  } i t | j  d 6| d 6}	 t | j k rt| j j t  }
 |
 r t |
  } n | j  j j } | j |  } t j i t j |  d 6t j |  d 6 } t | |  j pfd | j | j f d	 | j d
 g i | d 6 Sd | j k sd | j k r|  j r|  j	 | |  rt
 t d  |	  } |  j | | t j   | d k r| } n  t" i | d 6| d 6|  } t# |  Sd | j k r~t
 t d  |	  } |  j | | t j   | j$ } t" i | d 6| d 6|  } t# |  St
 t d  |	  } |  j | | t j   |  j% | |  Sd S(   uE   
        Determines the HttpResponse for the add_view stage.
        u   admin:%s_%s_changeR   R  u   <a href="{}">{}</a>u   nameu   obju   valueu   admin/%s/%s/popup_response.htmlu   admin/%s/popup_response.htmlu   admin/popup_response.htmlu   popup_response_datau	   _continueu
   _saveasnewuG   The {name} "{obj}" was added successfully. You may edit it again below.u   preserved_filtersu   optsu   _addanotheruL   The {name} "{obj}" was added successfully. You may add another {name} below.u*   The {name} "{obj}" was added successfully.N(&   R   t   _get_pk_valRt  R/   R   R   R   Rk   Ri   Rq   R4   R6   R2   R   RF  t   POSTRm   R  R_  R   t   attnamet   serializable_valuet   jsont   dumpsR0   t	   text_typeR.   t   popup_response_templatet   save_as_continueR   R  R   t   SUCCESSR   R   R+   t   patht   response_post_save_add(   RP   Rx   RE   t   post_url_continueR   t   pk_valueRs  t   obj_urlt   obj_reprt   msg_dictR   t   attrR   t   popup_response_dataR   t   redirect_url(    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   response_add  sl    	
	
				
			
		c         C  s
  t  | j k r | j } | j j t  } | r< t |  n	 | j j } | j j	 d } | j
 |  } t j i d d 6t j |  d 6t j |  d 6t j |  d 6 } t | |  j p d | j | j f d | j d	 g i | d
 6 S|  j j } | j   }	 |  j |  }
 i t | j  d 6t d t | j  |  d 6} d | j k rt t d  |  } |  j | | t j  | j } t i |
 d 6| d 6|  } t  |  Sd | j k rBt t d  |  } |  j | | t j  t! d | j | j f d |	 f d |  j" j# } t i |
 d 6| d 6|  } t  |  Sd | j k rt t d  |  } |  j | | t j  t! d | j | j f d |  j" j# } t i |
 d 6| d 6|  } t  |  St t d  |  } |  j | | t j  |  j$ | |  Sd S(   uH   
        Determines the HttpResponse for the change_view stage.
        i    u   changeu   actionu   valueu   obju	   new_valueu   admin/%s/%s/popup_response.htmlu   admin/%s/popup_response.htmlu   admin/popup_response.htmlu   popup_response_datau   nameu   <a href="{}">{}</a>u	   _continueuI   The {name} "{obj}" was changed successfully. You may edit it again below.u   preserved_filtersu   optsu
   _saveasnewuG   The {name} "{obj}" was added successfully. You may edit it again below.u   admin:%s_%s_changeR   R  u   _addanotheruN   The {name} "{obj}" was changed successfully. You may add another {name} below.u   admin:%s_%s_addu,   The {name} "{obj}" was changed successfully.N(%   RF  R  R   Rm   R  R_  R   R  Rl  R   R  R  R  R0   R  R.   R  R   R   Ro   R  Rt  R2   R   R4   R6   R  R   R  R   R  R   R+   R/   Rk   Ri   t   response_post_save_change(   RP   Rx   RE   R   R   R  R   t	   new_valueR  R  Rs  R  R   R  (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   response_changeb  sr    		
			
			
		
		c         C  s   |  j  j } |  j | d  ru t d | j | j f d |  j j } |  j	 |  } t
 i | d 6| d 6|  } n t d d |  j j } t |  S(   uy   
        Figure out where to redirect after the 'Save' button has been pressed
        when adding a new object.
        u   admin:%s_%s_changelistR  u   preserved_filtersu   optsu   admin:indexN(   Ro   R   Rq   R   R/   R   R   Rk   Ri   Rt  R   R+   (   RP   Rx   RE   R   t   post_urlRs  (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyR    s     	c         C  s   |  j  j } |  j | d  ru t d | j | j f d |  j j } |  j	 |  } t
 i | d 6| d 6|  } n t d d |  j j } t |  S(   u   
        Figure out where to redirect after the 'Save' button has been pressed
        when editing an existing object.
        u   admin:%s_%s_changelistR  u   preserved_filtersu   optsu   admin:indexN(   Ro   R   Rq   R   R/   R   R   Rk   Ri   Rt  R   R+   (   RP   Rx   RE   R   R  Rs  (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyR    s     	c         C  s  y t  | j j d d   } Wn t k
 r8 d } n X| j j   } | j t j d	  | j d d	  y% | j	 i | j
 d  | d 6 Wn t k
 r n X|  j | d d	 } |  j |  | j d _ | j   r| j d } | j d } |  j |  | d } | j j
 t j  }	 |	 rX| rXt d  }
 |  j | |
 t j  d	 S| ss| j d |	  } n  | |  | |  } t | t  r| St | j    Sn& t d  }
 |  j | |
 t j  d	 Sd	 S(
   u   
        Handle an admin action. This is called if a request is POSTed to the
        changelist; it returns an HttpResponse if the action was handled, and
        None otherwise.
        u   indexi    u   actiont   auto_idu   select_acrossuW   Items must be selected in order to perform actions on them. No items have been changed.t   pk__inu   No action selected.N(   Ry  R  Rm   R  RR   R  R   R?  R   RX   t   getlistt
   IndexErrort   action_formRP  R   R`   t   is_validt   cleaned_dataRL  R   R  R   t   WARNINGRI  Rb   R,   R+   t   get_full_path(   RP   Rx   R   t   action_indext   dataR  RB  t   select_acrossRC  t   selectedR   t   response(    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   response_action  s>    

%c         C  sF  |  j  j } t | j k r~ t j i d d 6t |  d 6 } t | |  j pp d | j	 | j
 f d | j	 d g i | d 6 S|  j | t d  i t | j  d	 6t |  d
 6t j  |  j | d  r$t d | j	 | j
 f d |  j j } |  j |  } t i | d 6| d 6|  } n t d d |  j j } t |  S(   uH   
        Determines the HttpResponse for the delete_view stage.
        u   deleteu   actionu   valueu   admin/%s/%s/popup_response.htmlu   admin/%s/popup_response.htmlu   admin/popup_response.htmlu   popup_response_datau0   The %(name)s "%(obj)s" was deleted successfully.u   nameu   obju   admin:%s_%s_changelistR  u   preserved_filtersu   optsu   admin:indexN(   Ro   R   RF  R  R  R  R_  R.   R  R   R   R  R   R2   R   R   R  Rq   R   R/   Rk   Ri   Rt  R   R+   (   RP   Rx   t   obj_displayt   obj_idR   R  R  Rs  (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   response_delete  s4    	

c         C  s}   |  j  j } | j } |  j j | _ | j d t d t d |  j	  t
 | |  j pv d j | | j  d j |  d g |  S(   Nt   to_field_vart   is_popup_varR  u$   admin/{}/{}/delete_confirmation.htmlu!   admin/{}/delete_confirmation.htmlu   admin/delete_confirmation.html(   Ro   R   R   Rk   Ri   R  RX   R  RF  R  R.   t   delete_confirmation_templatet   formatR   (   RP   Rx   R  R   R   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   render_delete_form?  s    		
	c      	   C  s   g  } x t  | |  D] \ } } t | j | |   } t | j | |   }	 t | j | |   }
 t j | | | |
 |	 d |  } | j |  q W| S(   NR   (	   t   zipR   R   R   Rf   R   R   t   InlineAdminFormSetR   (   RP   Rx   Ru  R   RE   t   inline_admin_formsetsR   R  R   t   readonlyt   prepopulatedt   inline_admin_formset(    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   get_inline_formsetsT  s    	c         C  s   t  | j j    } xj | D]b } y |  j j j |  } Wn t k
 rQ q n Xt | t j	  r | | j
 d  | | <q q W| S(   uk   
        Get the initial form data.
        Unless overridden, this populates from the GET params.
        u   ,(   Rf   RG  RV   Ro   R   R   R   Rb   R   Rc   R   (   RP   Rx   t   initialRZ   R   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   get_changeform_initial_dataa  s    c         C  se   t  d  i t | j  d 6t |  d 6} |  j | | t j  t d d |  j j	 } t
 |  S(   u   
        Create a message informing the user that the object doesn't exist
        and return a redirect to the admin index page.
        uA   %(name)s with ID "%(key)s" doesn't exist. Perhaps it was deleted?u   nameu   keyu   admin:indexR  (   R   R2   R   R   R  R   R  R/   Rk   Ri   R+   (   RP   Rx   R   R   R   R   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt    _get_obj_does_not_exist_redirectq  s    c      	   C  s?   t  j d t j |  j    |  j | | | |  SWd  QXd  S(   NR   (   R   t   atomicR   t   db_for_writeRo   t   _changeform_view(   RP   Rx   R   R  t   extra_context(    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   changeform_view~  s    c         C  s}  | j  j t | j j t   } | rM |  j | |  rM t d |   n  |  j } | j } | j d k r d | j  k r d  } n  | d  k } | r |  j
 |  s t  n  d  }	 nU |  j | t |  |  }	 |  j | |	  s t  n  |	 d  k r|  j | | |  S|  j | |	  }
 | j d k rV|
 | j  | j d |	 } | j   rxt } |  j | | d | } n t } | j } |  j | | d | \ } } t |  rM| rM|  j | | | |  |  j | | | |  |  j | | | |  } | r'|  j | | |  |  j | |  S|  j | | |  |  j | |  Sqt } nu | r|  j  |  } |
 d |  } |  j | | j d t \ } } n- |
 d |	  } |  j | |	 d t \ } } t! j" | t# |  j$ | |	   |  j% | |	  |  j& | |	  d |  } |  j' | j' } |  j( | | | |	  } x | D] } | | j' } qBWt) |  j* j+ |  d | rt, d	  n	 t, d
  t- | j.  d | d | d |	 d t/ | j  k pt/ | j k d | d | d | d t! j0 | |  d |  j1 |  
} | j d k rA| rAd | j  k rAt | d <t | d <t } n  | j2 | pPi   |  j3 | | d | d | d |	 d | S(   Nu"   The field %s cannot be referenced.u   POSTu
   _saveasnewt   instanceR  R  R   t   titleu   Add %su	   Change %st	   adminformR   t   originalt   is_popupR   R  R  t   errorsRs  u	   show_saveu   show_save_and_continueR   RE   R  (4   R  Rm   R  RG  R   R   Ro   R   t   methodR   Rp   R   R"  R   Rq   R  R  t   FILESR  R   R  RD   R  t   _create_formsetsR#   R  R  R   R8  R  R:  R  R  R   t	   AdminFormR   R   R   R   R  R  Rf   Rk   t   each_contextR   R2   R   RF  t   AdminErrorListRt  RX   R  (   RP   Rx   R   R  R  R   Ro   R   R   RE   R   R   t   form_validatedt
   new_objectRu  R   R3  R  t	   adminFormR  t   inline_formsetst   inline_formsetR  (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyR    s    !								$	+%

	c         C  s   |  j  | d  | |  S(   N(   R  R   (   RP   Rx   R  R  (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyR    s    c         C  s   |  j  | | | |  S(   N(   R  (   RP   Rx   R   R  R  (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyR    s    c         C  s\   t  j d j | |  j j j j   } g  | j j   D]! \ } } | j	 |  r7 | ^ q7 S(   u6   Return POST data values of list_editable primary keys.u
   {}-\d+-{}$(
   t   ret   compileR  Ro   R   R   Ri   R  RV   Rp  (   RP   Rx   t   prefixt
   pk_patternt   keyR   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   _get_edited_object_pks  s    'c         C  sw   |  j  | |  } |  j |  } | j j j j } y x | D] } | |  q= WWn t k
 rf | SX| j d |  S(   ur   
        Based on POST data, return a queryset of the objects that were edited
        via list_editable.
        R  (   R  R   Ro   R   R   R  R   RI  (   RP   Rx   R  t
   object_pksR   t   validateR   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   _get_list_editable_queryset  s    c      !   C  s8  d d l  m } |  j j } | j } |  j | d0  s@ t  n  |  j |  } |  j	 | |  } |  j
 |  } |  j |  }	 |  j |  }
 |  j |  } | r d g t |  } n  |  j |  } y@ | | |  j | | | |  j |	 |
 |  j |  j |  j |   } WnV t k
 r`| | j j   k rGt d i t d  d 6 St | j d | d  SXt } | j j t j  } | r| j  d	 k rd
 | j k rd | j k r| r|  j! | d | j" |  } | r| St# } qt d  } |  j$ | | t% j&  t# } n  | r| j  d	 k rt j | j k rd
 | j k rd | j k r| r|  j! | d | j" |  } | r| St# } qn  | rt | j'    Sd0 } | _( | j  d	 k rg| j rgd | j k rg|  j) |  } |  j* | | j+    } | | j | j, d | } | _( | j-   rd } x | j. D] } | j/   r?|  j0 | | d t# } |  j1 | | | d t# |  j2 | | d g  d t# |  j3 | | d0  } |  j4 | | |  | d 7} q?q?W| rT| d k rt5 | j6  } n t5 | j7  } t8 d d |  i | d 6| d 6t5 |  d 6} |  j$ | | t% j9  n  t | j'    Sn4 | j r|  j) |  } | d | j:  } | _( n  | r|  j; | j; } n	 |  j; } | r|  j< d d0  } |  j= |  | j> d _? | | j; 7} n d0 } t8 d d | j@  } tA |  jB jC |  d t5 | j7  d t d  i tD | j:  d 6d | i | j@ d  6d! | jE d" | jF d# | jG d$ | d% | d& |  jH |  d' | jI d( | d) |  jJ d* |  jK d+ |  jL d, |  jM |  } | jN | pi   |  jB jO | _P tQ | |  jR p1d- | | jS f d. | d/ g |  S(1   u>   
        The 'change list' admin view for this model.
        i(   t
   ERROR_FLAGu   action_checkboxu   admin/invalid_setup.htmlu   Database erroru   titleu   ?u   =1u   POSTu   indexu   _saveR   uW   Items must be selected in order to perform actions on them. No items have been changed.i    R  Ru  i   u,   %(count)s %(name)s was changed successfully.u-   %(count)s %(name)s were changed successfully.u   countu   nameu   objR  u   actionu   %(total_count)s selectedu   All %(total_count)s selectedt   module_namet   selection_noteu   0 of %(cnt)s selectedu   cntt   selection_note_allu   total_countR  R  R   t   clR  Rp   R   R  t   actions_on_topt   actions_on_bottomt   actions_selection_counterRs  u   admin/%s/%s/change_list.htmlu   admin/%s/change_list.htmlu   admin/change_list.htmlN(T   R  R  Ro   R   R   Rq   R   R   RT  RV  RW  R[  RY  RL  R   R  R   t   list_per_paget   list_max_show_allR$  RJ   RG  t   keysR-   R   R+   R  RD   R  R  R   R?  R  R  R   R   R  R   R  R  R  R%  R  t   get_default_prefixR  R  R   t   has_changedR  R  R  R   R:  R2   R   t   verbose_name_pluralR<   R  t   result_listR  R  RP  R   R`   t   result_countRf   Rk   R  R   R  R  R   Rp   R   R  R  R  Rt  RX   Ri   R  R.   t   change_list_templateR   (   RP   Rx   R  R  R   R   RS  RU  R   RZ  RX  RE  R  R  t   action_failedR  R  R   R  t   FormSett   modified_objectst   changecountR   RE   t
   change_msgRi   R  R  R  R  (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyR     s    					'"		 							c         C  s<   t  j d t j |  j    |  j | | |  SWd  QXd  S(   NR   (   R   R  R   R  Ro   t   _delete_view(   RP   Rx   R   R  (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyR    s    c         C  su  |  j  j } | j } | j j t | j j t   } | rb |  j | |  rb t d |   n  |  j	 | t
 |  |  } |  j | |  s t  n  | d k r |  j | | |  St j |  j   } t | g | | j |  j |  \ }	 }
 } } | j r| r| rt  n  t |  } | r3t |  n	 | j j } | j |  } |  j | | |  |  j | |  |  j | | |  St | j  } | s| rt d  i | d 6} n t d  } t |  j j |  d | d | d | d |	 d	 t |
  j    d
 | d | d | d | d |  j! |  d t" | j k pFt" | j k d | } | j# | pai   |  j$ | |  S(   u'   The 'delete' admin view for this model.u"   The field %s cannot be referenced.u   Cannot delete %(name)su   nameu   Are you sure?R  t   object_nameR6  t   deleted_objectst   model_countt   perms_lackingt	   protectedR   R   Rs  R  R   N(%   Ro   R   R   R  Rm   R  RG  R   R   R"  R   Rr   R   R   R  R   R  R   R   Rk   R2   R_  R   R  R  R<  R  R  R   R   Rf   R  RV   Rt  RF  RX   R  (   RP   Rx   R   R  R   R   R   RE   R   R
  R  t   perms_neededR  R  R  R  R	  R  R  (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyR    sV    	!	*		c         C  so  d d l  m } |  j } |  j | t |   } | d k rS |  j | | j |  S|  j | |  sn t	  n  | j } | j
 } | j j d t |  d t |   j   j d  }	 t |  j j |  d t d  t |  d |	 d	 t t | j   d
 | d | d |  j |  }
 |
 j | p)i   |  j j | _ t | |  j phd | | j f d | d g |
  S(   u(   The 'history' admin view for this model.i(   R-  R   t   content_typeu   action_timeR  u   Change history: %st   action_listR  R6  R   Rs  u   admin/%s/%s/object_history.htmlu   admin/%s/object_history.htmlu   admin/object_history.htmlN(   R4  R-  Ro   R"  R   R   R  R   Rq   R   R   RB   RI  RF   t   select_relatedR   Rf   Rk   R  R   R2   R8   R  Rt  RX   Ri   R  R.   t   object_history_templateR   (   RP   Rx   R   R  R-  Ro   RE   R   R   R  R  (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyR    s8    					c         C  s<  g  } g  } i  } | g } | r1 | j  |  n  x |  j |   D] \ } }	 | j   }
 | j |
 d  d | |
 <| |
 d k s |
 r d |
 | |
 f }
 n  i | d 6|
 d 6|	 j |  d 6} | j d k r| j i | j j   d 6| j	 d	 6d
 | j k d 6 n  | j  | |    | j  |	  qA W| | f S(   u9   Helper function to generate formsets for add/change_view.i    i   u   %s-%su   instanceu   prefixu   querysetu   POSTu   datau   filesu
   _saveasnewu   save_as_new(
   R   R'  R  Rm   R   R  RX   R  RR   R  (   RP   Rx   RE   R  Ru  R   t   prefixest   get_formsets_argsR  R   R  t   formset_params(    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyR    s.    		
(   u   __str__(    (    (    (    N(g   RK   RL   R   RS  RU  R   RD   RX  R  R  R$  RZ  R   R   R  R   R  R  R   R(  Rm  R   R  R  R  R  t%   delete_selected_confirmation_templateR  R  RE  R   t
   ActionFormR  R  R  R  R   RN   R\   R   R   R  t   propertyR	  R  R  R   R  R  R"  R#  R%  R'  R,  R8  R:  R<  R@  R7   RR  RL  R!   RP  RA  RT  RV  RW  RY  R[  Rk  Rt  R   R   t   INFOR  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  t   csrf_protect_mR  R  R  R  R  R  R   R  R  R  R  (    (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyR     s   					/								%							!							%O	M			C	*				a			>'t   InlineModelAdminc           B  s   e  Z d  Z d Z d Z e Z d Z d Z	 d Z
 d Z d Z d Z e Z e Z e Z d Z d   Z e d    Z d d  Z d d  Z d d  Z d d  Z d d  Z d	   Z d
   Z d d  Z d d  Z  RS(   u   
    Options for inline editing of ``model`` instances.

    Provide ``fk_name`` to specify the attribute name of the ``ForeignKey``
    from ``model`` to its parent. This is required if ``model`` has more than
    one ``ForeignKey`` to its parent.
    i   c         C  s   | |  _  | |  _ |  j j |  _ | j |  j  |  _ t t |   j	   |  j
 d  k rm |  j j j
 |  _
 n  |  j d  k r |  j j j |  _ n  d  S(   N(   Rk   t   parent_modelRo   R   R   t   is_registeredt   has_registered_modelR   R  R\   R   R   R  (   RP   R  Rk   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyR\   K  s    		c         C  s   t  j r d n d } d | d d | g } |  j s> |  j rT | j d d g  n  |  j r d |  j k r | j d	 |  n  t j d
 g  | D] } d | ^ q  S(   Nu    u   .minu   vendor/jquery/jquery%s.jsu   jquery.init.jsu   inlines%s.jsu   SelectBox.jsu   SelectFilter2.jsu   collapseu   collapse%s.jsR
  u   admin/js/%s(	   R   R  R   R   R  t   classesR   R   R  (   RP   R  R
  R   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyR  V  s    
c         K  s   |  j  S(   u6   Hook for customizing the number of extra inline forms.(   R  (   RP   Rx   RE   RQ   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt	   get_extraa  s    c         K  s   |  j  S(   u4   Hook for customizing the min number of inline forms.(   t   min_num(   RP   Rx   RE   RQ   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   get_min_nume  s    c         K  s   |  j  S(   u:   Hook for customizing the max number of extra inline forms.(   R   (   RP   Rx   RE   RQ   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   get_max_numi  s    c   
        s  d | k r | j  d  } n t |  j | |   } |  j | |  } | d k rZ g  n	 t |  } | j |  j | |   | d k r t |  j	 d  r |  j	 j
 j r | j |  j	 j
 j  n  | p d } |  j o |  j | |  } i
 |  j	 d 6|  j d 6|  j d 6| d 6| d 6t |  j d | d 6|  j | | |  d	 6|  j | | |  d
 6|  j | | |  d 6| d 6} | j |  | d }	 d |	 f   f d     Y    | d <| d d k rt | d  rt j | d <n  t |  j |  j |  S(   uD   Returns a BaseInlineFormSet class for use in admin add/change views.u   fieldsu   _metau   formu   formsetu   fk_nameu   excludeRx   u   formfield_callbacku   extrau   min_numu   max_numu
   can_deletet   DeleteProtectedModelFormc             s    e  Z d    Z   f d   Z RS(   c         S  s  |  j  j t t  rt j |  j j  } t d |  } |  j	 j
 d k rO d S| j |  j	 g  | j rg  } x< | j D]1 } | j t d  i | j j d 6| d 6 q{ Wi |  j j j j d 6|  j	 d 6t | t d   d 6} t d  } t | d	 d
 d |  qn  d S(   u   
                We don't validate the 'DELETE' field itself because on
                templates it's not rendered using the field information, but
                just using a generic "deletion_field" of the InlineModelAdmin.
                R   Nu   %(class_name)s %(instance)su
   class_nameu   instanceu   andu   related_objectsux   Deleting %(class_name)s %(instance)s would require deleting the following protected related objects: %(related_objects)st   codeu   deleting_protectedt   params(   R  Rm   R"   RD   R   R  R   Ro   R   R  R   R   t   collectR  R   R   R   R:   R   (   RP   R   t	   collectort   objst   pR&  R   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   hand_clean_DELETE  s$    	
c           s#   t    |   j   } |  j   | S(   N(   R   R  R+  (   RP   t   result(   R$  (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyR    s    
(   RK   RL   R+  R  (    (   R$  (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyR$    s   	N(   R  R   R   R   R   R   R  R   R   R   R   R   t
   can_deleteRr   R  t   fk_nameR   R|   R   R"  R#  RX   R&   R   R  R%   R  Ro   (
   RP   Rx   RE   RQ   R   R  R   R-  R  t   base_model_form(    (   R$  s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyR&  m  s8    -




$
!c         C  sN   |  j  r |  j  S|  j | | d d  j } t | j  t |  j | |   S(   NR   (   R   R&  R   R   R   R  R   (   RP   Rx   RE   R   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyR     s    	c         C  s:   t  t |   j |  } |  j |  s6 | j   } n  | S(   N(   R   R  R   Rq   t   none(   RP   Rx   R   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyR     s    c         C  s/   |  j  j r |  j |  St t |   j |  S(   N(   R   R   Rq   R   R  Rp   (   RP   Rx   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyRp     s    c         C  s   |  j  } | j rZ xE | j D]7 } | j r | j j |  j k r | j j j } Pq q Wn  t d |  } | j j	 d | j
 | f  S(   Nu   changeu   %s.%s(   R   R   R   Rn   Ro   R  R   R   R   R   R   (   RP   Rx   RE   R   R   R   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyRq     s    		c         C  s5   |  j  j r |  j | |  St t |   j | |  S(   N(   R   R   Rq   R   R  Rr   (   RP   Rx   RE   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyRr     s    N(!   RK   RL   R   R   Ro   R.  R$   R  R  R!  R   t   templateR   R  R   R-  RD   t   show_change_linkR   RN   R  R\   R  R  R   R"  R#  R&  R   R   Rp   Rq   Rr   (    (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyR  5  s2   	L			t   StackedInlinec           B  s   e  Z d  Z RS(   u   admin/edit_inline/stacked.html(   RK   RL   R1  (    (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyR3    s   t   TabularInlinec           B  s   e  Z d  Z RS(   u   admin/edit_inline/tabular.html(   RK   RL   R1  (    (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyR4    s   (   t
   __future__R    RR   R  Ra  R  t   collectionsR   t	   functoolsR   R   R   t   djangoR   t   django.confR   t   django.contribR   t   django.contrib.adminR   R	   t   django.contrib.admin.checksR
   R   R   t   django.contrib.admin.exceptionsR   t,   django.contrib.admin.templatetags.admin_urlsR   t   django.contrib.admin.utilsR   R   R   R   R   R   R   R   t   django.contrib.authR   t   django.core.exceptionsR   R   R   R   t   django.core.paginatorR   t	   django.dbR   R   R   t   django.db.models.constantsR    t   django.db.models.fieldsR!   t   django.forms.formsetsR"   R#   t   django.forms.modelsR$   R%   R&   R'   R(   t   django.forms.widgetsR)   R*   t   django.httpR+   t   django.http.responseR,   t   django.template.responseR-   R.   t   django.urlsR/   t   django.utilsR0   t   django.utils.decoratorsR1   t   django.utils.encodingR2   R3   t   django.utils.htmlR4   t   django.utils.httpR5   R6   t   django.utils.safestringR7   t   django.utils.textR8   R9   R:   t   django.utils.translationR;   R   R<   t   django.views.decorators.csrfR=   t   django.views.genericR>   RF  R  t
   HORIZONTALRG   RF   RI   t	   ExceptionRJ   t   SplitDateTimeFieldt   AdminSplitDateTimet   DateTimeFieldt   AdminDateWidgett	   DateFieldt   AdminTimeWidgett	   TimeFieldt   AdminTextareaWidgett	   TextFieldt   AdminURLFieldWidgett   URLFieldt   AdminIntegerFieldWidgett   IntegerFieldt   AdminBigIntegerFieldWidgett   BigIntegerFieldt   AdminTextInputWidgett	   CharFieldt   AdminFileWidgett
   ImageFieldt	   FileFieldt   AdminEmailInputWidgett
   EmailFieldRT   R  t   with_metaclasst   MediaDefiningClassRM   R   R  R3  R4  (    (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/admin/options.pyt   <module>   s   :"(		
"      S