Skip to content

Commit

Permalink
Merge pull request #24 from jasonyates/develop
Browse files Browse the repository at this point in the history
Adding support for external URL's
  • Loading branch information
jasonyates authored Jan 24, 2023
2 parents ddcb50e + 91d665a commit b3f2f24
Show file tree
Hide file tree
Showing 26 changed files with 782 additions and 87 deletions.
6 changes: 6 additions & 0 deletions BUILD.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

pip install build twine

python -m build
twine upload -r testpypi dist/*
twine upload dist/*
34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Changelog

## 0.5.0 (2023-01-24)

* Fix API Filtersets
* Add support for storing links to external URL's
* Documentation updates

## 0.4.6 (2023-01-23)

* Added nested serializer.

## 0.4.5 (2023-01-03)

* Updated navigation for NetBox 3.4
* Added support for plugin search indexing

## 0.4.4 (2023-01-02)

* Added Device Type support
* Fix files not being deleted from disk

## 0.3.1 (2022-04-06)

* Adds help text to add/edit forms
* Updating table view to link to the document object view
* Adds button to document widget to link to the document object view
* Adds a link to the associated parent objet from the document object view
* Adds a link to uploaded document from the document object view
* Updates document_type to render as a badge on document object view and document widget

## 0.3.0 (2022-04-04)

* Initial Release
99 changes: 99 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Contributing

Contributions are welcome, and they are greatly appreciated! Every little bit
helps, and credit will always be given.

You can contribute in many ways:

## Types of Contributions

### Report Bugs

Report bugs at https://github.com/jasonyates/netbox-documents/issues.

If you are reporting a bug, please include:

* Your operating system name and version.
* Any details about your local setup that might be helpful in troubleshooting.
* Detailed steps to reproduce the bug.

### Fix Bugs

Look through the GitHub issues for bugs. Anything tagged with "bug" and "help
wanted" is open to whoever wants to implement it.

### Implement Features

Look through the GitHub issues for features. Anything tagged with "enhancement"
and "help wanted" is open to whoever wants to implement it.

### Write Documentation

Netbox Documents Plugin could always use more documentation, whether as part of the
official Netbox Documents Plugin docs, in docstrings, or even on the web in blog posts,
articles, and such.

### Submit Feedback

The best way to send feedback is to file an issue at https://github.com/jasonyates/netbox-documents/issues.

If you are proposing a feature:

* Explain in detail how it would work.
* Keep the scope as narrow as possible, to make it easier to implement.
* Remember that this is a volunteer-driven project, and that contributions
are welcome :)

## Get Started!

Ready to contribute? Here's how to set up `netbox-documents` for local development.

1. Fork the `netbox-documents` repo on GitHub.
2. Clone your fork locally

```
$ git clone [email protected]:your_name_here/netbox-documents.git
```
3. Install dependencies and start your virtualenv:
```
$ poetry install -E test -E doc -E dev
```
4. Create a branch for local development:
```
$ git checkout -b name-of-your-bugfix-or-feature
```
Now you can make your changes locally.
5. When you're done making changes, check that your changes pass the
tests, including testing other Python versions, with tox:
```
$ poetry run tox
```
6. Commit your changes and push your branch to GitHub:
```
$ git add .
$ git commit -m "Your detailed description of your changes."
$ git push origin name-of-your-bugfix-or-feature
```
7. Submit a pull request through the GitHub website.
## Pull Request Guidelines
Before you submit a pull request, check that it meets these guidelines:
1. The pull request should include tests.
2. If the pull request adds functionality, the docs should be updated. Put
your new functionality into a function with a docstring, and add the
feature to the list in README.md.
3. The pull request should work for Python 3.6, 3.7, 3.8 and 3.9. Check
https://github.com/jasonyates/netbox-documents/actions
and make sure that the tests pass for all supported Python versions.
34 changes: 26 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,31 @@

A plugin designed to faciliate the storage of site, circuit, device type and device specific documents within [NetBox](https://github.com/netbox-community/netbox)

**Note: Netbox v3.2+ is required. This plugin will not work on an earlier release of Netbox.**
## Features

# Installation
* Store documents against the following NetBox models:
- Circuits
- Devices
- Device Types
- Sites

A working installation of Netbox 3.2+ is required - [see official documentation](https://netbox.readthedocs.io/en/stable/plugins/).
* Upload documents to your NetBox media/ folder or other Django supported storage method e.g. S3
* Supports a wide array of common file types (bmp, gif, jpeg, jpg, png, pdf, txt, doc, docx, xls, xlsx, xlsm)
* Store links to external URL's to save duplication of remote documents

### Package Installation from PyPi

## Compatibility

| NetBox Version | Plugin Version |
|----------------|----------------|
| 3.2+ | 0.5.0 |


## Installation

A working installation of Netbox 3.2+ is required. 3.4+ is recommended.

#### Package Installation from PyPi

Activate your virtual env and install via pip:

Expand All @@ -23,7 +41,7 @@ To ensure the Netbox Documents plugin is automatically re-installed during futur
# echo netbox-documents >> local_requirements.txt
```

### Enable the Plugin
#### Enable the Plugin

In the Netbox `configuration.py` configuration file add or update the PLUGINS parameter, adding `netbox_documents`:

Expand Down Expand Up @@ -101,23 +119,23 @@ FIELD_CHOICES = {
}
```

### Apply Database Migrations
#### Apply Database Migrations

Apply database migrations with Netbox `manage.py`:

```
(venv) $ python manage.py migrate
```

### Restart Netbox
#### Restart Netbox

Restart the Netbox service to apply changes:

```
sudo systemctl restart netbox
```

### Re-index Netbox search index (Upgrade to 3.4 only)
#### Re-index Netbox search index (Upgrade to 3.4 only)

If you are upgrading from Netbox 3.2 or above to Netbox 3.4, any previously inserted documents may not show up in the new search feature. To resolve this, re-index the plugin:

Expand Down
2 changes: 1 addition & 1 deletion netbox_documents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class NetboxDocuments(PluginConfig):
name = 'netbox_documents'
verbose_name = 'Document Storage'
description = 'Manage site, circuit and device diagrams and documents in Netbox'
version = '0.4.6'
version = '0.5.0'
author = 'Jason Yates'
author_email = '[email protected]'
min_version = '3.2.0'
Expand Down
14 changes: 7 additions & 7 deletions netbox_documents/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class SiteDocumentSerializer(NetBoxModelSerializer):
class Meta:
model = SiteDocument
fields = (
'id', 'url', 'display', 'name', 'document', 'document_type', 'filename', 'site', 'comments', 'tags', 'custom_fields', 'created',
'id', 'url', 'display', 'name', 'document', 'external_url', 'document_type', 'filename', 'site', 'comments', 'tags', 'custom_fields', 'created',
'last_updated',
)

Expand All @@ -30,7 +30,7 @@ class NestedSiteDocumentSerializer(WritableNestedSerializer):
class Meta:
model = SiteDocument
fields = (
'id', 'url', 'display', 'name', 'document', 'document_type', 'filename',
'id', 'url', 'display', 'name', 'document', 'external_url', 'document_type', 'filename',
)


Expand All @@ -46,7 +46,7 @@ class DeviceDocumentSerializer(NetBoxModelSerializer):
class Meta:
model = DeviceDocument
fields = (
'id', 'url', 'display', 'name', 'document', 'document_type', 'filename', 'device', 'comments', 'tags', 'custom_fields', 'created',
'id', 'url', 'display', 'name', 'document', 'external_url', 'document_type', 'filename', 'device', 'comments', 'tags', 'custom_fields', 'created',
'last_updated',
)

Expand All @@ -59,7 +59,7 @@ class NestedDeviceDocumentSerializer(WritableNestedSerializer):
class Meta:
model = DeviceDocument
fields = (
'id', 'url', 'display', 'name', 'document', 'document_type', 'filename',
'id', 'url', 'display', 'name', 'document', 'external_url', 'document_type', 'filename',
)


Expand All @@ -74,7 +74,7 @@ class DeviceTypeDocumentSerializer(NetBoxModelSerializer):
class Meta:
model = DeviceTypeDocument
fields = (
'id', 'url', 'display', 'name', 'document', 'document_type', 'filename', 'device_type', 'comments', 'tags', 'custom_fields', 'created',
'id', 'url', 'display', 'name', 'document', 'external_url', 'document_type', 'filename', 'device_type', 'comments', 'tags', 'custom_fields', 'created',
'last_updated',
)

Expand All @@ -90,7 +90,7 @@ class CircuitDocumentSerializer(NetBoxModelSerializer):
class Meta:
model = CircuitDocument
fields = (
'id', 'url', 'display', 'name', 'document', 'document_type', 'filename', 'circuit', 'comments', 'tags', 'custom_fields', 'created',
'id', 'url', 'display', 'name', 'document', 'external_url', 'document_type', 'filename', 'circuit', 'comments', 'tags', 'custom_fields', 'created',
'last_updated',
)

Expand All @@ -103,5 +103,5 @@ class NestedCircuitDocumentSerializer(WritableNestedSerializer):
class Meta:
model = CircuitDocument
fields = (
'id', 'url', 'display', 'name', 'document', 'document_type', 'filename',
'id', 'url', 'display', 'name', 'document', 'external_url', 'document_type', 'filename',
)
9 changes: 6 additions & 3 deletions netbox_documents/api/views.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
from netbox.api.viewsets import NetBoxModelViewSet

from .. import models
from .. import models, filtersets
from .serializers import SiteDocumentSerializer, DeviceDocumentSerializer, DeviceTypeDocumentSerializer, CircuitDocumentSerializer

class SiteDocumentViewSet(NetBoxModelViewSet):
queryset = models.SiteDocument.objects.prefetch_related('tags')
serializer_class = SiteDocumentSerializer
filterset_class = filtersets.SiteDocumentFilterSet

class DeviceDocumentViewSet(NetBoxModelViewSet):
queryset = models.DeviceDocument.objects.prefetch_related('tags')
serializer_class = DeviceDocumentSerializer

filterset_class = filtersets.DeviceDocumentFilterSet

class DeviceTypeDocumentViewSet(NetBoxModelViewSet):
queryset = models.DeviceTypeDocument.objects.prefetch_related('tags')
serializer_class = DeviceTypeDocumentSerializer
filterset_class = filtersets.DeviceTypeDocumentFilterSet

class CircuitDocumentViewSet(NetBoxModelViewSet):
queryset = models.CircuitDocument.objects.prefetch_related('tags')
serializer_class = CircuitDocumentSerializer
serializer_class = CircuitDocumentSerializer
filterset_class = filtersets.CircuitDocumentFilterSet
8 changes: 4 additions & 4 deletions netbox_documents/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class SiteDocumentForm(NetBoxModelForm):

class Meta:
model = SiteDocument
fields = ('name', 'document', 'document_type', 'site', 'comments', 'tags')
fields = ('name', 'document', 'external_url', 'document_type', 'site', 'comments', 'tags')

class SiteDocumentFilterForm(NetBoxModelFilterSetForm):
model = SiteDocument
Expand Down Expand Up @@ -48,7 +48,7 @@ class DeviceDocumentForm(NetBoxModelForm):

class Meta:
model = DeviceDocument
fields = ('name', 'document', 'document_type', 'device', 'comments', 'tags')
fields = ('name', 'document', 'external_url', 'document_type', 'device', 'comments', 'tags')

class DeviceDocumentFilterForm(NetBoxModelFilterSetForm):
model = DeviceDocument
Expand Down Expand Up @@ -80,7 +80,7 @@ class DeviceTypeDocumentForm(NetBoxModelForm):

class Meta:
model = DeviceTypeDocument
fields = ('name', 'document', 'document_type', 'device_type', 'comments', 'tags')
fields = ('name', 'document', 'external_url', 'document_type', 'device_type', 'comments', 'tags')

class DeviceTypeDocumentFilterForm(NetBoxModelFilterSetForm):
model = DeviceTypeDocument
Expand Down Expand Up @@ -112,7 +112,7 @@ class CircuitDocumentForm(NetBoxModelForm):

class Meta:
model = CircuitDocument
fields = ('name', 'document', 'document_type', 'circuit', 'comments', 'tags')
fields = ('name', 'document', 'external_url', 'document_type', 'circuit', 'comments', 'tags')

class CircuitDocumentFilterForm(NetBoxModelFilterSetForm):
model = CircuitDocument
Expand Down
Loading

0 comments on commit b3f2f24

Please sign in to comment.