U
    
d                     @   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__ 4/tmp/pip-unpacked-wheel-g6xi1tgp/ckeditor/widgets.pyr      s    
zLazyEncoder.default)__name__
__module____qualname__r   __classcell__r   r   r   r   r      s   r   c                       sF   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|| || _t | _ttdd }|rt|t	r| j|krr|| j }t|t	sdt
d| j | j| qt
d| j nt
d|p| jdd pg }|rd|| jd< |p| jdd pg | _d S )	NZ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,Z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-scriptZCKEDITOR_BASEPATHzckeditor/ckeditor/)idzdata-ckeditor-basepathzckeditor/ckeditor/ckeditor.js)Z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 )NZ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   r4   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   r5   y   s    
zCKEditorWidget._set_config)r   NN)r   r   r   __doc__Ztemplate_namer!   propertyr.   r4   r5   r   r   r   r   r   r      s      5
r   N)Zdjangor   Zdjango.confr   Zdjango.core.exceptionsr   Zdjango.core.serializers.jsonr   Zdjango.forms.widgetsr   Zdjango.templatetags.staticr   Zdjango.utils.encodingr	   Zdjango.utils.functionalr
   Zdjango.utils.translationr   Zjs_assetr   r,   r   r   encoder6   ZTextarear   r   r   r   r   <module>   s   