o
    ѷ6i                     @   sX   d dl Z d dlmZ d dlmZ d dlmZ d dlZdd Zdd Z	d	d
 Z
dd ZdS )    Nwraps)login_required)HttpResponsec                       t   fdd}|S )zDisable notifications.

    Does not work for async stuff, only disables notify in the same process.

    Example::

        @disable_notify
        def your_function():
            notify("no one will be notified", ...)
    c                     s   dt _ | i |}dt _|S )NTF)
django_nyt_disable_notifications)argskwargsresponsef Z/var/www/hoanhtaovolam_webdjango/env/lib/python3.10/site-packages/django_nyt/decorators.pywrapper   s   zdisable_notify.<locals>.wrapperr   r   r   r   r   r   disable_notify
   s   r   c                    r   )z~Similar to login_required. But if the request is an ajax request, then
    it returns an error in json with a 403 status code.c                    sb   | j ddkr$| jr| jjstdd | ddS  | g|R i |S t | g|R i |S )Nzx-requested-withXMLHttpRequestc                  _   s   ddiS )Nerrorznot logged inr   )akwr   r   r   <lambda>(   s    z6login_required_ajax.<locals>.wrapper.<locals>.<lambda>i  )status)headersgetuseris_authenticated	json_viewr   )requestr	   r
   r   r   r   r   $   s   
z$login_required_ajax.<locals>.wrapperr   r   r   r   r   login_required_ajax    s   
r   c                 K   s4   t j| dd}|dd}td|d}|| |S )NF)ensure_asciir      zapplication/json)content_typer   )jsondumpsr   r   write)datar
   	json_datar   r   r   r   r   data2jsonresponse2   s
   
r(   c                    r   )Nc                    s&    | g|R i |}t |fi |S )N)r(   )r   r	   r
   r&   r   r   r   r   ;   s   zjson_view.<locals>.wrapperr   r   r   r   r   r   :   s   r   )r#   	functoolsr   django.contrib.auth.decoratorsr   django.httpr   r   r   r   r(   r   r   r   r   r   <module>   s    