diff --git a/Makefile b/Makefile index 0779c12..75086c1 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 diff --git a/README.md b/README.md index 90030c3..5d4e1e2 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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, diff --git a/netbox_qrcode/template_content.py b/netbox_qrcode/template_content.py index 463de15..3c634f8 100644 --- a/netbox_qrcode/template_content.py +++ b/netbox_qrcode/template_content.py @@ -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) diff --git a/netbox_qrcode/version.py b/netbox_qrcode/version.py index 81f0fde..b1a19e3 100644 --- a/netbox_qrcode/version.py +++ b/netbox_qrcode/version.py @@ -1 +1 @@ -__version__ = "0.0.4" +__version__ = "0.0.5"