U
    )¬Þaá  ã                   @   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 d dlmZ d dlmZ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 )é    )Úabsolute_import)Úforms)Úsettings)ÚImproperlyConfigured)ÚDjangoJSONEncoder)Úflatatt)Úget_default_renderer©Ú	force_str)ÚPromise)Úconditional_escape)Ú	mark_safe)Úget_language)ÚJSÚstaticé   )ÚDEFAULT_CONFIGc                       s   e Zd Z‡ fdd„Z‡  ZS )ÚLazyEncoderc                    s"   t |tƒrt|ƒS tt| ƒ |¡S )N)Ú
isinstancer   r
   Úsuperr   Údefault)ÚselfÚobj©Ú	__class__© ú/home/adriano.carvalho/ftp/files/BrinquedotecaVirtual/brinquedotecavirtual/venv/lib/python3.8/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G dd„ dƒZd‡ fdd„	Zddd	„Zdd
d„Zdd„ Z‡  Z	S )ÚCKEditorWidgetzg
    Widget providing CKEditor for Rich Text Editing.
    Supports direct image uploads and embed.
    c                   @   s,   e Zd ZeddeededƒƒdœƒdfZdS )zCKEditorWidget.Mediazckeditor/ckeditor-init.jszckeditor-init-scriptZCKEDITOR_BASEPATHzckeditor/ckeditor/)Úidzdata-ckeditor-basepathzckeditor/ckeditor/ckeditor.jsN)r   r   r   r   Úgetattrr   r   Zjsr   r   r   r   ÚMedia#   s   ýþþôr$   r   Nc                    sÆ   t t| ƒj||Ž t ¡ | _ttdd ƒ}|r€t|t	ƒrx||krj|| }t|t	ƒs\t
d| ƒ‚| j |¡ q€t
d| ƒ‚nt
dƒ‚|p”| j dd ¡p”g }|rªd |¡| jd< |p¾| j dd ¡p¾g | _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   r!   Ú__init__r   ÚcopyÚconfigr#   r   r   Údictr   ÚupdateÚpopÚjoinr'   )r   Zconfig_namer%   r'   ÚargsÚkwargsÚconfigsr*   r   r   r   r(   3   s<    


þÿþÿÿÿýzCKEditorWidget.__init__c              
   C   sz   |d krt ƒ }|d krd}| j| j||d}|  ¡  dd„ | jD ƒ}t| dt|ƒtt	|ƒƒ|d t
| jƒt
|ƒdœ¡ƒS )NÚ )Únamec                 S   s(   g | ] \}}}t |ƒt |ƒt |ƒg‘qS r   r	   )Ú.0ÚaÚbÚcr   r   r   Ú
<listcomp>m   s   ÿz)CKEditorWidget.render.<locals>.<listcomp>zckeditor/widget.htmlr"   )Úfinal_attrsÚvaluer"   r*   r'   )r   Úbuild_attrsÚattrsÚ_set_configr'   r   Úrenderr   r   r
   Újson_encoder*   )r   r3   r:   r<   Zrendererr9   r'   r   r   r   r>   f   s(    þ
ûþÿzCKEditorWidget.renderc                 K   s   t |f|Ž}|r| |¡ |S )z˜
        Helper function for building an attribute dictionary.
        This is combination of the same method from Django<=1.10 and Django1.11+
        )r+   r,   )r   Z
base_attrsZextra_attrsr0   r<   r   r   r   r;      s    
zCKEditorWidget.build_attrsc                 C   s.   t ƒ }|dkrd}n|dkr d}|| jd< d S )Nzzh-hanszzh-cnzzh-hantÚzhÚlanguage)r   r*   )r   Úlangr   r   r   r=   ‰   s    zCKEditorWidget._set_config)r   NN)NN)N)
r   r   r   Ú__doc__r$   r(   r>   r;   r=   r    r   r   r   r   r!      s      ü3


r!   N)"Ú
__future__r   Zdjangor   Zdjango.confr   Zdjango.core.exceptionsr   Zdjango.core.serializers.jsonr   Zdjango.forms.utilsr   Zdjango.forms.widgetsr   Zdjango.utils.encodingr
   Zdjango.utils.functionalr   Zdjango.utils.htmlr   Zdjango.utils.safestringr   Zdjango.utils.translationr   Zjs_assetr   r   r1   r   r   Úencoder?   ZTextarear!   r   r   r   r   Ú<module>   s    