-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v1.4.4 Use middleware to inject, add opendelay
- Loading branch information
Showing
9 changed files
with
102 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
recursive-include netbox_contextmenus/templates *.html | ||
recursive-include netbox_contextmenus/static *.js | ||
recursive-include netbox_contextmenus/templates *.js | ||
recursive-include netbox_contextmenus/templates *.css |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from netbox.settings import VERSION # type: ignore | ||
if VERSION.startswith("3."): | ||
from extras.plugins import get_plugin_config # type: ignore | ||
else: | ||
from netbox.plugins import get_plugin_config # type: ignore | ||
|
||
import re | ||
|
||
|
||
class ContextMenusMiddleware: | ||
|
||
def __init__(self, get_response): | ||
self.get_response = get_response | ||
|
||
def __call__(self, request): | ||
response = self.get_response(request) | ||
request_path = request.get_full_path() | ||
NBCM_JSPATH = get_plugin_config('netbox_contextmenus', 'nbcmjspath') | ||
|
||
if request_path.startswith('/api/'): | ||
return response | ||
if NBCM_JSPATH == request.get_full_path(): | ||
return response | ||
|
||
NBCM_JS = '<script src="'+NBCM_JSPATH+'" defer></script>' | ||
content = str(response.content) | ||
if not NBCM_JS in content: | ||
response.content=re.sub( | ||
b'</head>', | ||
bytes(NBCM_JS, response.charset) + b'\n </head>', | ||
response.content, | ||
flags=re.IGNORECASE | ||
) | ||
return response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
__name__ = 'netbox_contextmenus' | ||
__version__ = '1.4.3' | ||
__version__ = '1.4.4' | ||
__description__ = 'Add context menu to links in NetBox' | ||
__author__ = 'Pieter Lambrecht' | ||
__author_email__ = '[email protected]' | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.urls import path | ||
from .views import ContextMenuRenderView | ||
|
||
urlpatterns = [ | ||
path('nbcmrender/', ContextMenuRenderView.as_view(), name='nbcmrender'), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from django.shortcuts import render | ||
from django.views.generic import View | ||
|
||
from netbox.settings import VERSION # type: ignore | ||
if VERSION.startswith("3."): | ||
from extras.plugins import get_plugin_config # type: ignore | ||
else: | ||
from netbox.plugins import get_plugin_config # type: ignore | ||
|
||
class ContextMenuRenderView(View): | ||
def get(self, request): | ||
return render( | ||
request, | ||
'netbox_contextmenus/nbcm.js', | ||
{ 'opendelay' : get_plugin_config('netbox_contextmenus', 'nbcmopendelay') }, | ||
content_type='application/javascript' | ||
) |