o
    V&Zc                     @   s   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 G dd deZe jZG dd dejZdS )    )forms)settings)ImproperlyConfigured)DjangoJSONEncoder)Media)static	force_str)Promise)get_language)JS   )DEFAULT_CONFIGc                       s   e Zd Z fddZ  ZS )LazyEncoderc                    s   t |tr	t|S t |S )N)
isinstancer
   r	   superdefault)selfobj	__class__ E/var/www/jaguar/venv/lib/python3.10/site-packages/ckeditor/widgets.pyr      s   
zLazyEncoder.default)__name__
__module____qualname__r   __classcell__r   r   r   r   r      s    r   c                       sL   e Zd ZdZdZ			d fdd	Zedd Z fd	d
Zdd Z	  Z
S )CKEditorWidgetzg
    Widget providing CKEditor for Rich Text Editing.
    Supports direct image uploads and embed.
    zckeditor/widget.htmlr   Nc                    s   t  j|i | || _t | _ttdd }|rFt|t	rB| j|v r;|| j }t|t	s4t
d| j | j| nt
d| j t
d|pP| jdd pPg }|r[d|| jd< |pe| jdd peg | _d S )	NCKEDITOR_CONFIGSzYCKEDITOR_CONFIGS["%s"]                                 setting must be a dictionary type.z_No configuration named '%s'                             found in your CKEDITOR_CONFIGS setting.zJCKEDITOR_CONFIGS setting must be a                        dictionary type.extra_plugins,extraPluginsexternal_plugin_resources)r   __init__config_namer   copyconfiggetattrr   r   dictr   updatepopjoinr"   )r   r$   r   r"   argskwargsconfigsr&   r   r   r   r#   !   s>   




zCKEditorWidget.__init__c                 C   s*   t tddttdd ptdddfdS )Nzckeditor/ckeditor-init.jszckeditor-init-scriptCKEDITOR_BASEPATHzckeditor/ckeditor/)idzdata-ckeditor-basepathzckeditor/ckeditor/ckeditor.js)js)r   r   r'   r   r   )r   r   r   r   mediaV   s   zCKEditorWidget.mediac                    sN   t  |||}|   t| j|d d< dd | jD }t||d d< |S )Nwidgetr&   c                 S   s(   g | ]\}}}t |t |t |gqS r   r   ).0abcr   r   r   
<listcomp>p   s    z.CKEditorWidget.get_context.<locals>.<listcomp>r"   )r   get_context_set_configjson_encoder&   r"   )r   namevalueattrscontextr"   r   r   r   r9   j   s   zCKEditorWidget.get_contextc                 C   s2   t   }|dkrd}n|dkrd}|| jd< d S )Nzzh-hanszzh-cnzzh-hantzhlanguage)r   lowerr&   )r   langr   r   r   r:   y   s   
zCKEditorWidget._set_config)r   NN)r   r   r   __doc__template_namer#   propertyr2   r9   r:   r   r   r   r   r   r      s    5
r   N)djangor   django.confr   django.core.exceptionsr   django.core.serializers.jsonr   django.forms.widgetsr   django.templatetags.staticr   django.utils.encodingr	   django.utils.functionalr
   django.utils.translationr   js_assetr   r.   r   r   encoder;   Textarear   r   r   r   r   <module>   s    