-
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.
And a real plugin now
- Loading branch information
Showing
8 changed files
with
133 additions
and
5 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.vscode | ||
env | ||
.DS_Store | ||
__pycache__ | ||
dist | ||
build | ||
*.egg-info |
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,2 @@ | ||
recursive-include netbox_contextmenus/templates *.html | ||
recursive-include netbox_contextmenus/static *.js |
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,50 @@ | ||
from netbox.plugins import PluginConfig | ||
|
||
from .pluginvars import __version__ | ||
from .pluginvars import __name__ | ||
from .pluginvars import __description__ | ||
from .pluginvars import __author__ | ||
from .pluginvars import __author_email__ | ||
|
||
class NetboxContextMenusConfig(PluginConfig): | ||
name = __name__ | ||
verbose_name = 'NetBox ContextMenu' | ||
description = __description__ | ||
version = __version__ | ||
author = __author__ | ||
author_email = __author_email__ | ||
required_settings = [] | ||
default_settings = { | ||
'nbcmjs': '<script src="/static/netbox_contextmenus/nbcm.js"></script>' | ||
} | ||
baseurl = 'netbox_contextmenus' | ||
|
||
|
||
def ready(self): | ||
import netbox_contextmenus.signals | ||
super().ready() | ||
|
||
from core.models import ConfigRevision | ||
from netbox.config import get_config | ||
from django.core.cache import cache | ||
|
||
NBCM_JS = self.default_settings['nbcmjs'] | ||
|
||
cache.clear() | ||
nb_config = get_config() | ||
nb_config._populate_from_db() | ||
ConfigRevisions = ConfigRevision.objects.all() | ||
if not ConfigRevisions: | ||
DefaultConfigRevisionParams = get_config().config | ||
ConfigRevisionItem = ConfigRevision.objects.create(data = DefaultConfigRevisionParams) | ||
ConfigRevisionItem.save() | ||
else: | ||
for ConfigRevisionItem in ConfigRevisions: | ||
if ConfigRevisionItem.is_active: | ||
if NBCM_JS not in getattr(ConfigRevisionItem, 'BANNER_BOTTOM' ,''): | ||
ConfigRevisionItem.save() | ||
|
||
|
||
|
||
config = NetboxContextMenusConfig | ||
|
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 @@ | ||
__name__ = 'netbox_contextmenus' | ||
__version__ = '1.4.0' | ||
__description__ = 'Add context menu to links in NetBox' | ||
__author__ = 'Pieter Lambrecht' | ||
__author_email__ = '[email protected]' | ||
__url__ = 'https://github.com/PieterL75/netbox_contextmenus' |
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,21 @@ | ||
from django.db.models.signals import pre_save, post_delete | ||
from django.dispatch import Signal, receiver | ||
|
||
from core.models import ConfigRevision | ||
from netbox.plugins import get_plugin_config | ||
from netbox.config import get_config | ||
|
||
@receiver(pre_save, sender=ConfigRevision) | ||
def update_configrevision(sender, instance, **kwargs): | ||
NBCM_JS = get_plugin_config('netbox_contextmenus', 'nbcmjs') | ||
BANNER_BOTTOM = instance.data.get('BANNER_BOTTOM' ,'') | ||
if NBCM_JS not in BANNER_BOTTOM: | ||
instance.data['BANNER_BOTTOM'] = BANNER_BOTTOM + NBCM_JS | ||
|
||
@receiver(post_delete, sender=ConfigRevision) | ||
def postdelete_configrevision(sender, instance, **kwargs): | ||
ConfigRevisions = ConfigRevision.objects.all() | ||
if not ConfigRevisions: | ||
DefaultConfigRevisionParams = get_config().config | ||
ConfigRevisionItem = ConfigRevision.objects.create(data = DefaultConfigRevisionParams) | ||
ConfigRevisionItem.save() |
File renamed without changes.
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,43 @@ | ||
import codecs | ||
import os.path | ||
|
||
from setuptools import find_packages, setup | ||
|
||
|
||
with open("README.md", "r") as fh: | ||
long_description = fh.read() | ||
|
||
|
||
def read(rel_path): | ||
here = os.path.abspath(os.path.dirname(__file__)) | ||
with codecs.open(os.path.join(here, rel_path), 'r') as fp: | ||
return fp.read() | ||
|
||
|
||
def get_pluginvar(variable,rel_path): | ||
for line in read(rel_path).splitlines(): | ||
if line.startswith(f'__{variable}__'): | ||
delim = '"' if '"' in line else "'" | ||
return line.split(delim)[1] | ||
else: | ||
raise RuntimeError(f"Unable to find {variable} string in f{rel_path}.") | ||
|
||
|
||
setup( | ||
name=get_pluginvar('name','netbox_contextmenus/pluginvars.py'), | ||
version=get_pluginvar('version','netbox_contextmenus/pluginvars.py'), | ||
description=get_pluginvar('description','netbox_contextmenus/pluginvars.py'), | ||
long_description=long_description, | ||
long_description_content_type="text/markdown", | ||
url=get_pluginvar('url','netbox_contextmenus/pluginvars.py'), | ||
author=get_pluginvar('author','netbox_contextmenus/pluginvars.py'), | ||
author_email=get_pluginvar('author_email','netbox_contextmenus/pluginvars.py'), | ||
install_requires=[], | ||
packages=find_packages(), | ||
include_package_data=True, | ||
classifiers=[ | ||
'Development Status :: 2 - Pre-Alpha', | ||
'Framework :: Django', | ||
'Programming Language :: Python :: 3', | ||
] | ||
) |