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
|
||||
|
||||
|
||||
@dataclass
|
||||
class PluginAuthor:
|
||||
name: str = ''
|
||||
org_id: str = ''
|
||||
url: str = ''
|
||||
|
||||
|
||||
@dataclass
|
||||
class PluginVersion:
|
||||
date: datetime.datetime = None
|
||||
@ -25,22 +32,25 @@ class PluginVersion:
|
||||
|
||||
@dataclass
|
||||
class Plugin:
|
||||
slug: str = ''
|
||||
config_name: str = ''
|
||||
name: str = ''
|
||||
id: str = ''
|
||||
status: str = ''
|
||||
title_short: str = ''
|
||||
title_long: str = ''
|
||||
tag_line: str = ''
|
||||
description_short: str = ''
|
||||
author: str = ''
|
||||
homepage_url: str = ''
|
||||
slug: str = ''
|
||||
author: PluginAuthor = field(default_factory=PluginAuthor)
|
||||
created_at: datetime.datetime = None
|
||||
updated_at: datetime.datetime = None
|
||||
license_type: str = ''
|
||||
created: datetime.datetime = None
|
||||
updated: datetime.datetime = None
|
||||
is_local: bool = False
|
||||
is_installed: bool = False
|
||||
homepage_url: str = ''
|
||||
package_name_pypi: str = ''
|
||||
config_name: str = ''
|
||||
is_certified: bool = False
|
||||
is_community: bool = False
|
||||
versions: list[PluginVersion] = field(default_factory=list)
|
||||
release_latest: PluginVersion = field(default_factory=PluginVersion)
|
||||
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():
|
||||
@ -52,15 +62,13 @@ def get_local_plugins():
|
||||
plugin_module = "{}.{}".format(plugin_config.__module__, plugin_config.__name__) # type: ignore
|
||||
plugins[plugin_config.name] = Plugin(
|
||||
slug=plugin_config.name,
|
||||
name=plugin_config.verbose_name,
|
||||
title_short=plugin_config.verbose_name,
|
||||
tag_line=plugin_config.description,
|
||||
description_short=plugin_config.description,
|
||||
author=plugin_config.author or _('Unknown Author'),
|
||||
is_local=True,
|
||||
is_installed=True,
|
||||
is_certified=False,
|
||||
is_community=False,
|
||||
)
|
||||
plugins[plugin_config.name].author.name = plugin_config.author or _('Unknown Author')
|
||||
|
||||
return plugins
|
||||
|
||||
@ -100,24 +108,40 @@ def get_catalog_plugins():
|
||||
)
|
||||
)
|
||||
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(
|
||||
slug=data['slug'],
|
||||
config_name=data['config_name'],
|
||||
name=data['title_short'],
|
||||
id=data['id'],
|
||||
status=data['status'],
|
||||
title_short=data['title_short'],
|
||||
title_long=data['title_long'],
|
||||
tag_line=data['tag_line'],
|
||||
description_short=data['description_short'],
|
||||
author=data['author']['name'] or _('Unknown Author'),
|
||||
homepage_url=data['homepage_url'],
|
||||
slug=data['slug'],
|
||||
author=author,
|
||||
created_at=datetime_from_timestamp(data['created_at']),
|
||||
updated_at=datetime_from_timestamp(data['updated_at']),
|
||||
license_type=data['license_type'],
|
||||
created=datetime_from_timestamp(data['created_at']),
|
||||
updated=datetime_from_timestamp(data['updated_at']),
|
||||
is_local=False,
|
||||
is_installed=False,
|
||||
is_certified=data['release_latest']['is_certified'],
|
||||
is_community=not data['release_latest']['is_certified'],
|
||||
versions=versions,
|
||||
homepage_url=data['homepage_url'],
|
||||
package_name_pypi=data['package_name_pypi'],
|
||||
config_name=data['config_name'],
|
||||
is_certified=data['is_certified'],
|
||||
release_latest=latest,
|
||||
release_recent_history=versions,
|
||||
)
|
||||
|
||||
return plugins
|
||||
@ -126,6 +150,7 @@ def get_catalog_plugins():
|
||||
def get_plugins():
|
||||
local_plugins = get_local_plugins()
|
||||
catalog_plugins = cache.get('plugins-catalog-feed')
|
||||
catalog_plugins = None
|
||||
if not catalog_plugins:
|
||||
catalog_plugins = get_catalog_plugins()
|
||||
cache.set('plugins-catalog-feed', catalog_plugins, 3600)
|
||||
|
@ -42,11 +42,12 @@ class PluginVersionTable(BaseTable):
|
||||
|
||||
|
||||
class CatalogPluginTable(BaseTable):
|
||||
name = tables.Column(
|
||||
title_short = tables.Column(
|
||||
linkify=('core:plugin', [tables.A('slug')]),
|
||||
verbose_name=_('Name')
|
||||
)
|
||||
author = tables.Column(
|
||||
accessor=tables.A('author.name'),
|
||||
verbose_name=_('Author')
|
||||
)
|
||||
is_local = tables.BooleanColumn(
|
||||
@ -58,18 +59,18 @@ class CatalogPluginTable(BaseTable):
|
||||
is_certified = tables.BooleanColumn(
|
||||
verbose_name=_('Certified')
|
||||
)
|
||||
created = tables.Column(
|
||||
created_at = tables.Column(
|
||||
verbose_name=_('Published')
|
||||
)
|
||||
updated = tables.Column(
|
||||
updated_at = tables.Column(
|
||||
verbose_name=_('Updated')
|
||||
)
|
||||
|
||||
class Meta(BaseTable.Meta):
|
||||
empty_text = _('No plugin data found')
|
||||
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 = (
|
||||
'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
|
||||
# Remaining catalog plugins
|
||||
# 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_installed, reverse=True)
|
||||
|
||||
@ -692,10 +692,11 @@ class PluginView(UserPassesTestMixin, View):
|
||||
plugins = get_plugins()
|
||||
plugin = plugins[name]
|
||||
|
||||
table = PluginVersionTable(plugin.versions, user=request.user)
|
||||
table = PluginVersionTable(plugin.release_recent_history, user=request.user)
|
||||
table.configure(request)
|
||||
|
||||
return render(request, 'core/plugin.html', {
|
||||
'plugin': plugin,
|
||||
'table': table,
|
||||
'show_install': settings.RELEASE.edition == 'Community'
|
||||
})
|
||||
|
@ -3,7 +3,7 @@
|
||||
{% load form_helpers %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block title %}{{ plugin.name }}{% endblock %}
|
||||
{% block title %}{{ plugin.title_short }}{% endblock %}
|
||||
|
||||
{% block object_identifier %}
|
||||
{% endblock object_identifier %}
|
||||
@ -15,16 +15,11 @@
|
||||
{% block subtitle %}
|
||||
<div class="text-secondary fs-5">
|
||||
{{ plugin.tag_line }}
|
||||
<a href="{{ plugin.homepage.url }}" target="_blank">Learn more <i class="mdi mdi-launch"></i></a><br />
|
||||
<strong>License:</strong> {{ plugin.license_type }}
|
||||
<a href="{{ plugin.homepage.url }}" target="_blank">Learn more <i class="mdi mdi-launch"></i></a>
|
||||
</div>
|
||||
{% endblock subtitle %}
|
||||
|
||||
{% block controls %}
|
||||
<div class="text-secondary">
|
||||
From
|
||||
</div>
|
||||
{{ plugin.author }}
|
||||
{% endblock %}
|
||||
|
||||
{% block tabs %}
|
||||
@ -40,7 +35,7 @@ From
|
||||
{% trans "Version history" %}
|
||||
</button>
|
||||
</li>
|
||||
{% if plugin.is_community %}
|
||||
{% if show_install %}
|
||||
<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">
|
||||
{% trans "Install" %}
|
||||
@ -55,7 +50,29 @@ From
|
||||
{% block content %}
|
||||
|
||||
<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>
|
||||
{% if not plugin.is_local %}
|
||||
<div class="tab-pane" id="version-history" role="tabpanel" aria-labelledby="version-history-tab">
|
||||
@ -66,7 +83,7 @@ From
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% if plugin.is_community %}
|
||||
{% if show_install %}
|
||||
<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>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