U
    "5i                     @   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-j53lzkjl/ckeditor/widgets.pyr      s    
zLazyEncoder.default)__name__
__module____qualname__r   __classcell__r   r   r   r   r      s   r   c                       sB   e 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.
    r   Nckeditor/widget.htmlc           	         s   || _ t j|| || _t | _ttdd }|rt	|t
r| j|krx|| j }t	|t
sjt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)template_namer   __init__config_namer   copyconfiggetattrr   r   dictr   updatepopjoinr!   )	r   r$   r   r!   r"   argskwargsconfigsr&   r   r   r   r#      s@    	




zCKEditorWidget.__init__c              	   C   s4   t ddgitddttdd p"tdddd	fd
S )Nallzckeditor/ckeditor.csszckeditor/ckeditor-init.jszckeditor-init-scriptZCKEDITOR_BASEPATHzckeditor/ckeditor/)idzdata-ckeditor-basepathzckeditor/ckeditor/ckeditor.jszckeditor/fixups.js)cssZ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>r   s   z.CKEditorWidget.get_context.<locals>.<listcomp>r!   )r   get_context_set_configjson_encoder&   r!   )r   namevalueattrscontextr!   r   r   r   r8   l   s    zCKEditorWidget.get_contextc                 C   s<   t   }|dkrd}n|dkr$d}|| jd< d| jd< d S )Nzzh-hanszzh-cnzzh-hantzhlanguageFZversionCheck)r   lowerr&   )r   langr   r   r   r9   {   s    

zCKEditorWidget._set_config)r   NNr   )
r   r   r   __doc__r#   propertyr2   r8   r9   r   r   r   r   r   r      s       7
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   encoder:   ZTextarear   r   r   r   r   <module>   s   