
    Bh                         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  G d dej                        Z G d	 d
ej                        Z G d de      Zy)    )chain)GenericRelation)models)PageSelectFormField)Placeholder)RemovedInDjangoCMS51Warningc                   X     e Zd ZdZd	 fd	Z fdZd Zd Z fdZ fdZ	 fdZ
 xZS )
PlaceholderFielda  
    .. warning::
        This field is for django CMS versions below 4 only. It may only be used for migrations. PlaceholderField
        will be removed in django CMS 4.3.

    The ``PlaceholderField`` has been replaced by the :class:`~cms.models.fields.PlaceholderRelationField`,
    the built-in migrations will automatically take care of the replacement.

    See documentation of :class:`~cms.models.fields.PlaceholderRelationField` for how to replace the code.
    c                    dd l }ddlm}m} |j	                  dt
        d       |s|}|j                  dd       dk(  rt        d      t        |      s ||       || _	        || _
         |       | _        |j                  d	d
i       |j                  ddi       d|d<   t        j                  |d<   t        | @  di | y )Nr   )PlaceholderNoActionvalidate_placeholder_namezDPlaceholderField is deprecated. Replace by PlaceholderRelationField.   )
stacklevelrelated_name+zEPlaceholderField does not support disabling of related names via '+'.nullTeditableFzcms.Placeholderto	on_delete )warningscms.utils.placeholderr   r   warnr   get
ValueErrorcallableslotnamedefault_widthactionsupdater   CASCADEsuper__init__)	selfr   r   r   kwargsr   r   r   	__class__s	           A/home/dcms/DCMS/lib/python3.12/site-packages/cms/models/fields.pyr#   zPlaceholderField.__init__   s    	
 	3'A 	 	
 )G::nd+s2dee!%h/ *yvtn%z5)* )t$nn{"6"    c                 T    t         |          \  }}}}| j                  |d<   ||||fS )Nr   )r"   deconstructr   )r$   namepathargsr%   r&   s        r'   r*   zPlaceholderField.deconstruct5   s6    #(7#6#8 dD&!]]zT4''r(   c                 v    t         j                  j                  | j                  |      | j                        S )N)slotr   )r   objectscreate_get_placeholder_slotr   )r$   instances     r'   _get_new_placeholderz%PlaceholderField._get_new_placeholder:   s0    ""))t/I/I(/Scgcucu)vvr(   c                     ddl m} t        | j                        r| j                  |      } ||       |S | j                  }|S )Nr   )r   )r   r   r   r   )r$   model_instancer   r   s       r'   r2   z&PlaceholderField._get_placeholder_slot=   s>    CDMM"}}^4H%h/  }}Hr(   c                    |j                   s't        || j                  | j                  |             n| j	                  |      }t        || j                        }|s<t        || j                  | j                  |             t        || j                        }|j                  |k7  r||_        |j                          t        | %  ||      S N)
pksetattrr+   r4   r2   getattrr/   saver"   pre_save)r$   r6   addr/   placeholderr&   s        r'   r=   zPlaceholderField.pre_saveG   s      NDIIt/H/H/XY--n=D!.$))<K		43L3L^3\]%ndii@4'#'   "w44r(   c                     t        || j                  d      }t        |t              s| j	                  |      }t
        |   ||       y )N )r;   r+   
isinstancer   r4   r"   save_form_data)r$   r3   datar&   s      r'   rC   zPlaceholderField.save_form_dataU   s>    xB/$,,,X6Dx.r(   c                 L   t         |   ||       t        |j                  d      sg |j                  _        t        |j                  d      si |j                  _        |j                  j                  j                  |       ||j                  j
                  | <   || _        y )Nplaceholder_field_namesplaceholder_fields)r"   contribute_to_classhasattr_metarF   rG   appendmodel)r$   clsr+   r&   s      r'   rH   z$PlaceholderField.contribute_to_class[   s{    #C.syy";<02CII-syy"67+-CII(		))006-1		$$T*
r(   )NN)__name__
__module____qualname____doc__r#   r*   r4   r2   r=   rC   rH   __classcell__r&   s   @r'   r
   r
      s1    	#>(
w5/ r(   r
   c                   0     e Zd ZdZeZ fdZ fdZ xZS )	PageFieldaE  
    This is a foreign key field to the :class:`cms.models.pagemodel.Page` model
    that defaults to the :class:`~cms.forms.fields.PageSelectFormField` form
    field when rendered in forms. It has the same API as the
    :class:`django:django.db.models.ForeignKey` but does not require
    the ``othermodel`` argument.
    c                 T    d|d<   t         j                  |d<   t        |   di | y )Nzcms.Pager   r   r   )r   r!   r"   r#   )r$   r%   r&   s     r'   r#   zPageField.__init__q   s,     "t$nn{"6"r(   c                 `    d| j                   i}|j                  |       t        |   di |S )N
form_classr   )default_form_classr    r"   	formfield)r$   r%   defaultsr&   s      r'   rZ   zPageField.formfieldx   s6    $11
 	w ,8,,r(   )	rN   rO   rP   rQ   r   rY   r#   rZ   rR   rS   s   @r'   rU   rU   f   s     -#- -r(   rU   c                   >     e Zd ZdZg Zd fd	Zed        Zd Z xZ	S )PlaceholderRelationFielda'  :class:`~django.contrib.contenttypes.fields.GenericForeignKey` to placeholders.

    If you create a model which contains placeholders you first create the ``PlaceHolderRelationField``::

        from cms.utils.placeholder import get_placeholder_from_slot

        class Post(models.Model):
            ...
            placeholders = PlaceholderRelationField()  # Generic relation

            @cached_property
            def content(self):
                return get_placeholder_from_slot(self.placeholders, "content")  # A specific placeholder
    c                     |xs d| _         |j                  dd        |j                  dd        t        |   t        fddd| y )Nr   object_id_fieldcontent_type_field	object_idcontent_type)r_   r`   )_checkspopr"   r#   r   )r$   checksr%   r&   s      r'   r#   z!PlaceholderRelationField.__init__   sQ    |

$d+

'.	
'-	
 		
r(   c                 B    t        | j                  | j                        S r8   )r   default_checksrc   )r$   s    r'   re   zPlaceholderRelationField.checks   s    T(($,,77r(   c                 D    t        fd| j                  D              S )Nc              3   0   K   | ]  } |        y wr8   r   ).0check_r?   users     r'   	<genexpr>z6PlaceholderRelationField.run_checks.<locals>.<genexpr>   s     G6+t,Gs   )allre   )r$   r?   rl   s    ``r'   
run_checksz#PlaceholderRelationField.run_checks   s    G4;;GGGr(   r8   )
rN   rO   rP   rQ   rg   r#   propertyre   ro   rR   rS   s   @r'   r]   r]      s.     N	
 8 8Hr(   r]   N)	itertoolsr   "django.contrib.contenttypes.fieldsr   	django.dbr   cms.forms.fieldsr   cms.models.placeholdermodelr   cms.utils.compat.warningsr   
ForeignKeyr
   rU   r]   r   r(   r'   <module>rx      sL     >  0 3 AXv(( Xv-!! -4!H !Hr(   