
    h                        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mZ d dlmZ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 d Zd Z e       Z d e	d      fd e	d      fd e	d      ffZ! G d deeee      Z"y)    )forms)settings)ManyToOneRel)gettext_lazy)AdminImageFormFieldFilerImageField)ImageThumbnailOption   )MarginFormMixinResponsiveFormMixin)AttributesFormFieldTagTypeFormFieldTemplateChoiceMixin)first_choice)FrontendUIItem   )AbstractLinkFormc            
      p    t        t        ddt        d      fdt        d      fdt        d      ff      } | S )zbadd setting for image alignment, renders a class or inline styles depending on your template setupDJANGOCMS_PICTURE_ALIGNstartz
Float leftendzFloat rightcenterzAlign center)getattrr   _)	alignments    V/home/dcms/DCMS/lib/python3.12/site-packages/djangocms_frontend/contrib/image/forms.pyget_alignmentr      sE    !ao&Am$%q()	
I     c                  @    t        t        ddt        d      fg      } | S )z3Add additional choices through the ``settings.py``.DJANGOCMS_PICTURE_TEMPLATESdefaultDefault)r   django_settingsr   )choicess    r   get_templatesr&      s*    %)%	
G Nr   inheritz7Let settings.DJANGOCMS_PICTURE_RESPONSIVE_IMAGES decideyesYesnoNoc            	       n    e Zd ZdZ G d d      ZdZ ej                   ed       e	        e
 e	                   Z e eeed      ej                   j#                         d ed      d	
      Z ej&                   ed      d	 ed            Z ej*                   ed      d	 ed            Z ej.                   ed      d	d ed            Z ej.                   ed      d	d ed            Z ej                   ed      ej6                   e       z   ej6                  d   d   d	 ed            Z e ed       ed            Z ej*                   ed      d	 ed            Z  ej*                   ed      d	 ed             Z! ej*                   ed!      d	 ed"            Z" ej*                   ed#      d	 ed$            Z# ej                   ed%      e$ e
e$       ed&      '      Z% ejL                  e'j                   j#                         d ed(      d	 ed)      *      Z( ej*                   ed+      d	d ed,      -      Z) ej*                   ed.      d	d	 ed/      -      Z* ej*                   ed0      d	d	 ed1      -      Z+ e       Z, e-       Z. fd2Z/ xZ0S )3	ImageFormzX
    Content > "Image" Plugin
    https://getbootstrap.com/docs/5.0/content/images/
    c                        e Zd ZeZdg diZdZy)ImageForm.Metaconfig)templatepictureexternal_picturelazy_loadingwidthheightr   link_attributesuse_automatic_scalinguse_cropuse_no_croppinguse_upscaleuse_responsive_imagethumbnail_optionspicture_fluidpicture_roundedpicture_thumbnail
attributes)ui_itemN)__name__
__module____qualname__r   modelentangled_fieldsexclude r   r   Metar/   A   s     
, r   rJ   TLayout)labelr%   initialidr	   F)relquerysetto_field_namerL   requiredzExternal imagezrIf provided, overrides the embedded image. Certain options such as cropping are not applicable to external images.)rL   rR   	help_textzLoad lazilyzZUse for images below the fold. This will load images only if user scrolls them into view. Width   zDThe image width as number in pixels. Example: "720" and not "720px".)rL   rR   	min_valuerS   HeightzEThe image height as number in pixels. Example: "720" and not "720px".	Alignmentr   z2Aligns the image according to the selected option.)rL   r%   rM   rR   rS   zLink attributesz$Attributes apply to the <b>link</b>.)rL   rS   zAutomatic scalingzDUses the placeholder dimensions to automatically calculate the size.zUse original imagez'Outputs the raw image without cropping.z
Crop imagezMCrops the image according to the thumbnail settings provided in the template.zUpscale imagezIUpscales the image to the size of the thumbnail settings in the template.zUse responsive imagezUses responsive image technique to choose better image to display based upon screen viewport. This configuration only applies to uploaded images (external pictures will not be affected). )rL   r%   rM   rS   zThumbnail optionszOOverrides width, height, and crop; scales up to the provided preset dimensions.)rP   rQ   rL   rR   rS   
Responsivez7Adds the .img-fluid class to make the image responsive.)rL   rR   rM   rS   Roundedz*Adds the .rounded class for round corners.	ThumbnailzAdds the .img-thumbnail class.c                    t         |           | j                  }|j                  dd      s0|j                  dd      st	        j
                  t        d            g d}d }|D ]1  }|j                  |d   d      s|j                  |d   d      s/|} n |rgt        d      }|j                  | j                  |d      j                  | j                  |d      j                  	      }t	        j
                  |      y )
Nr2   Fr3   zGYou need to add either an image, or a URL linking to an external image.))r8   r:   )r8   r=   )r:   r9   )r:   r;   )r:   r=   )r=   r9   )r=   r;   r   rU   zKInvalid cropping settings. You cannot combine "{field_a}" with "{field_b}".)field_afield_b)
supercleancleaned_datagetr   ValidationErrorr   formatfieldsrL   )selfdatainvalid_option_pairsinvalid_option_pairpairmessage	__class__s         r   r`   zImageForm.clean   s      xx	5)$((;Mu2U''*s(tuu 
 #( 	DxxQ'DHHT!We,D&*#	
 efGnn$7$:;AA$7$:;AA % G ''00 r   )1rC   rD   rE   __doc__rJ   link_is_optionalr   ChoiceFieldr   r&   r   r1   r   r   r   r	   objectsallr2   URLFieldr3   BooleanFieldr4   IntegerFieldr5   r6   r   EMPTY_CHOICEr   r   r   r7   r8   r:   r9   r;   RESPONSIVE_IMAGE_CHOICESr<   ModelChoiceFieldr
   r=   r>   r?   r@   rA   r   tag_typer`   __classcell__)rl   s   @r   r-   r-   6   s<   
 4  u  k]_-H
 "%6""$jG &u~~ !V
 &5%%pqL EjZ[	E  Uk[\	F "!!n%%7%%a(+HII *!":;O /E..#$Z[ )e(($%=>O "u!!ocdH
 %%$$ _`K
 -5,,&'(56l
	 /.. ((,,.#$ef 'E&&oMN	M )e((	l@A	O +**n45	 %&J!H 1  1r   r-   N)#djangor   django.confr   r$   django.db.models.fields.relatedr   django.utils.translationr   r   filer.fields.imager   r   filer.modelsr	   r
   djangocms_frontendcommonr   r   re   r   r   r   helpersr   modelsr   
link.formsr   r   r&   PICTURE_ALIGNMENTrv   r-   rI   r   r   <module>r      s     3 8 6 C / ' : P P # $ )	 "O  KLM
AeH	1T7O z1	z1r   