* refactors function based report views into class based for EIV, OEK, EMA, KOM * introduces BaseReportView for proper inheritance of shared logic * refactors generating of qr codes into proper class
48 lines
1.0 KiB
Python
48 lines
1.0 KiB
Python
"""
|
|
Author: Michel Peltriaux
|
|
Created on: 17.10.25
|
|
|
|
"""
|
|
from io import BytesIO
|
|
|
|
import qrcode
|
|
import qrcode.image.svg as svg
|
|
|
|
|
|
class QrCode:
|
|
""" A wrapping class for creating a qr code with content
|
|
|
|
"""
|
|
_content = None
|
|
_img = None
|
|
|
|
def __init__(self, content: str, size: int):
|
|
self._content = content
|
|
self._img = self._generate_qr_code(content, size)
|
|
|
|
def _generate_qr_code(self, content: str, size: int = 20) -> str:
|
|
""" Generates a qr code from given content
|
|
|
|
Args:
|
|
content (str): The content for the qr code
|
|
size (int): The image size
|
|
|
|
Returns:
|
|
qrcode_svg (str): The qr code as svg
|
|
"""
|
|
img_factory = svg.SvgImage
|
|
qrcode_img = qrcode.make(
|
|
content,
|
|
image_factory=img_factory,
|
|
box_size=size
|
|
)
|
|
stream = BytesIO()
|
|
qrcode_img.save(stream)
|
|
return stream.getvalue().decode()
|
|
|
|
def get_img(self):
|
|
return self._img
|
|
|
|
def get_content(self):
|
|
return self._content
|