feat: temp barcode templates
This commit is contained in:
0
barcodes/__init__.py
Normal file
0
barcodes/__init__.py
Normal file
21
barcodes/attributes/__init__.py
Normal file
21
barcodes/attributes/__init__.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from abc import abstractmethod, ABC
|
||||
|
||||
from .article_attribute_writer import ArticleAttributeWriter
|
||||
from .name_attribute_writer import NameAttributeWriter
|
||||
from ..barcode import Barcode
|
||||
|
||||
|
||||
class BaseAttributeWriter(ABC):
|
||||
@abstractmethod
|
||||
def write(self, barcode: Barcode):
|
||||
pass
|
||||
|
||||
|
||||
class AttributeWriterFactory:
|
||||
@staticmethod
|
||||
def get_writer(key: str):
|
||||
match key:
|
||||
case 'name':
|
||||
return NameAttributeWriter()
|
||||
case 'article':
|
||||
return ArticleAttributeWriter()
|
||||
7
barcodes/attributes/article_attribute_writer.py
Normal file
7
barcodes/attributes/article_attribute_writer.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from barcodes.attributes import BaseAttributeWriter
|
||||
from barcodes.barcode import Barcode
|
||||
|
||||
|
||||
class ArticleAttributeWriter(BaseAttributeWriter):
|
||||
def write(self, barcode: Barcode):
|
||||
pass
|
||||
7
barcodes/attributes/name_attribute_writer.py
Normal file
7
barcodes/attributes/name_attribute_writer.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from barcodes.attributes import BaseAttributeWriter
|
||||
from barcodes.barcode import Barcode
|
||||
|
||||
|
||||
class NameAttributeWriter(BaseAttributeWriter):
|
||||
def write(self, barcode: Barcode):
|
||||
pass
|
||||
15
barcodes/barcode.py
Normal file
15
barcodes/barcode.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from .attributes import AttributeWriterFactory
|
||||
from models import ProductBarcode, BarcodeTemplate, BarcodeTemplateAttribute
|
||||
|
||||
|
||||
class Barcode:
|
||||
def __init__(self, session, barcode: ProductBarcode):
|
||||
self.session = session
|
||||
self.barcode = barcode
|
||||
|
||||
def render(self, template: BarcodeTemplate):
|
||||
for attribute in template.attributes:
|
||||
attribute: BarcodeTemplateAttribute
|
||||
writer = AttributeWriterFactory.get_writer(attribute.key)
|
||||
writer.write(self)
|
||||
|
||||
6
barcodes/generator.py
Normal file
6
barcodes/generator.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from models import ProductBarcode
|
||||
|
||||
|
||||
class BarcodeGenerator:
|
||||
def __init__(self, barcode: ProductBarcode):
|
||||
self.barcode = barcode
|
||||
Reference in New Issue
Block a user