o
    ["<f                     @   s   d dl Z d dlZd dlmZmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ zd dlZW n ey9   dZY nw e
dd Zd	d
 Zdd Zdd Zdd Zdd Zdd ZdS )    N)HttpResponseJsonResponse)render)reverse)csrf_exemptgzip_compressorc              
      s   zLt std| jd}| jd}| jd}t |s(d| d}t|t |  fdd}|d	kr>d
||i}n
d| d}t|W t
|S  tyl } ztd dt	|i}W Y d}~t
|S d}~ww )zO
    Returns a response that implements the TinyMCE spellchecker protocol.
    z0install pyenchant for spellchecker functionalitymethodtextlangz#Dictionary not found for language 'z', check pyenchant.c                    sD   i }|   }|D ]}|  |d  |s |||< q|S )z[
            Sanitize words in text and recommend suggestions for wrong words.
            z.,:;'")splitstripchecksuggest)r
   suggested_wordswordswordchecker D/var/www/html/kck/venv/lib/python3.10/site-packages/tinymce/views.pysanitize_words'   s   

z#spell_check.<locals>.sanitize_words
spellcheckr   zGot an unexpected method ''zError running spellcheckererrorN)enchantRuntimeErrorPOSTgetdict_existsDict	Exceptionlogging	exceptionstrr   )requestr	   r
   r   e_msgr   outputerrr   r   r   spell_check   s.   

	
r)   c                 C   s(   ddl m} dd |j D }t|S )zr
    Returns a HttpResponse whose content is a Javascript file representing a
    list of links to flatpages.
    r   )FlatPagec                 S   s   g | ]}|j |jfqS r   )titleurl).0pager   r   r   
<listcomp>H   s    z'flatpages_link_list.<locals>.<listcomp>)django.contrib.flatpages.modelsr*   objectsallrender_to_link_list)r%   r*   	link_listr   r   r   flatpages_link_listA   s   r5   c                 C   s   t | S )z-
    Returns a GZip-compressed response.
    r   )r%   r   r   r   
compressorL   s   r6   c                 C   
   t d| S )z
    Returns a HttpResponse whose content is a Javascript file representing a
    list of links suitable for use wit the TinyMCE external_link_list_url
    configuration option. The link_list parameter must be a list of 2-tuples.
    tinyMCELinkListrender_to_js_vardef)r4   r   r   r   r3   S      
r3   c                 C   r7   )z
    Returns a HttpResponse whose content is a Javascript file representing a
    list of images suitable for use wit the TinyMCE external_image_list_url
    configuration option. The image_list parameter must be a list of 2-tuples.
    tinyMCEImageListr9   )
image_listr   r   r   render_to_image_list\   r;   r>   c                 C   s$   d|  dt | d}t|ddS )Nzvar z = ;zapplication/x-javascriptcontent_type)jsondumpsr   )var_name	var_valuer'   r   r   r   r:   e   s   r:   c                 C   sH   z	|  td}W n ty   |  td}Y nw t| dd|iddS )N	fb_browsezfilebrowser:fb_browseztinymce/filebrowser.jsfb_urlzapplication/javascriptr@   )build_absolute_urir   r!   r   )r%   rG   r   r   r   filebrowserj   s   rI   )rB   r"   django.httpr   r   django.shortcutsr   django.urlsr   django.views.decorators.csrfr   tinymce.compressorr   r   ImportErrorr)   r5   r6   r3   r>   r:   rI   r   r   r   r   <module>   s(   
,		