Skip to content

Commit

Permalink
add custom fields ability;
Browse files Browse the repository at this point in the history
  • Loading branch information
k01ek committed Mar 22, 2021
1 parent f00c925 commit 71229bb
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PYTHON_VER?=3.9
NETBOX_VER?=v2.10.3
PYTHON_VER?=3.7
NETBOX_VER?=v2.10.6

NAME=netbox-qrcode

Expand Down Expand Up @@ -27,7 +27,7 @@ stop:

destroy:
docker-compose -f ${COMPOSE_FILE} -p ${BUILD_NAME} down
docker volume rm -f ${BUILD_NAME}_pgdata_netbox_tickets
docker volume rm -f ${BUILD_NAME}_pgdata_netbox_qrcode

nbshell:
docker-compose -f ${COMPOSE_FILE} -p ${BUILD_NAME} run netbox python manage.py nbshell
Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Restart NetBox and add `netbox-qrcode` to your local_requirements.txt
The following options are available:

* `with_text`: Boolean (default True). Text label will be added to QR code image if enabled.
* `text_fields`: List of String (default ['name']). Text fields of object that will be added as text label to QR image.
* `text_fields`: List of String (default ['name']). Text fields of an object that will be added as text label to QR image. It's possible to use custom field values.
* `font`: String (default TahomaBold) Font name for text label ( Some font include in package, see fonts dir).
* `custom_text`: String or None (default None) additional text label to QR code image (will be added after text_fields).
* `qr_version`: Integer (default 1) parameter is an integer from 1 to 40 that controls the size of
Expand Down Expand Up @@ -67,7 +67,13 @@ PLUGINS_CONFIG = {
# per object options
'cable': None, # disable QR code for Cable object
'rack': {
'text_fields': ['site', 'name', 'facility_id', 'tenant']
'text_fields': [
'site',
'name',
'facility_id',
'tenant',
'cf.cf_name'
]
},
'device': {
'qr_box_size': 6,
Expand Down
15 changes: 14 additions & 1 deletion netbox_qrcode/template_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,21 @@ def x_page(self):
if config.get('with_text'):
text = []
for text_field in config.get('text_fields', []):
cfn = None
if '.' in text_field:
try:
text_field, cfn = text_field.split('.')
except ValueError:
cfn = None
if getattr(obj, text_field, None):
text.append('{}'.format(getattr(obj, text_field)))
if cfn:
try:
if getattr(obj, text_field).get(cfn):
text.append('{}'.format(getattr(obj, text_field).get(cfn)))
except AttributeError:
pass
else:
text.append('{}'.format(getattr(obj, text_field)))
custom_text = config.get('custom_text')
if custom_text:
text.append(custom_text)
Expand Down
2 changes: 1 addition & 1 deletion netbox_qrcode/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.0.4"
__version__ = "0.0.5"

0 comments on commit 71229bb

Please sign in to comment.