mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-08 08:38:16 -06:00
7025 change to api fields
This commit is contained in:
parent
7594ecc790
commit
3964e8176d
@ -10,6 +10,13 @@ from django.utils.translation import gettext_lazy as _
|
|||||||
from utilities.datetime import datetime_from_timestamp
|
from utilities.datetime import datetime_from_timestamp
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class PluginAuthor:
|
||||||
|
name: str = ''
|
||||||
|
org_id: str = ''
|
||||||
|
url: str = ''
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class PluginVersion:
|
class PluginVersion:
|
||||||
date: datetime.datetime = None
|
date: datetime.datetime = None
|
||||||
@ -25,22 +32,25 @@ class PluginVersion:
|
|||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Plugin:
|
class Plugin:
|
||||||
slug: str = ''
|
id: str = ''
|
||||||
config_name: str = ''
|
status: str = ''
|
||||||
name: str = ''
|
title_short: str = ''
|
||||||
title_long: str = ''
|
title_long: str = ''
|
||||||
tag_line: str = ''
|
tag_line: str = ''
|
||||||
description_short: str = ''
|
description_short: str = ''
|
||||||
author: str = ''
|
slug: str = ''
|
||||||
homepage_url: str = ''
|
author: PluginAuthor = field(default_factory=PluginAuthor)
|
||||||
|
created_at: datetime.datetime = None
|
||||||
|
updated_at: datetime.datetime = None
|
||||||
license_type: str = ''
|
license_type: str = ''
|
||||||
created: datetime.datetime = None
|
homepage_url: str = ''
|
||||||
updated: datetime.datetime = None
|
package_name_pypi: str = ''
|
||||||
is_local: bool = False
|
config_name: str = ''
|
||||||
is_installed: bool = False
|
|
||||||
is_certified: bool = False
|
is_certified: bool = False
|
||||||
is_community: bool = False
|
release_latest: PluginVersion = field(default_factory=PluginVersion)
|
||||||
versions: list[PluginVersion] = field(default_factory=list)
|
release_recent_history: list[PluginVersion] = field(default_factory=list)
|
||||||
|
is_local: bool = False # extra field for locall intsalled plugins
|
||||||
|
is_installed: bool = False
|
||||||
|
|
||||||
|
|
||||||
def get_local_plugins():
|
def get_local_plugins():
|
||||||
@ -52,15 +62,13 @@ def get_local_plugins():
|
|||||||
plugin_module = "{}.{}".format(plugin_config.__module__, plugin_config.__name__) # type: ignore
|
plugin_module = "{}.{}".format(plugin_config.__module__, plugin_config.__name__) # type: ignore
|
||||||
plugins[plugin_config.name] = Plugin(
|
plugins[plugin_config.name] = Plugin(
|
||||||
slug=plugin_config.name,
|
slug=plugin_config.name,
|
||||||
name=plugin_config.verbose_name,
|
title_short=plugin_config.verbose_name,
|
||||||
tag_line=plugin_config.description,
|
tag_line=plugin_config.description,
|
||||||
description_short=plugin_config.description,
|
description_short=plugin_config.description,
|
||||||
author=plugin_config.author or _('Unknown Author'),
|
|
||||||
is_local=True,
|
is_local=True,
|
||||||
is_installed=True,
|
is_installed=True,
|
||||||
is_certified=False,
|
|
||||||
is_community=False,
|
|
||||||
)
|
)
|
||||||
|
plugins[plugin_config.name].author.name = plugin_config.author or _('Unknown Author')
|
||||||
|
|
||||||
return plugins
|
return plugins
|
||||||
|
|
||||||
@ -100,24 +108,40 @@ def get_catalog_plugins():
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
versions = sorted(versions, key=lambda x: x.date, reverse=True)
|
versions = sorted(versions, key=lambda x: x.date, reverse=True)
|
||||||
|
latest = PluginVersion(
|
||||||
|
date=datetime_from_timestamp(data['release_latest']['date']),
|
||||||
|
version=data['release_latest']['version'],
|
||||||
|
netbox_min_version=data['release_latest']['netbox_min_version'],
|
||||||
|
netbox_max_version=data['release_latest']['netbox_max_version'],
|
||||||
|
has_model=data['release_latest']['has_model'],
|
||||||
|
is_certified=data['release_latest']['is_certified'],
|
||||||
|
is_feature=data['release_latest']['is_feature'],
|
||||||
|
is_integration=data['release_latest']['is_integration'],
|
||||||
|
is_netboxlabs_supported=data['release_latest']['is_netboxlabs_supported'],
|
||||||
|
)
|
||||||
|
author = PluginAuthor(
|
||||||
|
name=data['author']['name'],
|
||||||
|
org_id=data['author']['org_id'],
|
||||||
|
url=data['author']['url'],
|
||||||
|
)
|
||||||
plugins[data['slug']] = Plugin(
|
plugins[data['slug']] = Plugin(
|
||||||
slug=data['slug'],
|
id=data['id'],
|
||||||
config_name=data['config_name'],
|
status=data['status'],
|
||||||
name=data['title_short'],
|
title_short=data['title_short'],
|
||||||
title_long=data['title_long'],
|
title_long=data['title_long'],
|
||||||
tag_line=data['tag_line'],
|
tag_line=data['tag_line'],
|
||||||
description_short=data['description_short'],
|
description_short=data['description_short'],
|
||||||
author=data['author']['name'] or _('Unknown Author'),
|
slug=data['slug'],
|
||||||
homepage_url=data['homepage_url'],
|
author=author,
|
||||||
|
created_at=datetime_from_timestamp(data['created_at']),
|
||||||
|
updated_at=datetime_from_timestamp(data['updated_at']),
|
||||||
license_type=data['license_type'],
|
license_type=data['license_type'],
|
||||||
created=datetime_from_timestamp(data['created_at']),
|
homepage_url=data['homepage_url'],
|
||||||
updated=datetime_from_timestamp(data['updated_at']),
|
package_name_pypi=data['package_name_pypi'],
|
||||||
is_local=False,
|
config_name=data['config_name'],
|
||||||
is_installed=False,
|
is_certified=data['is_certified'],
|
||||||
is_certified=data['release_latest']['is_certified'],
|
release_latest=latest,
|
||||||
is_community=not data['release_latest']['is_certified'],
|
release_recent_history=versions,
|
||||||
versions=versions,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return plugins
|
return plugins
|
||||||
@ -126,6 +150,7 @@ def get_catalog_plugins():
|
|||||||
def get_plugins():
|
def get_plugins():
|
||||||
local_plugins = get_local_plugins()
|
local_plugins = get_local_plugins()
|
||||||
catalog_plugins = cache.get('plugins-catalog-feed')
|
catalog_plugins = cache.get('plugins-catalog-feed')
|
||||||
|
catalog_plugins = None
|
||||||
if not catalog_plugins:
|
if not catalog_plugins:
|
||||||
catalog_plugins = get_catalog_plugins()
|
catalog_plugins = get_catalog_plugins()
|
||||||
cache.set('plugins-catalog-feed', catalog_plugins, 3600)
|
cache.set('plugins-catalog-feed', catalog_plugins, 3600)
|
||||||
|
@ -42,11 +42,12 @@ class PluginVersionTable(BaseTable):
|
|||||||
|
|
||||||
|
|
||||||
class CatalogPluginTable(BaseTable):
|
class CatalogPluginTable(BaseTable):
|
||||||
name = tables.Column(
|
title_short = tables.Column(
|
||||||
linkify=('core:plugin', [tables.A('slug')]),
|
linkify=('core:plugin', [tables.A('slug')]),
|
||||||
verbose_name=_('Name')
|
verbose_name=_('Name')
|
||||||
)
|
)
|
||||||
author = tables.Column(
|
author = tables.Column(
|
||||||
|
accessor=tables.A('author.name'),
|
||||||
verbose_name=_('Author')
|
verbose_name=_('Author')
|
||||||
)
|
)
|
||||||
is_local = tables.BooleanColumn(
|
is_local = tables.BooleanColumn(
|
||||||
@ -58,18 +59,18 @@ class CatalogPluginTable(BaseTable):
|
|||||||
is_certified = tables.BooleanColumn(
|
is_certified = tables.BooleanColumn(
|
||||||
verbose_name=_('Certified')
|
verbose_name=_('Certified')
|
||||||
)
|
)
|
||||||
created = tables.Column(
|
created_at = tables.Column(
|
||||||
verbose_name=_('Published')
|
verbose_name=_('Published')
|
||||||
)
|
)
|
||||||
updated = tables.Column(
|
updated_at = tables.Column(
|
||||||
verbose_name=_('Updated')
|
verbose_name=_('Updated')
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta(BaseTable.Meta):
|
class Meta(BaseTable.Meta):
|
||||||
empty_text = _('No plugin data found')
|
empty_text = _('No plugin data found')
|
||||||
fields = (
|
fields = (
|
||||||
'name', 'author', 'is_local', 'is_installed', 'is_certified', 'created', 'updated',
|
'title_short', 'author', 'is_local', 'is_installed', 'is_certified', 'created_at', 'updated_at',
|
||||||
)
|
)
|
||||||
default_columns = (
|
default_columns = (
|
||||||
'name', 'author', 'is_local', 'is_installed', 'is_certified', 'created', 'updated',
|
'title_short', 'author', 'is_local', 'is_installed', 'is_certified', 'created_at', 'updated_at',
|
||||||
)
|
)
|
||||||
|
@ -664,7 +664,7 @@ class PluginListView(UserPassesTestMixin, View):
|
|||||||
# Certified catalog plugins
|
# Certified catalog plugins
|
||||||
# Remaining catalog plugins
|
# Remaining catalog plugins
|
||||||
# With alphabetical sort within each traunch.
|
# With alphabetical sort within each traunch.
|
||||||
plugins = sorted(plugins, key=lambda x: x.name, reverse=False)
|
plugins = sorted(plugins, key=lambda x: x.title_short, reverse=False)
|
||||||
plugins = sorted(plugins, key=lambda x: x.is_certified, reverse=True)
|
plugins = sorted(plugins, key=lambda x: x.is_certified, reverse=True)
|
||||||
plugins = sorted(plugins, key=lambda x: x.is_installed, reverse=True)
|
plugins = sorted(plugins, key=lambda x: x.is_installed, reverse=True)
|
||||||
|
|
||||||
@ -692,10 +692,11 @@ class PluginView(UserPassesTestMixin, View):
|
|||||||
plugins = get_plugins()
|
plugins = get_plugins()
|
||||||
plugin = plugins[name]
|
plugin = plugins[name]
|
||||||
|
|
||||||
table = PluginVersionTable(plugin.versions, user=request.user)
|
table = PluginVersionTable(plugin.release_recent_history, user=request.user)
|
||||||
table.configure(request)
|
table.configure(request)
|
||||||
|
|
||||||
return render(request, 'core/plugin.html', {
|
return render(request, 'core/plugin.html', {
|
||||||
'plugin': plugin,
|
'plugin': plugin,
|
||||||
'table': table,
|
'table': table,
|
||||||
|
'show_install': settings.RELEASE.edition == 'Community'
|
||||||
})
|
})
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
{% load form_helpers %}
|
{% load form_helpers %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
{% block title %}{{ plugin.name }}{% endblock %}
|
{% block title %}{{ plugin.title_short }}{% endblock %}
|
||||||
|
|
||||||
{% block object_identifier %}
|
{% block object_identifier %}
|
||||||
{% endblock object_identifier %}
|
{% endblock object_identifier %}
|
||||||
@ -15,16 +15,11 @@
|
|||||||
{% block subtitle %}
|
{% block subtitle %}
|
||||||
<div class="text-secondary fs-5">
|
<div class="text-secondary fs-5">
|
||||||
{{ plugin.tag_line }}
|
{{ plugin.tag_line }}
|
||||||
<a href="{{ plugin.homepage.url }}" target="_blank">Learn more <i class="mdi mdi-launch"></i></a><br />
|
<a href="{{ plugin.homepage.url }}" target="_blank">Learn more <i class="mdi mdi-launch"></i></a>
|
||||||
<strong>License:</strong> {{ plugin.license_type }}
|
|
||||||
</div>
|
</div>
|
||||||
{% endblock subtitle %}
|
{% endblock subtitle %}
|
||||||
|
|
||||||
{% block controls %}
|
{% block controls %}
|
||||||
<div class="text-secondary">
|
|
||||||
From
|
|
||||||
</div>
|
|
||||||
{{ plugin.author }}
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block tabs %}
|
{% block tabs %}
|
||||||
@ -40,7 +35,7 @@ From
|
|||||||
{% trans "Version history" %}
|
{% trans "Version history" %}
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
{% if plugin.is_community %}
|
{% if show_install %}
|
||||||
<li class="nav-item" role="presentation">
|
<li class="nav-item" role="presentation">
|
||||||
<button class="nav-link" id="install-tab" data-bs-toggle="tab" data-bs-target="#install" type="button" role="tab" aria-controls="object-list" aria-selected="false">
|
<button class="nav-link" id="install-tab" data-bs-toggle="tab" data-bs-target="#install" type="button" role="tab" aria-controls="object-list" aria-selected="false">
|
||||||
{% trans "Install" %}
|
{% trans "Install" %}
|
||||||
@ -55,7 +50,29 @@ From
|
|||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
<div class="tab-pane show active" id="overview" role="tabpanel" aria-labelledby="overview-tab">
|
<div class="tab-pane show active" id="overview" role="tabpanel" aria-labelledby="overview-tab">
|
||||||
{{ plugin.description_short|markdown }}
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col col-md-12">
|
||||||
|
<div class="card">
|
||||||
|
<table class="table table-hover attr-table">
|
||||||
|
<tr>
|
||||||
|
<th scope="row">{% trans "Author" %}</th>
|
||||||
|
<td>{{ plugin.author.name }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">{% trans "License" %}</th>
|
||||||
|
<td>{{ plugin.license_type }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">{% trans "Description" %}</th>
|
||||||
|
<td>{{ plugin.description_short|markdown }}</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
{% if not plugin.is_local %}
|
{% if not plugin.is_local %}
|
||||||
<div class="tab-pane" id="version-history" role="tabpanel" aria-labelledby="version-history-tab">
|
<div class="tab-pane" id="version-history" role="tabpanel" aria-labelledby="version-history-tab">
|
||||||
@ -66,7 +83,7 @@ From
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% if plugin.is_community %}
|
{% if show_install %}
|
||||||
<div class="tab-pane" id="install" role="tabpanel" aria-labelledby="install-tab">
|
<div class="tab-pane" id="install" role="tabpanel" aria-labelledby="install-tab">
|
||||||
<p>You can install this plugin from the command line with PyPi.</p>
|
<p>You can install this plugin from the command line with PyPi.</p>
|
||||||
<p>The following commands may be helpful; always refer to <a href="{{ plugin.homepage_url }}" target="_blank">the plugin's own documentation <i class="mdi mdi-launch"></i></a> and the <a href="https://netboxlabs.com/docs/netbox/en/stable/plugins/installation/" target="_blank">Installing a Plugin unit <i class="mdi mdi-launch"></i></a> of the NetBox documentation.</p>
|
<p>The following commands may be helpful; always refer to <a href="{{ plugin.homepage_url }}" target="_blank">the plugin's own documentation <i class="mdi mdi-launch"></i></a> and the <a href="https://netboxlabs.com/docs/netbox/en/stable/plugins/installation/" target="_blank">Installing a Plugin unit <i class="mdi mdi-launch"></i></a> of the NetBox documentation.</p>
|
||||||
|
Loading…
Reference in New Issue
Block a user