From e153d4a1c075ed652d405b5547c5ba042d8120fa Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 6 Oct 2024 13:04:42 +0300 Subject: [PATCH] feat: bigger product size --- barcodes/attributes/size_attribute_getter.py | 4 +++- barcodes/generator/default_generator.py | 6 +++++- barcodes/pdf/generator.py | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/barcodes/attributes/size_attribute_getter.py b/barcodes/attributes/size_attribute_getter.py index 430cdb4..1d206fb 100644 --- a/barcodes/attributes/size_attribute_getter.py +++ b/barcodes/attributes/size_attribute_getter.py @@ -4,4 +4,6 @@ from models import Product class SizeAttributeGetter(BaseAttributeGetter): def get_value(self, product: Product): - return product.size + if not product.size: + return None + return f'{product.size}' diff --git a/barcodes/generator/default_generator.py b/barcodes/generator/default_generator.py index 8e3a133..70b9288 100644 --- a/barcodes/generator/default_generator.py +++ b/barcodes/generator/default_generator.py @@ -21,11 +21,15 @@ class DefaultBarcodeGenerator(BaseBarcodeGenerator): if not attribute_getter: continue value = attribute_getter.get_value(barcode_data["product"]) + if not value or not value.strip(): continue attributes[attribute.name] = value for additional_attribute in barcode_data["template"].additional_attributes: - attributes[additional_attribute.name] = additional_attribute.value + value = additional_attribute.value + if not value: + continue + attributes[additional_attribute.name] = value barcode_text = '
'.join([f'{key}: {value}' for key, value in attributes.items()]) pdf_barcodes_gen_data.append( diff --git a/barcodes/pdf/generator.py b/barcodes/pdf/generator.py index b378305..f5f6b90 100644 --- a/barcodes/pdf/generator.py +++ b/barcodes/pdf/generator.py @@ -34,7 +34,7 @@ class PDFGenerator: leading=7, spaceAfter=2, leftIndent=2, - rightIndent=2 + rightIndent=2, ) def generate_small_text(self, barcode_value, text, num_duplicates=1):