
    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
 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mZ  ee      Z G d de      Z G d de      Zedk(  rdZndZej7                  e e
d      dddff      e_        y)    )forms)get_object_or_404)TemplateResponse)path)gettext)gettext_lazy   )FILER_IMAGE_MODEL)normalize_subject_location)string_concat)
load_model   )	FileAdminFileAdminChangeFromc                   v    e Zd Z ej                  dd ed       ed            Zd Zd Zd Z	 G d	 d
      Z
y)ImageAdminForm@   FSubject locationz9Location of the main subject of the scene. Format: "x,y".)
max_lengthrequiredlabel	help_textc                 V    | j                   rd| j                   j                         z  S y)Nz%.6F )instancesidebar_image_ratio)selfs    F/home/dcms/DCMS/lib/python3.12/site-packages/filer/admin/imageadmin.pyr   z"ImageAdminForm.sidebar_image_ratio   s&    == DMM==???    c                     | j                   j                  }||d<   | j                  j                         | _        || j                  d<   y )Nsubject_location)r   r!   datacopy)r   cleaned_datar!   s      r   _set_previous_subject_locationz-ImageAdminForm._set_previous_subject_location$   s>    ==99+;'(IINN$	(8		$%r   c           
         | j                   d   }|s|S t        |      }|st        d      }d}nZ|d   | j                  j                  cxkD  rdkD  s(n |d   | j                  j
                  cxkD  rdkD  rn |S t        d      }d}n|S | j                  | j                          t        j                  t        |t        dj                  |	            d
      |      )z
        Validate subject_location preserving last saved value.

        Last valid value of the subject_location field is shown to the user
        for subject location widget to receive valid coordinates on field
        validation errors.
        r!   z!Invalid subject location format. invalid_subject_formatr   r   z*Subject location is outside of the image. subject_out_of_boundsz"Your input: "{subject_location}". r!   zPrevious value is restored.)code)r$   r   r   r   widthheightr%   r   ValidationErrorr   format)r   r!   coordinateserr_msgerr_codes        r   clean_subject_locationz%ImageAdminForm.clean_subject_location*   s      ,,-?@## 11AB"#FGG/H NT]]004141~ 4 48q8 $#	 #<>G.H##++D,=,=>##AHH%5 I 7 8-	/
  	r   c                       e Zd ZeZdZy)ImageAdminForm.Meta N)__name__
__module____qualname__Imagemodelexcluder5   r   r   Metar4   Q   s    r   r<   N)r6   r7   r8   r   	CharField_r!   r   r%   r2   r<   r5   r   r   r   r      sH    &u"# % &'	9%N r   r   c                   ,     e Zd ZdZeZ fdZd Z xZS )
ImageAdminz"admin/filer/image/change_form.htmlc           	          t         |          t        d| j                  j	                  | j
                        | j                  j                   d| j                  j                   d      gz   S )Nzexpand/<int:file_id>r>   _expand)name)	superget_urlsr   
admin_site
admin_viewexpand_viewopts	app_label
model_name)r   	__class__s    r   rE   zImageAdmin.get_urlsZ   sg    w!'++D,<,<=,,-Qtyy/C/C.DGLN%
 
 	
r   c                 d    t        | j                  |      }t        |dd|j                  i      S )N)pkzadmin/filer/image/expand.htmloriginal_url)context)r   r:   r   url)r   requestfile_idimages       r   rH   zImageAdmin.expand_viewa   s3    !$**9+		
 	
r   )	r6   r7   r8   change_form_templater   formrE   rH   __classcell__)rL   s   @r   r@   r@   V   s    ?D

r   r@   zfiler.Image)authordefault_alt_textdefault_caption)rY   rZ   r   r)   )collapse)fieldsclasses)extra_main_fieldsextra_fieldsetsN)djangor   django.shortcutsr   django.template.responser   django.urlsr   django.utils.translationr   r>   r   settingsr
   thumbnail_processorsr   utils.compatibilityr   utils.loaderr   	fileadminr   r   r9   r   r@   r^   build_fieldsets	fieldsetsr5   r   r   <module>rl      s     . 5  1 1 ( = / % 5 	$%A( AH
 
, %J@!11'	
	+$!
 	 2 
 r   