diff --git a/.gitignore b/.gitignore index 668d105..4e5efb2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,18 +1,16 @@ test.ipynb test.py -mangadexdlp/__pycache__/ +test.html +test.sh test/ downloads/ .vscode/ -.pytest_cache& +.pytest_cache .vscode/ __pycache__/ .pytest_cache/ -chaps.txt -mangas.txt .idea/ venv -test.sh .ruff_cache/ development/db-data/ development/redis-data/ diff --git a/README.md b/README.md index baf07c2..d8d1e54 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ NetBox plugin to generate QR codes for assets +> Based on/inspired by: [k01ek/netbox-qrcode](https://github.com/k01ek/netbox-qrcode) + CI/CD [![status-badge](https://img.shields.io/drone/build/olofvndrhr/netbox-qrgen?label=ci&server=https%3A%2F%2Fci.44net.ch)](https://ci.44net.ch/olofvndrhr/netbox-qrgen) @@ -30,7 +32,9 @@ test ## Features (not complete) -- test +- Generate QR Codes for your assets +- Download them either as PNG or SVG +- Directly print them via the Web interface ## Compatibility @@ -52,7 +56,7 @@ Review the [official Netbox plugin documentation](https://docs.netbox.dev/en/sta /opt/netbox/venv/bin/pip install --no-warn-script-location netbox-qrgen ``` -### In the netbox docker container +### In the Netbox docker container For adding to a NetBox Docker setup see [the general instructions for using netbox-docker with plugins](https://github.com/netbox-community/netbox-docker/wiki/Using-Netbox-Plugins). @@ -78,6 +82,7 @@ PLUGINS_CONFIG = { "qr_with_text": True, "qr_text_fields": ["name", "serial"], "qr_font": "Tahoma", + "qr_width": "200px", "qr_custom_text": None, "qr_text_location": "right", "qr_version": 2, @@ -112,7 +117,8 @@ PLUGINS_CONFIG = { | --------------------- | ----------- | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `qr_with_text` | `bool` | `True` | Generate a text with the specified infos besides the QR code. | | `qr_text_fields` | `list[str]` | `["name", "serial"]` | Fields to add as a text to the QR code. All object properties can be used. | -| `qr_font` | `str` | `'Tahoma'` | Font to use to generate the text. Included fonts: `ArialBlack`,`ArialMT`,`JetBrainsMono`,`JetBrainsMonoBold`,`Tahoma`,`TahomaBold`. | +| `qr_font` | `str` | `Tahoma` | Font to use to generate the text. Included fonts: `ArialBlack`,`ArialMT`,`JetBrainsMono`,`JetBrainsMonoBold`,`Tahoma`,`TahomaBold`. | +| `qr_width` | `str` | `200px` | Size for the SVG image to render. Can be any HTML valid size. | | `qr_custom_text` | `str` | `None` | Custom text to be added to every QR code. | | `qr_text_location` | `str` | `right` | Where the text fields are rendered relative to the QR code | | `qr_version` | `int` | `2` | An integer from 1 to 40 that controls the size of the QR Code (the smallest, version 1, is a 21x21 matrix). More details [here](https://www.qrcode.com/en/about/version.html) | @@ -129,7 +135,3 @@ If you encounter any bugs, also just open an issue with a description of the pro ## TODO's - test - -``` - -``` diff --git a/development/config/plugins.py b/development/config/plugins.py index 2040f88..ea32563 100644 --- a/development/config/plugins.py +++ b/development/config/plugins.py @@ -21,6 +21,7 @@ PLUGINS_CONFIG = { "qr_with_text": True, "qr_text_fields": ["name", "serial"], "qr_font": "TahomaBold", + "qr_width": "200px", "qr_custom_text": None, "qr_text_location": "bottom", "qr_version": 2, diff --git a/netbox_qrgen/__init__.py b/netbox_qrgen/__init__.py index 8ddbf07..965adb5 100644 --- a/netbox_qrgen/__init__.py +++ b/netbox_qrgen/__init__.py @@ -14,6 +14,7 @@ class NetBoxQRGenConfig(PluginConfig): "qr_with_text": True, "qr_text_fields": ["name", "serial"], "qr_font": "Tahoma", + "qr_width": "200px", "qr_custom_text": None, "qr_text_location": "right", "qr_version": 2, diff --git a/netbox_qrgen/template_content.py b/netbox_qrgen/template_content.py index 95e5d97..a2f0b8e 100644 --- a/netbox_qrgen/template_content.py +++ b/netbox_qrgen/template_content.py @@ -7,50 +7,50 @@ plugin_settings = settings.PLUGINS_CONFIG.get("netbox_qrgen", {}) class QRGen(PluginTemplateExtension): - def get_url(self) -> str: + def _get_url(self) -> str: obj = self.context["object"] request = self.context["request"] url: str = request.build_absolute_uri(obj.get_absolute_url()) return url - def get_qrcode(self, url: str) -> str: - img = generate_qrcode(url=url, **plugin_settings) - b64 = get_base64(img) + def _get_qrcode(self, url: str) -> tuple[str, str]: + img_png, img_svg = generate_qrcode(url=url, **plugin_settings) + b64_png = get_base64(img_png) + b64_svg = get_base64(img_svg) - return b64 + return b64_png, b64_svg def right_page(self): - qr_img = self.get_qrcode(self.get_url()) + b64_png, b64_svg = self._get_qrcode(self._get_url()) return self.render( "netbox_qrgen/qrgen.html", - extra_context={"image": qr_img}, + extra_context={ + "image_width": plugin_settings["qr_width"], + "image_png": b64_png, + "image_svg": b64_svg, + }, ) class QRGenDevice(QRGen): model = "dcim.device" - # kind = "device" class QRGenRack(QRGen): model = "dcim.rack" - # kind = "rack" class QRGenCable(QRGen): model = "dcim.cable" - # kind = "cable" class QRGenInventoryItem(QRGen): model = "dcim.inventoryitem" - # kind = "inventoryitem" class QRGenCircuit(QRGen): model = "circuits.circuit" - # kind = "circuit" template_extensions = [ diff --git a/netbox_qrgen/templates/netbox_qrgen/qrgen.html b/netbox_qrgen/templates/netbox_qrgen/qrgen.html index 9548e4f..79192c9 100644 --- a/netbox_qrgen/templates/netbox_qrgen/qrgen.html +++ b/netbox_qrgen/templates/netbox_qrgen/qrgen.html @@ -12,11 +12,21 @@
QR Code
- +