§
    ¨Mºf¢  ã                   óø   — d Z ddlZddlmZ ddlmZmZ ddlmZ ddlm	Z	 	 ddl
mZ n
#  d„ ZY nxY wd	d
lmZmZ d	dlmZmZ d„ Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zd d„Zd d„Zd„ ZddlmZ d!d„Zd"d„Zd„ Z dS )#a†  
Views for serving up dash applications and their constituents

Copyright (c) 2018 Gibbs Consulting and others - see CONTRIBUTIONS.md

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
é    N)ÚJSONDecodeError)ÚHttpResponseÚHttpResponseRedirect)Úredirect)ÚPreventUpdate)Úcheck_fingerprintc                 ó
   — | d fS )N© )Úresources    úW/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/django_plotly_dash/views.pyr   r   '   s   € Ø˜ˆ~Ðó    é   )ÚDashAppÚcheck_stateless_loaded)Úget_initial_argumentsÚstatic_pathc                  ó   — t           ‚)zReturn routes)ÚNotImplementedError)ÚargsÚkwargss     r   Úroutesr   .   s   € å
Ðr   Fc                 ó  — t          j        ||¦  «        \  }}|                     ¦   «         5  |                     d¦  «        } |¦   «         }t	          |j        |j        ¬¦  «        cddd¦  «         S # 1 swxY w Y   dS )zReturn the dependencieszdash-dependencies©Úcontent_typeN)r   Úlocate_itemÚapp_contextÚlocate_endpoint_functionr   ÚdataÚmimetype)ÚrequestÚidentÚ	statelessr   Ú_ÚappÚ	view_funcÚresps           r   Údependenciesr'   2   sÆ   € åÔ  ¨	Ñ2Ô2�F€A€sà	�ŠÑ	Ô	ð 8ð 8Ø×0Ò0Ð1DÑEÔEˆ	Øˆy‰{Œ{ˆÝ˜DœIØ)-¬ð8ñ 8ô 8ð8ð 8ð 8ð 8ñ 8ô 8ð 8ð 8ð 8ð 8ð 8ð 8øøøð 8ð 8ð 8ð 8ð 8ð 8s   ­:A4Á4A8Á;A8c                 óä   — t          j        ||¦  «        \  }}|                     d¦  «        } |¦   «         }t          | |¦  «        }	|                     ||	¦  «        \  }
}t          |
|¬¦  «        S )z)Return the layout of the dash applicationzdash-layoutr   )r   r   r   r   Úaugment_initial_layoutr   )r    r!   r"   Úcache_idr   r#   r$   r%   r&   Úinitial_argumentsÚresponse_datar   s               r   Úlayoutr-   <   s}   € åÔ  ¨	Ñ2Ô2�F€A€sà×,Ò,¨]Ñ;Ô;€IØˆ9‰;Œ;€Då-¨g°xÑ@Ô@Ðà!×8Ò8¸Ð?PÑQÔQÑ€M�8Ý˜Ø%-ð/ñ /ô /ð /r   c                 ób   — 	 t          | ||fi |¤ŽS # t          $ r t          d¬¦  «        cY S w xY w)NéÌ   ©Ústatus)Ú_updater   r   )r    r!   r"   r   s       r   Úupdater3   I   sS   € ð(Ý�w  yÐ;Ð;°FÐ;Ð;Ð;øÝð (ð (ð (Ý 3Ð'Ñ'Ô'Ð'Ð'Ð'ð(øøøs   ‚ ‘.­.c                 óH  — t          j        ||¦  «        \  }}	 t          j        | j                             d¦  «        ¦  «        }n'# t          t          f$ r t          d¬¦  «        cY S w xY w| j	         
                    dt          ¦   «         ¦  «        }||| j        | |dœ}|                     ||¦  «        }	|| j	        d<   |                     ¦   «          t          |	¦  «        dk    rt          d¦  «        S 	 |	j        }
|	j        }n#  |	}
d}Y nxY wt          |
|¬	¦  «        S )
zGenerate update json responsezutf-8éÈ   r0   Údjango_plotly_dash)Údash_app_idÚdash_appÚuserr    Úsession_stateÚEDGECASEEXITÚ zapplication/jsonr   )r   r   ÚjsonÚloadsÚbodyÚdecoder   ÚUnicodeDecodeErrorr   ÚsessionÚgetÚdictr9   Údispatch_with_argsÚhandle_current_stateÚstrr   r   )r    r!   r"   r   r8   r$   Úrequest_bodyÚ	app_stateÚarg_mapr&   ÚrdataÚrtypes               r   r2   r2   O   sP  € åÔ'¨¨yÑ9Ô9�M€Hˆcð(Ý”z '¤,×"5Ò"5°gÑ">Ô">Ñ?Ô?ˆˆøÝÕ/Ð0ð (ð (ð (Ý 3Ð'Ñ'Ô'Ð'Ð'Ð'ð(øøøð ”×#Ò#Ð$8½$¹&¼&ÑAÔA€IØ#Ø#Ø”|Ø Ø )ð	+ð +€Gð
 ×!Ò! ,°Ñ8Ô8€DØ,5€G„OÐ(Ñ)Ø×!Ò!Ñ#Ô#Ð#õ ˆ4�y„y�NÒ"Ð"Ý˜BÑÔÐð#Ø”	ˆØ”ˆˆøð#ØˆØ"ˆˆˆøøøå˜Ø%*ð,ñ ,ô ,ð ,s   š,A Á!A+Á*A+Ã9D ÄDc                 ó�   — t          j        |||¬¦  «        \  }}|                     ¦   «         } |¦   «         }t          |¦  «        S )zMain view for a dash app)r*   )r   r   r   r   )	r    r!   r"   r*   r   r#   r$   r%   r&   s	            r   Ú	main_viewrN   r   sG   € åÔ  ¨	¸HÐEÑEÔE�F€A€sà×,Ò,Ñ.Ô.€IØˆ9‰;Œ;€DÝ˜ÑÔÐr   c                 ó$   — t          | f||ddœ|¤ŽS )úFReturn part of a client-side component, served locally for some reasonz_components/)r   Ú	componentÚextra_element©Úcomponent_suites)r    r   rQ   r   s       r   Úcomponent_component_suitesrU   z   s3   € å˜Gð &Ø%-Ø&/Ø*8ð&ð &ð %ð	&ð &ð &r   r<   c                 ó,   — t          | f||||› d�dœ|¤ŽS )rP   z/build)r   rQ   rR   Úcpe2rS   )r    r   rQ   rR   rW   r   s         r   Úcomponent_suites_buildrX   ƒ   s<   € å˜Gð &Ø%-Ø&/Ø*7Ø$(   ð	&ð &ð
 %ð&ð &ð &r   c                 óÂ   — |r|› d�nd}| j                              ¦   «         }|r	 t          |¦  «        \  }}	t          d|›d|›|›|›�¦  «        }t	          |¬¦  «        S )rP   ú/r<   Fzdash/component/ú?©Úredirect_to)ÚGETÚ	urlencoder   r   r   )
r    r   rQ   rR   rW   r   Úextra_path_partÚ
get_paramsÚ
redone_urlÚ_fingerprints
             r   rT   rT   �   s…   € ð %)Ð0˜�j�j�j�j¨b€Oà”×&Ò&Ñ(Ô(€JØð uð uõ "3°8Ñ!<Ô!<Ñˆ�,Ý �[¸y¸y¸yÈ/È/Ð[hÐ[hÐjrÐjrÐ!sÑtÔtˆ
å¨JÐ7Ñ7Ô7Ð7r   c                 ó¬   — | j                              ¦   «         }d}|rt          d|›d|›�¦  «        }nt          d|z  ¦  «        }t          |¬¦  «        S )zLReturn a local dash app asset, served up through the Django static frameworkr<   zdash/assets/r[   zdash/assets/%sr\   )r^   r_   r   r   )r    r   ra   Ú
extra_partrb   s        r   Ú
app_assetsrf   ›   sc   € à”×&Ò&Ñ(Ô(€JØ€JØð @Ý �[°z°z°zÀ:À:Ð!NÑOÔOˆ
ˆ
å Ð!1°JÑ!>Ñ?Ô?ˆ
å¨JÐ7Ñ7Ô7Ð7r   )ÚTemplateResponseú
index.htmlc                 óÂ   — | j                              dt          ¦   «         ¦  «        }|                     dd¦  «        }|dz   |d<   || j         d<   t          | |i ¦  «        S )zTAdd some info to a session in a place that django-plotly-dash can pass to a callbackr6   Úadd_counterr   r   )rB   rC   rD   rg   )r    Útemplate_namer   r6   Úsession_add_counts        r   Úadd_to_sessionrm   ©   sf   € ð !œ×,Ò,Ð-AÅ4Á6Ä6ÑJÔJÐà*×.Ò.¨}¸aÑ@Ô@ÐØ(9¸AÑ(=Ð�}Ñ%Ø,>€G„OÐ(Ñ)å˜G ]°BÑ7Ô7Ð7r   c                 óz   — t          j        ||¦  «        \  }}|                     |¦  «        }t          |¦  «        S )z&Redirect static assets for a component)r   r   Úget_asset_static_urlr   )r    Úpathr!   r"   r   ÚXr$   r   s           r   Úasset_redirectionrr   ´   s=   € õ Ô  ¨	Ñ2Ô2�F€A€sð ×(Ò(¨Ñ.Ô.€Kå�KÑ Ô Ð r   c                 ó<   — t          ¦   «          t          d¦  «        S )zKCheck all registered stateless apps and create ORM entries that are missingz0admin:django_plotly_dash_statelessapp_changelist)r   r   )r    r   s     r   Úadd_stateless_appsrt   ¾   s   € åÑÔÐÝÐFÑGÔGÐGr   )F)FN)NN)NNr<   N)rh   )NF)!Ú__doc__r=   r   Údjango.httpr   r   Údjango.shortcutsr   Údash.exceptionsr   Údash.fingerprintr   Úmodelsr   r   Úutilr   r   r   r'   r-   r3   r2   rN   rU   rX   rT   rf   Údjango.template.responserg   rm   rr   rt   r
   r   r   ú<module>r}      sï  ððð ð4 €€€Ø  Ð  Ð  Ð  Ð  Ð  à :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ø %Ð %Ð %Ð %Ð %Ð %à )Ð )Ð )Ð )Ð )Ð )ðØ2Ð2Ð2Ð2Ð2Ð2Ð2øððð ð ð ð øøøð 4Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ø 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4ðð ð ð8ð 8ð 8ð 8ð/ð /ð /ð /ð(ð (ð (ð (ð!,ð !,ð !,ð !,ðFð ð ð ð&ð &ð &ð &ð&ð &ð &ð &ð8ð 8ð 8ð 8ð	8ð 	8ð 	8ð 6Ð 5Ð 5Ð 5Ð 5Ð 5ð	8ð 	8ð 	8ð 	8ð!ð !ð !ð !ðHð Hð Hð Hð Hs   ¢) ©0