Skip to content

Commit 0d31fd3

Browse files
committed
Generate each label individually to always get fresh template rendering (new UUIDs, random and counter values as well as current datetime)
Signed-off-by: DL6ER <[email protected]>
1 parent 10cd412 commit 0d31fd3

3 files changed

Lines changed: 19 additions & 18 deletions

File tree

app/labeldesigner/label.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ def __init__(
9292
border_distance=(0, 0),
9393
border_color=(0, 0, 0),
9494
timestamp=0,
95+
counter=1,
9596
red_support=False):
9697
self._width = width
9798
self._height = height
@@ -111,7 +112,7 @@ def __init__(
111112
self._border_roundness = border_roundness
112113
self._border_distance = border_distance
113114
self._border_color = border_color
114-
self._counter = 1
115+
self._counter = counter
115116
self._timestamp = timestamp
116117
self._red_support = red_support
117118

@@ -213,9 +214,6 @@ def random_replacer(match):
213214
return ''.join(random.choices(string.ascii_letters + string.digits + string.punctuation, k=length))
214215
line['text'] = re.sub(r"\{\{random(?:\:(\d+))?\}\}", random_replacer, line['text'])
215216

216-
# Increment counter
217-
self._counter += 1
218-
219217
def generate(self, rotate = False):
220218
# Process possible templates in the text
221219
self.process_templates()

app/labeldesigner/printer.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,12 @@ def label_size(self):
4545
def label_size(self, value):
4646
self._label_size = value
4747

48-
def add_label_to_queue(self, label, count, cut_once=False, high_res: bool = False):
49-
for cnt in range(0, count):
50-
cut = (cut_once == False) or (cut_once and cnt == count-1)
51-
52-
self._printQueue.append(
53-
{'label': label,
54-
'cut': cut,
55-
'high_res': high_res
56-
})
48+
def add_label_to_queue(self, label, cut: bool = True, high_res: bool = False):
49+
self._printQueue.append(
50+
{'label': label,
51+
'cut': cut,
52+
'high_res': high_res
53+
})
5754

5855
def process_queue(self) -> bool:
5956
qlr = BrotherQLRaster(self._model)

app/labeldesigner/routes.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ def print_label():
115115
if isinstance(level, int):
116116
current_app.logger.setLevel(level)
117117
printer = create_printer_from_request(request)
118-
label = create_label_from_request(request)
119118
print_count = int(request.values.get('print_count', 1))
120119
if print_count < 1:
121120
raise ValueError("print_count must be greater than 0")
@@ -127,9 +126,15 @@ def print_label():
127126
# Generate error 400 response
128127
return make_response(jsonify(return_dict), 400)
129128

130-
printer.add_label_to_queue(label, print_count, cut_once, high_res)
131-
132129
try:
130+
for i in range(print_count):
131+
label = create_label_from_request(request, i + 1)
132+
# Cut only if we
133+
# - always cut, or
134+
# - we cut only once and this is the last label to be generated
135+
cut = (cut_once == False) or (cut_once and i == print_count-1)
136+
printer.add_label_to_queue(label, cut, high_res)
137+
133138
status = printer.process_queue()
134139
except Exception as e:
135140
return_dict['message'] = str(e)
@@ -159,7 +164,7 @@ def parse_text_form(input):
159164
return []
160165
return json.loads(input)
161166

162-
def create_label_from_request(request):
167+
def create_label_from_request(request, counter: int = 1):
163168
d=request.values
164169
label_size = d.get('label_size', "62")
165170
kind = [label.form_factor for label in ALL_LABELS if label.identifier == label_size][0]
@@ -312,5 +317,6 @@ def get_uploaded_image(image):
312317
border_roundness=context['border_roundness'],
313318
border_distance=(context['border_distanceX'], context['border_distanceY']),
314319
border_color=border_color,
315-
timestamp=context['timestamp']
320+
timestamp=context['timestamp'],
321+
counter=counter
316322
)

0 commit comments

Comments
 (0)