
    >Tf                        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mZmZ d dlmZmZ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(m)Z) d dl*m+Z+ d dl,m-Z-m.Z. d dl/m0Z0 d dl1m2Z2 d dl3m4Z4 d dl5m6Z6 d dl7m8Z8 d dl9m:Z:m;Z; d dl<m=Z= d dl>m?Z?m@Z@ d dlAmBZB d dlCmDZD d dlEmFZF d dlGmHZH d d lImJZJ d d!lKmLZLmMZMmNZN d d"lOmPZP d#d$lQmRZRmSZSmTZT d#d%lUmVZV d#d&lWT d#d'lTmXZXmYZY  G d( d)e6jZ                  Z[ eNe\           G d* d+e6j]                              Z^ eNe\d,           G d- d.e6j_                              Z` eNe\d/           G d0 d1e6ja                              Zb G d2 d3e6jc                  Zd G d4 d5e6je                  Zf G d6 d7e6jg                  Zh G d8 d9e6jZ                  Zi eNej           G d: d;e6j]                              Zk eNejd,           G d< d=e6j_                              Zl eNejd/           G d> d?e6ja                              Zm G d@ dAe6jc                  Zn G dB dCe6je                  Zo G dD dEe6jg                  Zp G dF dGe6jZ                  Zq eNer           G dH dIe6j]                              Zs eNerd,           G dJ dKe6j_                              Zt eNerd/           G dL dMe6ja                              Zu G dN dOe6jc                  Zv G dP dQe6je                  Zw G dR dSe6jg                  Zx G dT dUe6jZ                  Zy eNez           G dV dWe6j]                              Z{ eNezd,           G dX dYe6j_                              Z| eNezd/           G dZ d[e6ja                              Z} G d\ d]e6jc                  Z~ G d^ d_e6je                  Z G d` dae6jg                  Z G db dce6j                  Z G dd de          Z G df dgee6jZ                  Z eNe           G dh diee6j]                              Z eNed,           G dj dkee6j_                              Z eNed/           G dl dmee6ja                              Z G dn doee6jc                  Z G dp dqee6je                  Z G dr dsee6jg                  Z G dt due6j_                  Z eNed/           G dv dwe6ja                              Z G dx dye6jg                  Z G dz d{e6jZ                  Z eNe           G d| d}e6j]                              Z eNed,           G d~ de6j_                              Z eNed/           G d de6ja                              Z G d de6jc                  Z G d de6je                  Z G d de6jg                  Z G d dee          Z eNed           G d dee                      Z eNed           G d dee                      Z eNed/           G d de6ja                              Z G d de6jg                  Z G d de6j_                  Z eNed/           G d de6ja                              Z G d de6jg                  Z G d de6jZ                  Z eNe           G d de6j]                              Z eNed,           G d de6j_                              Z eNed/           G d de6ja                              Z G d de6jc                  Z G d de6je                  Z G d de6jg                  Z G d de6jZ                  Z eNe           G d de6j]                              Z eNed,           G d de6j_                              Z eNed/           G d de6ja                              Z G d de6jc                  Z G d de6je                  Z G d de6jg                  Z G d de6jZ                  Z eNe           G d de6j]                              Z eNed,           G d de6j_                              Z eNed/           G d de6ja                              Z G d de6jc                  Z G d de6je                  Z G d de6jg                  Z G dĄ de6jZ                  Z eNe           G dƄ de6j]                              Z eNed,           G dȄ de6j_                              Z G dʄ de6je                  Z eNed/           G d̄ de6ja                              Z G d΄ de6jg                  Z G dЄ de6j                  Z G d҄ de6j]                  Z G dԄ de6jZ                  Z eNeĦ           G dք de6j]                              Z eNed,           G d؄ de6j_                              Z eNed/           G dڄ de6ja                              Z G d܄ de6jc                  Z G dބ de6je                  Z G d de6jg                  Z G d de6j                  Z G d de6jZ                  Z eNed,           G d de6j_                              Z eNed/           G d de6ja                              Z G d de6jZ                  Z eNeѦ           G d de6j]                              Z eNed,           G d de6j_                              Z eNed/           G d de6ja                              Z G d de6je                  Z G d de6jg                  Z G d de6jc                  Z G d dee          Z G d dee          Z G d dee          Z G d dee          Z eNed,           G d  de6j_                              Z eNed/           G d de6ja                              Z G d deLe          Z G d de6j]                  Z G d d	e          Z G d
 de          Z G d de          Z G d de8e6j]                  Z G d dee          ZdS (      )messages)LoginRequiredMixin)ContentType)	EmptyPage)CountQ)HttpResponseBadRequestHttpResponseForbiddenHttpResponse)get_object_or_404redirectrender)reverse)import_string)timezone)gettext)View)ManagedFileRootPathChoices)ManagedFileForm)Job)JobTable)Device
DeviceRolePlatform)LogLevelChoices)DashboardWidgetAddFormDashboardWidgetForm)get_widget_class)DEFAULT_ACTION_PERMISSIONS)registry)generic)
TableMixin)ConfirmationFormget_field_value)htmx_partial)EnhancedPaginatorget_paginate_count)count_related)normalize_querydict)copy_safe_request)get_workers_for_queue)render_markdown)"ContentTypePermissionRequiredMixinget_viewnameregister_model_view)VirtualMachine   )
filtersetsformstables)LOG_LEVEL_RANK)*)ReportResultsTableScriptResultsTablec                   l    e Zd Zej                            d          Zej        Z	e
j        Zej        ZdS )CustomFieldListView
choice_setN)__name__
__module____qualname__CustomFieldobjectsselect_relatedquerysetr2   CustomFieldFilterSet	filtersetr3   CustomFieldFilterFormfilterset_formr4   CustomFieldTabletable     1/var/www/html/netbox-4.1.3/netbox/extras/views.pyr:   r:   .   s<        "11,??H/I0N#EEErJ   r:   c                   H    e Zd Zej                            d          Zd ZdS )CustomFieldViewr;   c                 .   d}|j                                         D ]v}||                                j                            |j        d                              t          di d|j         dit          di d|j         d iz            fz  }wd|iS )NrI   viewcustom_field_data__ related_models)	object_typesallmodel_classr@   restrictuserexcluder   name)selfrequestinstancerR   object_types        rK   get_extra_contextz!CustomFieldView.get_extra_context9   s    #04466 	 	K''))1::7<PPXXDD>x}>>CDDFF>x}>>EFFG  NN n
 	
rJ   N)r<   r=   r>   r?   r@   rA   rB   r^   rI   rJ   rK   rM   rM   5   s9        "11,??H
 
 
 
 
rJ   rM   editc                   P    e Zd Zej                            d          Zej        Z	dS )CustomFieldEditViewr;   N)
r<   r=   r>   r?   r@   rA   rB   r3   CustomFieldFormformrI   rJ   rK   ra   ra   I   s,        "11,??H DDDrJ   ra   deletec                   B    e Zd Zej                            d          ZdS )CustomFieldDeleteViewr;   N)r<   r=   r>   r?   r@   rA   rB   rI   rJ   rK   rf   rf   O   s$        "11,??HHHrJ   rf   c                   P    e Zd Zej                            d          Zej        Z	dS )CustomFieldBulkImportViewr;   N)
r<   r=   r>   r?   r@   rA   rB   r3   CustomFieldImportForm
model_formrI   rJ   rK   rh   rh   T   s,        "11,??H,JJJrJ   rh   c                   l    e Zd Zej                            d          Zej        Z	e
j        Zej        ZdS )CustomFieldBulkEditViewr;   N)r<   r=   r>   r?   r@   rA   rB   r2   rC   rD   r4   rG   rH   r3   CustomFieldBulkEditFormrc   rI   rJ   rK   rl   rl   Y   s<        "11,??H/I#E(DDDrJ   rl   c                   ^    e Zd Zej                            d          Zej        Z	e
j        ZdS )CustomFieldBulkDeleteViewr;   N)r<   r=   r>   r?   r@   rA   rB   r2   rC   rD   r4   rG   rH   rI   rJ   rK   ro   ro   `   s4        "11,??H/I#EEErJ   ro   c                   j    e Zd Zej                                        Zej        Z	e
j        Zej        ZdS )CustomFieldChoiceSetListViewN)r<   r=   r>   CustomFieldChoiceSetr@   rT   rB   r2   CustomFieldChoiceSetFilterSetrD   r3   CustomFieldChoiceSetFilterFormrF   r4   CustomFieldChoiceSetTablerH   rI   rJ   rK   rq   rq   j   s:        #+//11H8I9N,EEErJ   rq   c                   F    e Zd Zej                                        Zd ZdS )CustomFieldChoiceSetViewc                 4   t          |          }	 |j                            dd          }n# t          $ r d}Y nw xY wt	          |j        |          }	 |                    |          }n*# t          $ r |                    |j                  }Y nw xY w||dS )Npager1   )	paginatorchoices)	r'   GETget
ValueErrorr&   r{   ry   r   	num_pages)rZ   r[   r\   per_pagepage_numberrz   r{   s          rK   r^   z*CustomFieldChoiceSetView.get_extra_contextu   s     &g..	!+//&!44KK 	 	 	KKK	%h&6AA		:nn[11GG 	: 	: 	:nnY%899GGG	: #
 
 	
s   - <<A+ +$BBN)r<   r=   r>   rr   r@   rT   rB   r^   rI   rJ   rK   rw   rw   q   s7        #+//11H
 
 
 
 
rJ   rw   c                   N    e Zd Zej                                        Zej        Z	dS )CustomFieldChoiceSetEditViewN)
r<   r=   r>   rr   r@   rT   rB   r3   CustomFieldChoiceSetFormrc   rI   rJ   rK   r   r      s*        #+//11H)DDDrJ   r   c                   @    e Zd Zej                                        ZdS )CustomFieldChoiceSetDeleteViewN)r<   r=   r>   rr   r@   rT   rB   rI   rJ   rK   r   r      s"        #+//11HHHrJ   r   c                   N    e Zd Zej                                        Zej        Z	dS )"CustomFieldChoiceSetBulkImportViewN)
r<   r=   r>   rr   r@   rT   rB   r3   CustomFieldChoiceSetImportFormrj   rI   rJ   rK   r   r      s*        #+//11H5JJJrJ   r   c                   j    e Zd Zej                                        Zej        Z	e
j        Zej        ZdS ) CustomFieldChoiceSetBulkEditViewN)r<   r=   r>   rr   r@   rT   rB   r2   rs   rD   r4   ru   rH   r3    CustomFieldChoiceSetBulkEditFormrc   rI   rJ   rK   r   r      s:        #+//11H8I,E1DDDrJ   r   c                   \    e Zd Zej                                        Zej        Z	e
j        ZdS )"CustomFieldChoiceSetBulkDeleteViewN)r<   r=   r>   rr   r@   rT   rB   r2   rs   rD   r4   ru   rH   rI   rJ   rK   r   r      s2        #+//11H8I,EEErJ   r   c                   j    e Zd Zej                                        Zej        Z	e
j        Zej        ZdS )CustomLinkListViewN)r<   r=   r>   
CustomLinkr@   rT   rB   r2   CustomLinkFilterSetrD   r3   CustomLinkFilterFormrF   r4   CustomLinkTablerH   rI   rJ   rK   r   r      s:        !%%''H.I/N"EEErJ   r   c                   @    e Zd Zej                                        ZdS )CustomLinkViewNr<   r=   r>   r   r@   rT   rB   rI   rJ   rK   r   r      "        !%%''HHHrJ   r   c                   N    e Zd Zej                                        Zej        Z	dS )CustomLinkEditViewN)
r<   r=   r>   r   r@   rT   rB   r3   CustomLinkFormrc   rI   rJ   rK   r   r      s*        !%%''HDDDrJ   r   c                   @    e Zd Zej                                        ZdS )CustomLinkDeleteViewNr   rI   rJ   rK   r   r      r   rJ   r   c                   N    e Zd Zej                                        Zej        Z	dS )CustomLinkBulkImportViewN)
r<   r=   r>   r   r@   rT   rB   r3   CustomLinkImportFormrj   rI   rJ   rK   r   r      s*        !%%''H+JJJrJ   r   c                   j    e Zd Zej                                        Zej        Z	e
j        Zej        ZdS )CustomLinkBulkEditViewN)r<   r=   r>   r   r@   rT   rB   r2   r   rD   r4   r   rH   r3   CustomLinkBulkEditFormrc   rI   rJ   rK   r   r      s:        !%%''H.I"E'DDDrJ   r   c                   \    e Zd Zej                                        Zej        Z	e
j        ZdS )CustomLinkBulkDeleteViewN)r<   r=   r>   r   r@   rT   rB   r2   r   rD   r4   r   rH   rI   rJ   rK   r   r      s2        !%%''H.I"EEErJ   r   c                       e Zd Zej                                        Zej        Z	e
j        Zej        ZdZi eddhiZdS )ExportTemplateListViewzextras/exporttemplate_list.html	bulk_syncsyncN)r<   r=   r>   ExportTemplater@   rT   rB   r2   ExportTemplateFilterSetrD   r3   ExportTemplateFilterFormrF   r4   ExportTemplateTablerH   template_namer   actionsrI   rJ   rK   r   r      s_        %))++H2I3N&E5M
$fX GGGrJ   r   c                   @    e Zd Zej                                        ZdS )ExportTemplateViewNr<   r=   r>   r   r@   rT   rB   rI   rJ   rK   r   r      "        %))++HHHrJ   r   c                   N    e Zd Zej                                        Zej        Z	dS )ExportTemplateEditViewN)
r<   r=   r>   r   r@   rT   rB   r3   ExportTemplateFormrc   rI   rJ   rK   r   r      *        %))++H#DDDrJ   r   c                   @    e Zd Zej                                        ZdS )ExportTemplateDeleteViewNr   rI   rJ   rK   r   r      r   rJ   r   c                   N    e Zd Zej                                        Zej        Z	dS )ExportTemplateBulkImportViewN)
r<   r=   r>   r   r@   rT   rB   r3   ExportTemplateImportFormrj   rI   rJ   rK   r   r      *        %))++H/JJJrJ   r   c                   j    e Zd Zej                                        Zej        Z	e
j        Zej        ZdS )ExportTemplateBulkEditViewN)r<   r=   r>   r   r@   rT   rB   r2   r   rD   r4   r   rH   r3   ExportTemplateBulkEditFormrc   rI   rJ   rK   r   r      :        %))++H2I&E+DDDrJ   r   c                   \    e Zd Zej                                        Zej        Z	e
j        ZdS )ExportTemplateBulkDeleteViewN)r<   r=   r>   r   r@   rT   rB   r2   r   rD   r4   r   rH   rI   rJ   rK   r   r      2        %))++H2I&EEErJ   r   c                   @    e Zd Zej                                        ZdS )ExportTemplateBulkSyncDataViewNr   rI   rJ   rK   r   r     "        %))++HHHrJ   r   c                       e Zd Zd ZdS )SavedFilterMixinc                     t           j                                        }|j        }|j        r|S |j        r|                    d          S |                    t          d          t          |          z            S )zz
        Return only shared SavedFilters, or those owned by the current user, unless
        this is a superuser.
        T)sharedrW   )SavedFilterr@   rT   rW   is_superuseris_anonymousfilterr   )rZ   r[   rB   rW   s       rK   get_querysetzSavedFilterMixin.get_queryset  s|    
 &**,,| 	O 	0??$?///TNNNQD\\\)
 
 	
rJ   Nr<   r=   r>   r   rI   rJ   rK   r   r     s#        
 
 
 
 
rJ   r   c                   8    e Zd Zej        Zej        Ze	j
        ZdS )SavedFilterListViewN)r<   r=   r>   r2   SavedFilterFilterSetrD   r3   SavedFilterFilterFormrF   r4   SavedFilterTablerH   rI   rJ   rK   r   r     s&        /I0N#EEErJ   r   c                   @    e Zd Zej                                        ZdS )SavedFilterViewNr<   r=   r>   r   r@   rT   rB   rI   rJ   rK   r   r   %  "        "&&((HHHrJ   r   c                   T    e Zd Zej                                        Zej        Z	d Z
dS )SavedFilterEditViewc                 ,    |j         s|j        |_        |S N)pkrW   rZ   objr[   url_args
url_kwargss        rK   alter_objectz SavedFilterEditView.alter_object/  s    v 	$|CH
rJ   N)r<   r=   r>   r   r@   rT   rB   r3   SavedFilterFormrc   r   rI   rJ   rK   r   r   *  s?        "&&((H D    rJ   r   c                   @    e Zd Zej                                        ZdS )SavedFilterDeleteViewNr   rI   rJ   rK   r   r   5  r   rJ   r   c                   N    e Zd Zej                                        Zej        Z	dS )SavedFilterBulkImportViewN)
r<   r=   r>   r   r@   rT   rB   r3   SavedFilterImportFormrj   rI   rJ   rK   r   r   :  s*        "&&((H,JJJrJ   r   c                   j    e Zd Zej                                        Zej        Z	e
j        Zej        ZdS )SavedFilterBulkEditViewN)r<   r=   r>   r   r@   rT   rB   r2   r   rD   r4   r   rH   r3   SavedFilterBulkEditFormrc   rI   rJ   rK   r   r   ?  s:        "&&((H/I#E(DDDrJ   r   c                   \    e Zd Zej                                        Zej        Z	e
j        ZdS )SavedFilterBulkDeleteViewN)r<   r=   r>   r   r@   rT   rB   r2   r   rD   r4   r   rH   rI   rJ   rK   r   r   F  s2        "&&((H/I#EEErJ   r   c                   (    e Zd Zej        Zd Zd ZdS )BookmarkCreateViewc                 L    t           j                            |j                  S Nr   Bookmarkr@   r   rW   rZ   r[   s     rK   r   zBookmarkCreateView.get_querysetS      &&GL&999rJ   c                     |j         |_         |S r   r   r   s        rK   r   zBookmarkCreateView.alter_objectV      <
rJ   N)r<   r=   r>   r3   BookmarkFormrc   r   r   rI   rJ   rK   r   r   P  s:        D: : :    rJ   r   c                       e Zd Zd ZdS )BookmarkDeleteViewc                 L    t           j                            |j                  S r   r   r   s     rK   r   zBookmarkDeleteView.get_queryset^  r   rJ   Nr   rI   rJ   rK   r   r   [  s#        : : : : :rJ   r   c                   "    e Zd Zej        Zd ZdS )BookmarkBulkDeleteViewc                 L    t           j                            |j                  S r   r   r   s     rK   r   z#BookmarkBulkDeleteView.get_querysete  r   rJ   N)r<   r=   r>   r4   BookmarkTablerH   r   rI   rJ   rK   r   r   b  s+         E: : : : :rJ   r   c                   j    e Zd Zej                                        Zej        Z	e
j        Zej        ZdS )NotificationGroupListViewN)r<   r=   r>   NotificationGroupr@   rT   rB   r2   NotificationGroupFilterSetrD   r3   NotificationGroupFilterFormrF   r4   NotificationGroupTablerH   rI   rJ   rK   r  r  m  s:         (,,..H5I6N)EEErJ   r  c                   @    e Zd Zej                                        ZdS )NotificationGroupViewNr<   r=   r>   r  r@   rT   rB   rI   rJ   rK   r
  r
  t  "         (,,..HHHrJ   r
  c                   N    e Zd Zej                                        Zej        Z	dS )NotificationGroupEditViewN)
r<   r=   r>   r  r@   rT   rB   r3   NotificationGroupFormrc   rI   rJ   rK   r  r  y  s*         (,,..H&DDDrJ   r  c                   @    e Zd Zej                                        ZdS )NotificationGroupDeleteViewNr  rI   rJ   rK   r  r    r  rJ   r  c                   N    e Zd Zej                                        Zej        Z	dS )NotificationGroupBulkImportViewN)
r<   r=   r>   r  r@   rT   rB   r3   NotificationGroupImportFormrj   rI   rJ   rK   r  r    s*         (,,..H2JJJrJ   r  c                   j    e Zd Zej                                        Zej        Z	e
j        Zej        ZdS )NotificationGroupBulkEditViewN)r<   r=   r>   r  r@   rT   rB   r2   r  rD   r4   r  rH   r3   NotificationGroupBulkEditFormrc   rI   rJ   rK   r  r    s:         (,,..H5I)E.DDDrJ   r  c                   \    e Zd Zej                                        Zej        Z	e
j        ZdS )NotificationGroupBulkDeleteViewN)r<   r=   r>   r  r@   rT   rB   r2   r  rD   r4   r  rH   rI   rJ   rK   r  r    s2         (,,..H5I)EEErJ   r  c                       e Zd ZdZd ZdS )NotificationsViewz5
    HTMX-only user-specific notifications list.
    c                     t          |d|j        j                                        |j        j                                        d          S )Nhtmx/notifications.html)notificationstotal_count)r   rW   r  unreadcountr   s     rK   r}   zNotificationsView.get  sK    g8$\7>>@@"<5;;==;
 ;
   	rJ   Nr<   r=   r>   __doc__r}   rI   rJ   rK   r  r    s-             rJ   r  readc                       e Zd ZdZd ZdS )NotificationReadViewzR
    Mark the Notification read and redirect the user to its attached object.
    c                 $   t          |j        j        |          }t          j                    |_        |                                 t          |j        d          r&t          |j        
                                          S t          d          S )Nr   get_absolute_urlaccount:notifications)r   rW   r  r   nowr$  savehasattrobjectr   r)  rZ   r[   r   notifications       rK   r}   zNotificationReadView.get  s~    ()CKKK$LNN <&(:;; 	DL/@@BBCCC/000rJ   Nr"  rI   rJ   rK   r&  r&    s-         
1 
1 
1 
1 
1rJ   r&  dismissc                       e Zd ZdZd ZdS )NotificationDismissViewzP
    A convenience view which allows deleting notifications with one click.
    c                 
   t          |j        j        |          }|                                 t	          |          r7t          |dd|j        j                                        d d         i          S t          d          S )Nr(  r  r  
   r*  )r   rW   r  rd   r%   r   r   r   r/  s       rK   r}   zNotificationDismissView.get  s    ()CKKK   	'#<!;!B!B!D!DSbS!I?    /000rJ   Nr"  rI   rJ   rK   r3  r3    s-         	1 	1 	1 	1 	1rJ   r3  c                       e Zd Zd ZdS )NotificationDeleteViewc                 L    t           j                            |j                  S r   Notificationr@   r   rW   r   s     rK   r   z#NotificationDeleteView.get_queryset      #***===rJ   Nr   rI   rJ   rK   r7  r7    #        > > > > >rJ   r7  c                   "    e Zd Zej        Zd ZdS )NotificationBulkDeleteViewc                 L    t           j                            |j                  S r   r9  r   s     rK   r   z'NotificationBulkDeleteView.get_queryset  r;  rJ   N)r<   r=   r>   r4   NotificationTablerH   r   rI   rJ   rK   r>  r>    +        $E> > > > >rJ   r>  c                   (    e Zd Zej        Zd Zd ZdS )SubscriptionCreateViewc                 L    t           j                            |j                  S r   Subscriptionr@   r   rW   r   s     rK   r   z#SubscriptionCreateView.get_queryset  r;  rJ   c                     |j         |_         |S r   r   r   s        rK   r   z#SubscriptionCreateView.alter_object  r   rJ   N)r<   r=   r>   r3   SubscriptionFormrc   r   r   rI   rJ   rK   rC  rC    s:        !D> > >    rJ   rC  c                       e Zd Zd ZdS )SubscriptionDeleteViewc                 L    t           j                            |j                  S r   rE  r   s     rK   r   z#SubscriptionDeleteView.get_queryset  r;  rJ   Nr   rI   rJ   rK   rJ  rJ    r<  rJ   rJ  c                   "    e Zd Zej        Zd ZdS )SubscriptionBulkDeleteViewc                 L    t           j                            |j                  S r   rE  r   s     rK   r   z'SubscriptionBulkDeleteView.get_queryset  r;  rJ   N)r<   r=   r>   r4   SubscriptionTablerH   r   rI   rJ   rK   rM  rM    rA  rJ   rM  c                   j    e Zd Zej                                        Zej        Z	e
j        Zej        ZdS )WebhookListViewN)r<   r=   r>   Webhookr@   rT   rB   r2   WebhookFilterSetrD   r3   WebhookFilterFormrF   r4   WebhookTablerH   rI   rJ   rK   rQ  rQ    s9        ""$$H+I,NEEErJ   rQ  c                   @    e Zd Zej                                        ZdS )WebhookViewNr<   r=   r>   rR  r@   rT   rB   rI   rJ   rK   rW  rW    !        ""$$HHHrJ   rW  c                   N    e Zd Zej                                        Zej        Z	dS )WebhookEditViewN)
r<   r=   r>   rR  r@   rT   rB   r3   WebhookFormrc   rI   rJ   rK   r[  r[    s)        ""$$HDDDrJ   r[  c                   @    e Zd Zej                                        ZdS )WebhookDeleteViewNrX  rI   rJ   rK   r^  r^  	  rY  rJ   r^  c                   N    e Zd Zej                                        Zej        Z	dS )WebhookBulkImportViewN)
r<   r=   r>   rR  r@   rT   rB   r3   WebhookImportFormrj   rI   rJ   rK   r`  r`    s)        ""$$H(JJJrJ   r`  c                   j    e Zd Zej                                        Zej        Z	e
j        Zej        ZdS )WebhookBulkEditViewN)r<   r=   r>   rR  r@   rT   rB   r2   rS  rD   r4   rU  rH   r3   WebhookBulkEditFormrc   rI   rJ   rK   rc  rc    s9        ""$$H+IE$DDDrJ   rc  c                   \    e Zd Zej                                        Zej        Z	e
j        ZdS )WebhookBulkDeleteViewN)r<   r=   r>   rR  r@   rT   rB   r2   rS  rD   r4   rU  rH   rI   rJ   rK   rf  rf    s1        ""$$H+IEEErJ   rf  c                   j    e Zd Zej                                        Zej        Z	e
j        Zej        ZdS )EventRuleListViewN)r<   r=   r>   	EventRuler@   rT   rB   r2   EventRuleFilterSetrD   r3   EventRuleFilterFormrF   r4   EventRuleTablerH   rI   rJ   rK   rh  rh  $  s:         $$&&H-I.N!EEErJ   rh  c                   @    e Zd Zej                                        ZdS )EventRuleViewNr<   r=   r>   ri  r@   rT   rB   rI   rJ   rK   rn  rn  +  "         $$&&HHHrJ   rn  c                   N    e Zd Zej                                        Zej        Z	dS )EventRuleEditViewN)
r<   r=   r>   ri  r@   rT   rB   r3   EventRuleFormrc   rI   rJ   rK   rr  rr  0  s*         $$&&HDDDrJ   rr  c                   @    e Zd Zej                                        ZdS )EventRuleDeleteViewNro  rI   rJ   rK   ru  ru  6  rp  rJ   ru  c                   N    e Zd Zej                                        Zej        Z	dS )EventRuleBulkImportViewN)
r<   r=   r>   ri  r@   rT   rB   r3   EventRuleImportFormrj   rI   rJ   rK   rw  rw  ;  s*         $$&&H*JJJrJ   rw  c                   j    e Zd Zej                                        Zej        Z	e
j        Zej        ZdS )EventRuleBulkEditViewN)r<   r=   r>   ri  r@   rT   rB   r2   rj  rD   r4   rl  rH   r3   EventRuleBulkEditFormrc   rI   rJ   rK   rz  rz  @  s:         $$&&H-I!E&DDDrJ   rz  c                   \    e Zd Zej                                        Zej        Z	e
j        ZdS )EventRuleBulkDeleteViewN)r<   r=   r>   ri  r@   rT   rB   r2   rj  rD   r4   rl  rH   rI   rJ   rK   r}  r}  G  s2         $$&&H-I!EEErJ   r}  c                       e Zd Zej                             eed                    Ze	j
        Zej        Zej        ZdS )TagListViewtagitemsN)r<   r=   r>   Tagr@   annotater(   
TaggedItemrB   r2   TagFilterSetrD   r3   TagFilterFormrF   r4   TagTablerH   rI   rJ   rK   r  r  Q  sR        {##mJ.. $  H 'I(NOEEErJ   r  c                   F    e Zd Zej                                        Zd ZdS )TagViewc                 H   t           j                            |          }t          j        |d          }|                    |           d |                    d                              t          d                    D             }||	                                |dS )	N)r  F)data	orderablec                 l    g | ]1}t           j                            |d                    |d         d2S )content_typer(  
item_count)r  r  )r   r@   r}   ).0tis     rK   
<listcomp>z-TagView.get_extra_context.<locals>.<listcomp>f  sU     
 
 
  !, 3 7 72n;M 7 N N . 
 
 
rJ   r  r   )r  )taggeditem_tabletagged_item_countrS   )
r  r@   r   r4   TaggedItemTable	configurevaluesr  r   r!  )rZ   r[   r\   tagged_itemsr  rS   s         rK   r^   zTagView.get_extra_context^  s    !)00X0>>!1
 
 
 	""7+++
 
 %++N;;DDPUVZP[P[D\\	
 
 
 !1!-!3!3!5!5(
 
 	
rJ   N)r<   r=   r>   r  r@   rT   rB   r^   rI   rJ   rK   r  r  Z  s4        {  H
 
 
 
 
rJ   r  c                   N    e Zd Zej                                        Zej        Z	dS )TagEditViewN)
r<   r=   r>   r  r@   rT   rB   r3   TagFormrc   rI   rJ   rK   r  r  t  s&        {  H=DDDrJ   r  c                   @    e Zd Zej                                        ZdS )TagDeleteViewN)r<   r=   r>   r  r@   rT   rB   rI   rJ   rK   r  r  z  s        {  HHHrJ   r  c                   N    e Zd Zej                                        Zej        Z	dS )TagBulkImportViewN)
r<   r=   r>   r  r@   rT   rB   r3   TagImportFormrj   rI   rJ   rK   r  r    s'        {  H$JJJrJ   r  c                   t    e Zd Zej                             eed                    Ze	j
        Zej        ZdS )TagBulkEditViewr  r  N)r<   r=   r>   r  r@   r  r(   r  rB   r4   r  rH   r3   TagBulkEditFormrc   rI   rJ   rK   r  r    sJ        {##mJ.. $  H OE DDDrJ   r  c                   f    e Zd Zej                             eed                    Ze	j
        ZdS )TagBulkDeleteViewr  r  N)r<   r=   r>   r  r@   r  r(   r  rB   r4   r  rH   rI   rJ   rK   r  r    sB        {##mJ.. $  H OEEErJ   r  c                       e Zd Zej                                        Zej        Z	e
j        Zej        ZdZdhdhdhdhdZdS )ConfigContextListViewzextras/configcontext_list.htmladdchangerd   r   )r  	bulk_editbulk_deleter   N)r<   r=   r>   ConfigContextr@   rT   rB   r2   ConfigContextFilterSetrD   r3   ConfigContextFilterFormrF   r4   ConfigContextTablerH   r   r   rI   rJ   rK   r  r    s_        $((**H1I2N%E4MwZ zX	 GGGrJ   r  c                   F    e Zd Zej                                        Zd ZdS )ConfigContextViewc                    d|j         j        fd|j        j        fd|j        j        fd|j        j        fd|j        j        fd|j        j        fd|j        j        fd|j        j        fd	|j	        j        fd
|j
        j        fd|j        j        fd|j        j        fd|j        j        ff}|j                            d          dv rI|j                            d          }|j        j        r"|j        j                            d|d           n/|j        j        r!|j        j                            dd          }nd}||dS )NRegionszSite GroupsSites	LocationszDevice TypesRoles	PlatformszCluster TypeszCluster GroupsClusterszTenant GroupsTenantsTagsformatjsonyamldata_formatTcommitr  )assigned_objectsr  )regionsrT   site_groupssites	locationsdevice_typesroles	platformscluster_typescluster_groupsclusterstenant_groupstenantstagsr|   r}   rW   is_authenticatedconfigset)rZ   r[   r\   r  r  s        rK   r^   z#ConfigContextView.get_extra_context  sb    (,-H045hn()(,01X267hn()(,01h489x6:;*./h489(,-X]&'
" ;??8$$(888[__X..F|, L#''vd'KKK\* 	\(,,]FCCFFF !1
 
 	
rJ   N)r<   r=   r>   r  r@   rT   rB   r^   rI   rJ   rK   r  r    s7        $((**H
 
 
 
 
rJ   r  c                   N    e Zd Zej                                        Zej        Z	dS )ConfigContextEditViewN)
r<   r=   r>   r  r@   rT   rB   r3   ConfigContextFormrc   rI   rJ   rK   r  r    s*        $((**H"DDDrJ   r  c                   j    e Zd Zej                                        Zej        Z	e
j        Zej        ZdS )ConfigContextBulkEditViewN)r<   r=   r>   r  r@   rT   rB   r2   r  rD   r4   r  rH   r3   ConfigContextBulkEditFormrc   rI   rJ   rK   r  r    s:        $((**H1I%E*DDDrJ   r  c                   @    e Zd Zej                                        ZdS )ConfigContextDeleteViewNr<   r=   r>   r  r@   rT   rB   rI   rJ   rK   r  r    s"        $((**HHHrJ   r  c                   \    e Zd Zej                                        Zej        Z	e
j        ZdS )ConfigContextBulkDeleteViewN)r<   r=   r>   r  r@   rT   rB   r2   r  rD   r4   r  rH   rI   rJ   rK   r  r    s2        $((**H1I%EEErJ   r  c                   @    e Zd Zej                                        ZdS )ConfigContextBulkSyncDataViewNr  rI   rJ   rK   r  r    s"        $((**HHHrJ   r  c                       e Zd ZdZdZd ZdS )ObjectConfigContextViewNz extras/object_configcontext.htmlc                    t           j                            |j        d                              |          }|j                            d          dv rI|j                            d          }|j        j        r"|j        j        	                    d|d           n/|j        j        r!|j        j                            dd          }nd}|
                                ||| j        dS )	NrO   r  r  r  Tr  r  )rendered_contextsource_contextsr  base_template)r  r@   rV   rW   get_for_objectr|   r}   r  r  r  get_config_contextr  )rZ   r[   r\   r  r  s        rK   r^   z)ObjectConfigContextView.get_extra_context  s    '/88vNN]]^fgg ;??8$$(888[__X..F|, L#''vd'KKK\* 	\(,,]FCCFFF !) ; ; = =.!/	
 
 	
rJ   )r<   r=   r>   r  r   r^   rI   rJ   rK   r  r    s-        M6M
 
 
 
 
rJ   r  c            	           e Zd Zej                             eed           eed           ee	d           ee
d                    Zej        Zej        Zej        ZdZi eddhiZdS )ConfigTemplateListViewconfig_template)device_countvm_count
role_countplatform_countzextras/configtemplate_list.htmlr   r   N)r<   r=   r>   ConfigTemplater@   r  r(   r   r0   r   r   rB   r2   ConfigTemplateFilterSetrD   r3   ConfigTemplateFilterFormrF   r4   ConfigTemplateTablerH   r   r   r   rI   rJ   rK   r  r    s        %.."]6+<==~/@AA =->??$}X/@AA	 /  H 2I3N&E5M
$fX GGGrJ   r  c                   @    e Zd Zej                                        ZdS )ConfigTemplateViewNr<   r=   r>   r  r@   rT   rB   rI   rJ   rK   r  r    r   rJ   r  c                   N    e Zd Zej                                        Zej        Z	dS )ConfigTemplateEditViewN)
r<   r=   r>   r  r@   rT   rB   r3   ConfigTemplateFormrc   rI   rJ   rK   r  r    r   rJ   r  c                   @    e Zd Zej                                        ZdS )ConfigTemplateDeleteViewNr  rI   rJ   rK   r  r     r   rJ   r  c                   N    e Zd Zej                                        Zej        Z	dS )ConfigTemplateBulkImportViewN)
r<   r=   r>   r  r@   rT   rB   r3   ConfigTemplateImportFormrj   rI   rJ   rK   r  r  %  r   rJ   r  c                   j    e Zd Zej                                        Zej        Z	e
j        Zej        ZdS )ConfigTemplateBulkEditViewN)r<   r=   r>   r  r@   rT   rB   r2   r  rD   r4   r  rH   r3   ConfigTemplateBulkEditFormrc   rI   rJ   rK   r   r   *  r   rJ   r   c                   \    e Zd Zej                                        Zej        Z	e
j        ZdS )ConfigTemplateBulkDeleteViewN)r<   r=   r>   r  r@   rT   rB   r2   r  rD   r4   r  rH   rI   rJ   rK   r  r  1  r   rJ   r  c                   @    e Zd Zej                                        ZdS )ConfigTemplateBulkSyncDataViewNr  rI   rJ   rK   r  r  7  r   rJ   r  c                   t    e Zd Zej                                        Zej        Z	e
j        Zej        ZddhiZdS )ImageAttachmentListViewexportrO   N)r<   r=   r>   ImageAttachmentr@   rT   rB   r2   ImageAttachmentFilterSetrD   r3   ImageAttachmentFilterFormrF   r4   ImageAttachmentTablerH   r   rI   rJ   rK   r  r  ?  sH        &**,,H3I4N'E6(GGGrJ   r  c                   l     e Zd Zej                                        Zej        Z	d Z
d fd	Zd Z xZS )ImageAttachmentEditViewc                     |j         snt          t          |j                            d                    }t          |                                |j                            d                    |_        |S )Nr]   r(  	object_id)r   r   r   r|   r}   rU   parent)rZ   r\   r[   argskwargsr]   s         rK   r   z$ImageAttachmentEditView.alter_objectN  sa    { 	l+KGKOOM<Z<Z[[[K/0G0G0I0Igkoo^iNjNjkkkHOrJ   Nc                 |    |r|j                                         n t                                          |          S r   r  r)  superget_return_urlrZ   r[   r   	__class__s      rK   r  z&ImageAttachmentEditView.get_return_urlU  4    03Xsz**,,,9O9OPW9X9XXrJ   c                 l    |j                             d          |j                             d          dS )Nr]   r  )r]   r  )r|   r}   r   s     rK   get_extra_addanother_paramsz3ImageAttachmentEditView.get_extra_addanother_paramsX  s3    ";??=99 55
 
 	
rJ   r   )r<   r=   r>   r	  r@   rT   rB   r3   ImageAttachmentFormrc   r   r  r  __classcell__r  s   @rK   r  r  I  s}        &**,,H$D  Y Y Y Y Y Y
 
 
 
 
 
 
rJ   r  c                   R     e Zd Zej                                        Zd fd	Z xZS )ImageAttachmentDeleteViewNc                 |    |r|j                                         n t                                          |          S r   r  r  s      rK   r  z(ImageAttachmentDeleteView.get_return_urlc  r  rJ   r   )	r<   r=   r>   r	  r@   rT   rB   r  r  r  s   @rK   r!  r!  _  s[        &**,,HY Y Y Y Y Y Y Y Y YrJ   r!  c                       e Zd Zej                                        Zej        Z	e
j        Zej        ZdhdhdhdhdZdS )JournalEntryListViewr  rO   r  rd   )importr  r  r  N)r<   r=   r>   JournalEntryr@   rT   rB   r2   JournalEntryFilterSetrD   r3   JournalEntryFilterFormrF   r4   JournalEntryTablerH   r   rI   rJ   rK   r$  r$  k  sZ        #''))H0I1N$E'(Z z	 GGGrJ   r$  c                   @    e Zd Zej                                        ZdS )JournalEntryViewN)r<   r=   r>   r&  r@   rT   rB   rI   rJ   rK   r+  r+  x  s"        #''))HHHrJ   r+  c                   Z    e Zd Zej                                        Zej        Z	d Z
d ZdS )JournalEntryEditViewc                 ,    |j         s|j        |_        |S r   )r   rW   
created_by)rZ   r   r[   r  r  s        rK   r   z!JournalEntryEditView.alter_object  s    v 	*$\CN
rJ   c                     |j         st          d          S |j         }t          |d          }t          |d|j        i          S )Nzextras:journalentry_listjournalr   r  )assigned_objectr   r.   r   rZ   r[   r\   r   viewnames        rK   r  z#JournalEntryEditView.get_return_url  sL    ' 	75666&Y//xsv7777rJ   N)r<   r=   r>   r&  r@   rT   rB   r3   JournalEntryFormrc   r   r  rI   rJ   rK   r-  r-  }  sN        #''))H!D  
8 8 8 8 8rJ   r-  c                   F    e Zd Zej                                        Zd ZdS )JournalEntryDeleteViewc                 `    |j         }t          |d          }t          |d|j        i          S )Nr1  r   r2  )r3  r.   r   r   r4  s        rK   r  z%JournalEntryDeleteView.get_return_url  s2    &Y//xsv7777rJ   N)r<   r=   r>   r&  r@   rT   rB   r  rI   rJ   rK   r8  r8    s7        #''))H8 8 8 8 8rJ   r8  c                   j    e Zd Zej                                        Zej        Z	e
j        Zej        ZdS )JournalEntryBulkEditViewN)r<   r=   r>   r&  r@   rT   rB   r2   r'  rD   r4   r)  rH   r3   JournalEntryBulkEditFormrc   rI   rJ   rK   r;  r;    s:        #''))H0I$E)DDDrJ   r;  c                   \    e Zd Zej                                        Zej        Z	e
j        ZdS )JournalEntryBulkDeleteViewN)r<   r=   r>   r&  r@   rT   rB   r2   r'  rD   r4   r)  rH   rI   rJ   rK   r>  r>    s2        #''))H0I$EEErJ   r>  c                   N    e Zd Zej                                        Zej        Z	dS )JournalEntryBulkImportViewN)
r<   r=   r>   r&  r@   rT   rB   r3   JournalEntryImportFormrj   rI   rJ   rK   r@  r@    s*        #''))H-JJJrJ   r@  c                       e Zd ZdZd Zd ZdS )DashboardResetViewzextras/dashboard/reset.htmlc                     t          t          j                                        |j                   t                      }t          || j        |t          d          d          S )Nr   homerc   
return_url)	r   	Dashboardr@   rT   rW   r#   r   r   r   )rZ   r[   rc   s      rK   r}   zDashboardResetView.get  s`    )+//11EEEE!!gt1!&//4
 4
   	rJ   c                    t          t          j                                        |j                  }t          |j                  }|                                rR|                                 t          j
        |t          d                     t          t          d                    S t          || j        |t          d          d          S )Nr   zYour dashboard has been reset.rE  rF  )r   rH  r@   rT   rW   r#   POSTis_validrd   r   success_r   r   r   r   )rZ   r[   	dashboardrc   s       rK   postzDashboardResetView.post  s    %i&7&;&;&=&=GLQQQ	--==?? 	-Wa(H&I&IJJJGFOO,,,gt1!&//4
 4
   	rJ   Nr<   r=   r>   r   r}   rO  rI   rJ   rK   rC  rC    s7        1M      rJ   rC  c                       e Zd ZdZd Zd ZdS )DashboardWidgetAddViewz extras/dashboard/widget_add.htmlc                    |j         st          d          S |j        pddi}t          |          }t	          |d          }t          |          }|                    |j        d          }t          || j	        |||d          S )NrE  widget_classzextras.NoteWidgetinitialr  rV  prefixrT  widget_formconfig_form)
htmxr   r|   r   r$   r   
ConfigFormdefault_configr   r   )rZ   r[   rV  rZ  widget_namerT  r[  s          rK   r}   zDashboardWidgetAddView.get  s    | 	$F###+ 
/"
 -W===%k>BB'44"--l6QZb-ccgt1(&&4
 4
   	rJ   c                    t          |j                  }d }d }|                                rt          |j        d                   }|                    |j        d          }|                                r|j        }|                    d           |j        |d<    |d	i |}|j        j        	                    |           |j        j        
                                 t          j        |t          d          t          |j                  z              t!          dt#          d          i          S t%          || j        |||d          S )
NrT  r  rX  zAdded widget: HX-RedirectrE  headersrY  rI   )r   rJ  rK  r   cleaned_datar]  poprW   rN  
add_widgetr,  r   rL  rM  stridr   r   r   r   )rZ   r[   rZ  r[  rT  r  widgets          rK   rO  zDashboardWidgetAddView.post  s[   ,W\::!! 	+K,D^,TUUL&11',x1PPK##%% "/(((!,!9X%----&11&999&++--- !,<*=*=FI*NOOO#!76??-     gt1(&&4
 4
   	rJ   NrP  rI   rJ   rK   rR  rR    s7        6M  $    rJ   rR  c                       e Zd ZdZd Zd ZdS )DashboardWidgetConfigViewz#extras/dashboard/widget_config.htmlc                 V   |j         st          d          S |j        j                            |          }t          |j                  }|                    |j                            d          d          }t          || j
        |j        ||t          dd|i          d          S )	NrE  rU  r  rW  extras:dashboardwidget_configri  r2  )rT  rZ  r[  form_url)r\  r   rW   rN  
get_widgetr   	form_datar]  r}   r   r   r  r   )rZ   r[   ri  rj  rZ  r[  s         rK   r}   zDashboardWidgetConfigView.get  s    | 	$F###'22266)&2BCCC''0@0D0DX0N0NW_'``gt1",&& ?r
SSS	4
 4
   	rJ   c                    |j         j                            |          }t          |j                  }|                    |j        d          }|                                r|                                r|j        }|j        |d<   |j         j        j        t          |                   
                    |           |j         j                                         t          j        |t          d          t          |j                  z              t!          dt#          d          i          S t%          || j        ||t#          dd|i	          d
          S )Nr  ra  zUpdated widget: rb  rE  rc  rn  ri  r2  )rZ  r[  ro  )rW   rN  rp  r   rJ  r]  rK  re  r  rh  updater,  r   rL  rM  ri  r   r   r   r   )rZ   r[   ri  rj  rZ  r[  r  s          rK   rO  zDashboardWidgetConfigView.post  sL   '22266)',77''X'FF!! 		k&:&:&<&< 		+D(5DNL")#b''299$???L"'')))Wa(:&;&;c&)nn&LMMMwv)     gt1&& ?r
SSS4
 4
   	rJ   NrP  rI   rJ   rK   rl  rl    s7        9M      rJ   rl  c                       e Zd ZdZd Zd ZdS )DashboardWidgetDeleteViewzgeneric/object_delete.htmlc                     |j         st          d          S |j        j                            |          }t          |j                  }t          |d|j        j	        ||t          dd|i          d          S )NrE  rU  zhtmx/delete_form.htmlzextras:dashboardwidget_deleteri  r2  )r]   r.  rc   ro  )r\  r   rW   rN  rp  r#   r|   r   r  r<   r   )rZ   r[   ri  rj  rc   s        rK   r}   zDashboardWidgetDeleteView.get(  s    | 	$F###'22266444g6!+4 ?r
SSS	9
 9
   	rJ   c                    t          |j                  }|                                rp|j        j                            |           |j        j                                         t          j        |t          d          t          |          z              n=t          j        |t          d          t          |j        d                   z              t          t          d                    S )NzDeleted widget: zError deleting widget: r   rE  )r#   rJ  rK  rW   rN  delete_widgetr,  r   rL  rM  rh  errorerrorsr   r   )rZ   r[   ri  rc   s       rK   rO  zDashboardWidgetDeleteView.post6  s    --==?? 	XL"00444L"'')))Wa(:&;&;c"gg&EFFFFN7A&?$@$@3t{ST~CVCV$VWWW(((rJ   NrP  rI   rJ   rK   ru  ru  %  s7        0M  
) 
) 
) 
) 
)rJ   ru  c                   J    e Zd Zej                                        ZeZd Z	dS )ScriptModuleCreateViewc                 (    t           j        |_        |S r   )r   SCRIPTS	file_root)rZ   r   r  r  s       rK   r   z#ScriptModuleCreateView.alter_objectL  s    2:
rJ   N)
r<   r=   r>   ScriptModuler@   rT   rB   r   rc   r   rI   rJ   rK   r|  r|  G  s<        #''))HD    rJ   r|  c                   D    e Zd Zej                                        ZdZdS )ScriptModuleDeleteViewzextras:script_listN)r<   r=   r>   r  r@   rT   rB   default_return_urlrI   rJ   rK   r  r  Q  s*        #''))H-rJ   r  c                       e Zd Zd Zd ZdS )ScriptListViewc                     dS Nzextras.view_scriptrI   rZ   s    rK   get_required_permissionz&ScriptListView.get_required_permissionY      ##rJ   c                     t           j                            |j                                      ddd          }t          |dt           |d          S )Ndata_source	data_filejobszextras/script_list.html)modelscript_modules)r  r@   rV   rW   prefetch_relatedr   )rZ   r[   r  s      rK   r}   zScriptListView.get\  sZ    %-66w|DDUU;
 
 g8!,;
 ;
   	rJ   N)r<   r=   r>   r  r}   rI   rJ   rK   r  r  W  s2        $ $ $    rJ   r  c                   F    e Zd Zej                                        Zd ZdS )BaseScriptViewc                 ,    |j         x}r
 |            S dS )zA
        Return an instance of the Script's Python class
        N)python_class)rZ   scriptscript_classs      rK   _get_script_classz BaseScriptView._get_script_classj  s*     "..< 	"<>>!	" 	"rJ   N)r<   r=   r>   Scriptr@   rT   rB   r  rI   rJ   rK   r  r  g  s6        ~!!##H" " " " "rJ   r  c                       e Zd Zd Zd ZdS )
ScriptViewc           	          | j         di |}|                     |          }|st          |dd|i          S |                    t	          |j                            }t          |d||||j                                        d          S )Nextras/script.htmlr  rU  r  r  rc   	job_countrI   )
get_objectr  r   as_formr)   r|   r  r!  )rZ   r[   r  r  r  rc   s         rK   r}   zScriptView.gett  s     **6**--f55 	'#7&:    ##,?,L,L#MMg3(**,,	6
 6
   	rJ   c                 d    | j         di |}|j                            d|          st                      S |                     |          }|st          |dd|i          S |                    |j        |j                  }t          d          s#t          j        |t          d                     n|                                rt          d          }|                    ||j        |j                            d          |j                            d	          |j        t%          |          |j        j        |j                            d
                    }t+          d|j                  S t          |d||                                ||j                                        d          S )Nzextras.run_script)r   r  r  defaultz4Unable to run script: RQ worker process not running.zextras.jobs.ScriptJob_schedule_at	_interval_commit)r\   rW   schedule_atintervalr  r[   job_timeoutr  zextras:script_result)job_pkr  rI   )r  rW   has_permr
   r  r   r  rJ  FILESr+   r   ry  rM  rK  r   enqueuere  rf  r*   r  r  r   r   r  r!  )rZ   r[   r  r  r  rc   	ScriptJobjobs           rK   rO  zScriptView.post  s    **6**|$$%8f$EE 	+(***--f55 	'#7&:    ##GL'-@@ %Y// 	CN7A&\$]$]^^^^]]__ 	C%&=>>I##\ -11.AA*..{;;&)'22"/;(,,Y77 $ 	 	C 236BBBBg3"//11**,,	6
 6
   	rJ   N)r<   r=   r>   r}   rO  rI   rJ   rK   r  r  r  s2          "% % % % %rJ   r  c                   F    e Zd Zej                                        Zd ZdS )ScriptSourceViewc           	           | j         di |}|                     |          }t          |d|||j                                        dd          S )Nzextras/script/source.htmlsource)r  r  r  tabrI   )r  r  r   r  r!  )rZ   r[   r  r  r  s        rK   r}   zScriptSourceView.get  sg     **6**--f55g:(**,,	=
 =
   	rJ   Nr<   r=   r>   r  r@   rT   rB   r}   rI   rJ   rK   r  r    s6        ~!!##H	 	 	 	 	rJ   r  c                   F    e Zd Zej                                        Zd ZdS )ScriptJobsViewc           	           | j         di |}t          |j                                        d|j                  }|                    |           t          |d|||j                                        dd          S )NF)r  r  rW   zextras/script/jobs.htmlr  )r  rH   r  r  rI   )r  r   r  rT   rW   r  r   r!  )rZ   r[   r  r  
jobs_tables        rK   r}   zScriptJobsView.get  s     **6**""
 
 


 	W%%%g8**,,	;
 ;
   	rJ   Nr  rI   rJ   rK   r  r    s6        ~!!##H    rJ   r  c                   T    e Zd Zej                                        Zd ZddZd Z	dS )ScriptResultViewc                     dS r  rI   r  s    rK   r  z(ScriptResultView.get_required_permission  r  rJ   Tc           
      \   g }d }d }d}	 t           |j                            dt          j                           }n'# t
          $ r t           t          j                 }Y nw xY w|j        rd|j        v rd|j        v r|j        d         }|j        d         D ]}	t          j        |	                    d          t          j                  }
|
|k    r|dz  }||	                    d          |	                    d          |	                    d          |	                    d	          |	                    d
          d}|                    |           t          ||j
                  }|                    |           n|j        }|r|                                D ]c\  }}d|v rZ|d         D ]Q\  }}}}}t          j        |t          j                  }
|
|k    r$|dz  }|||||||d}|                    |           Rdt          ||j
                  }|                    |           |S )Nr   log_thresholdlogtestsstatusr1   timemessager   url)indexr  r  r  r.  r  r   )r  methodr  r  r.  r  r  )r5   r|   r}   r   	LOG_DEBUGKeyErrorr  LOG_DEFAULTappendr8   rW   r  r  r7   )rZ   r  r[   bulk_actionsr  r  rH   r  r  r  	log_levelresultr  	test_datar  r  r   r  r  s                      rK   	get_tablezScriptResultView.get_table  sY   	F*7;???OLe+f+fgMM 	F 	F 	F*?+DEMMM	F8 	!  ch&&HW-E8E? , ,C . 237783D3DoFa b bI M11
%*$'GGFOO&)ggh&7&7'*wwy'9'9&)ggenn#&775>>" " F+++*4glCCC((((  	%%*[[]] 0 0!	I%%;DU;K 0 07fc3$2$6v?Z$[$[	$55!QJE).*0(,*0*-'*+2& &F !KK///&t',???EOOG$$$s   0; !AAc                    d }t          t          j                                        |                    d                    }|j        r|                     ||d          }|j                            dt          j	                  }|t          vrt          j	        }|j        ||t          t                    |d}|j        r(d|j        v r|j                            di           |d<   n-|j        r&d	 |j                                        D             |d<   t          |          rS|j                            d          rt!          |d
|          S t!          |d|          }|j        s|j        sd|_        |S t!          |d|          S )Nr  r(  F)r  r  )r  r  rH   
log_levelsr  r  r  c                 D    i | ]\  }}|                     d           ||S )test_)
startswith)r  rY   r  s      rK   
<dictcomp>z(ScriptResultView.get.<locals>.<dictcomp>*  s@          )tT??7++ d     rJ   zhtmx/table.htmlzextras/htmx/script_result.htmli  zextras/script_result.html)r   r   r@   rT   r}   	completedr  r|   r   r  r5   r.  dictr  r  r%   r   startedstatus_code)rZ   r[   r  rH   r  r  contextresponses           rK   r}   zScriptResultView.get  s    1 1fjj6J6JKKK= 	ENN3eNDDE9RSS..+5M j//*
 
 8 	))"x||GR88GGX 	   -0X^^-=-=     GG    	{u%% Cg'8'BBBg'GQQH} +CK +'*$Og:GDDDrJ   N)T)
r<   r=   r>   r   r@   rT   rB   r  r  r}   rI   rJ   rK   r  r    s]        {  H$ $ $9 9 9 9v'E 'E 'E 'E 'ErJ   r  c                       e Zd Zd ZdS )RenderMarkdownViewc                     t          j        |j                  }|                                st	                       t          |j        d                   }t          |          S )Ntext)r3   RenderMarkdownFormrJ  rK  r	   r,   re  r   )rZ   r[   rc   rendereds       rK   rO  zRenderMarkdownView.postB  sS    '55}} 	%"$$$"4#4V#<==H%%%rJ   N)r<   r=   r>   rO  rI   rJ   rK   r  r  @  s#        & & & & &rJ   r  N)django.contribr   django.contrib.auth.mixinsr   "django.contrib.contenttypes.modelsr   django.core.paginatorr   django.db.modelsr   r   django.httpr	   r
   r   django.shortcutsr   r   r   django.urlsr   django.utils.module_loadingr   django.utilsr   django.utils.translationr   rM  django.views.genericr   core.choicesr   
core.formsr   core.modelsr   core.tablesr   dcim.modelsr   r   r   extras.choicesr   extras.dashboard.formsr   r   extras.dashboard.utilsr   netbox.constantsr   netbox.registryr    netbox.viewsr!   netbox.views.generic.mixinsr"   utilities.formsr#   r$   utilities.htmxr%   utilities.paginatorr&   r'   utilities.queryr(   utilities.querydictr)   utilities.requestr*   utilities.rqworkerr+   'utilities.templatetags.builtins.filtersr,   utilities.viewsr-   r.   r/   virtualization.modelsr0   rQ   r2   r3   r4   	constantsr5   modelsr7   r8   ObjectListViewr:   r?   
ObjectViewrM   ObjectEditViewra   ObjectDeleteViewrf   BulkImportViewrh   BulkEditViewrl   BulkDeleteViewro   rq   rr   rw   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   BulkSyncDataViewr   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r
  r  r  r  r  r  r  r:  r&  r3  r7  r>  rC  rF  rJ  rM  rQ  rR  rW  r[  r^  r`  rc  rf  rh  ri  rn  rr  ru  rw  rz  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r	  r  r!  r$  r&  r+  r-  r8  r;  r>  r@  rC  rR  rl  ru  r  r|  r  r  r  r  r  r  r  r  rI   rJ   rK   <module>r     s   # # # # # # 9 9 9 9 9 9 : : : : : : + + + + + + % % % % % % % % S S S S S S S S S S @ @ @ @ @ @ @ @ @ @       5 5 5 5 5 5 ! ! ! ! ! ! 1 1 1 1 1 1 % % % % % % 3 3 3 3 3 3 & & & & & &                   4 4 4 4 4 4 4 4 4 4 * * * * * * N N N N N N N N 3 3 3 3 3 3 7 7 7 7 7 7 $ $ $ $ $ $             2 2 2 2 2 2 = = = = = = = = ' ' ' ' ' ' E E E E E E E E ) ) ) ) ) ) 3 3 3 3 3 3 / / / / / / 4 4 4 4 4 4 C C C C C C a a a a a a a a a a 0 0 0 0 0 0 ' ' ' ' ' ' ' ' ' ' % % % % % %     : : : : : : : :$ $ $ $ $'0 $ $ $ [!!
 
 
 
 
g( 
 
 "!
& [&))! ! ! ! !'0 ! ! *)!
 [(++@ @ @ @ @G4 @ @ ,+@- - - - - 6 - - -
) ) ) ) )g2 ) ) )$ $ $ $ $ 6 $ $ $- - - - -7#9 - - - )**
 
 
 
 
w1 
 
 +*
. )622* * * * *7#9 * * 32*
 )8442 2 2 2 2W%= 2 2 5426 6 6 6 6)? 6 6 6
2 2 2 2 2w'; 2 2 2- - - - -)? - - -# # # # #/ # # # Z  ( ( ( ( (W' ( ( ! ( Z((         /     )( 
 Z**( ( ( ( (73 ( ( +*(, , , , ,w5 , , ,
( ( ( ( (W1 ( ( (# # # # #w5 # # #	 	 	 	 	W3 	 	 	 ^$$, , , , ,+ , , %$, ^V,,$ $ $ $ $W3 $ $ -,$
 ^X.., , , , ,w7 , , /.,0 0 0 0 07#9 0 0 0
, , , , ,!5 , , ,' ' ' ' '7#9 ' ' ', , , , ,W%= , , ,
 
 
 
 
 
 
 
$$ $ $ $ $*G,B $ $ $ [!!) ) ) ) )&(: ) ) "!) [&))    *G,B   *) [(++) ) ) ) ),g.F ) ) ,+)- - - - - 0'2H - - -
) ) ) ) ).0D ) ) )$ $ $ $ $ 0'2H $ $ $    /    Xx((: : : : :1 : : )(:: : : : :W3 : : :* * * * * 6 * * * &''/ / / / /G. / / ('/ &//' ' ' ' ' 6 ' ' 0/'
 &11/ / / / /'": / / 21/3 3 3 3 3g&< 3 3 3
/ / / / /G$8 / / /* * * * *g&< * * *    *D    \6**1 1 1 1 1-t 1 1 +*1" \9--1 1 1 1 10$ 1 1 .-1  \8,,> > > > >W5 > > -,>> > > > >!7 > > >    W3    \8,,> > > > >W5 > > -,>> > > > >!7 > > >         g,       W% % % % %'$ % % % Wf%%    g,   &%
 Wh''% % % % %0 % % ('%) ) ) ) )G2 ) ) )
% % % % %'. % % %         G2      " " " " ". " " " Y' ' ' ' 'G& ' '  ' Y''    .   ('
 Y))' ' ' ' ''2 ' ' *)'+ + + + +g4 + + +
' ' ' ' 'G0 ' ' '" " " " "g4 " " "    '(    S
 
 
 
 
g  
 
 
2 S&!!    '(   "!
 S(##! ! ! ! !G, ! ! $#!% % % % %. % % %
! ! ! ! !g* ! ! !    .       G2    ]##"
 "
 "
 "
 "
* "
 "
 $#"
J ]F++# # # # #G2 # # ,+#
+ + + + + 4 + + + ]H--+ + + + +g6 + + .-+& & & & &'"8 & & &+ + + + +G$< + + +
 
 
 
 
g0 
 
 
:    W3   " ^$$, , , , ,+ , , %$, ^V,,$ $ $ $ $W3 $ $ -,$
 ^X.., , , , ,w7 , , /.,0 0 0 0 07#9 0 0 0
, , , , ,!5 , , ,' ' ' ' '7#9 ' ' ', , , , ,W%= , , ,    g4    _f--
 
 
 
 
g4 
 
 .-
* _h//Y Y Y Y Y 8 Y Y 0/Y
 
 
 
 
71 
 
 
 \""* * * * *w) * * #"* \6**8 8 8 8 871 8 8 +*8" \8,,8 8 8 8 8W5 8 8 -,8* * * * *w3 * * *% % % % %!7 % % %. . . . .!7 . . .    +T   6/ / / / // / / /d& & & & & 2D & & &R) ) ) ) ) 2D ) ) )D \6**    W3   +* \8,,. . . . .W5 . . -,.
    7    " " " " "W' " " "8 8 8 8 8 8 8 8v    ~       ^   *hE hE hE hE hEz7#5 hE hE hE^& & & & &+T & & & & &rJ   