Fix: unticking every sheet field silently reset to the defaults
Same absent-checkbox bug as the tape page, caught alongside it. The hidden form marker lets an empty field list be honoured as a real choice instead of being treated as "nothing was submitted".
This commit is contained in:
1 parent
4a1bfc4acd
commit
5319870a7c
1 file changed
+19
-4
@@ -101,6 +101,11 @@ FIELD_OPTIONS = [
|
|||||||
|
|
||||||
DEFAULT_FIELDS = ['image', 'name', 'dimensions', 'part_number', 'accent']
|
DEFAULT_FIELDS = ['image', 'name', 'dimensions', 'part_number', 'accent']
|
||||||
|
|
||||||
|
# Hidden marker the options form always submits, so an unticked checkbox
|
||||||
|
# (which the browser omits entirely) can be told apart from a fresh arrival
|
||||||
|
# with no options at all. See tape_printer.FORM_MARKER.
|
||||||
|
FORM_MARKER = '_opts'
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class LabelOptions:
|
class LabelOptions:
|
||||||
@@ -126,7 +131,14 @@ def get_preset(key: Optional[str]) -> SheetPreset:
|
|||||||
|
|
||||||
|
|
||||||
def options_from_form(form) -> LabelOptions:
|
def options_from_form(form) -> LabelOptions:
|
||||||
"""Build LabelOptions from request.form or request.args."""
|
"""
|
||||||
|
Build LabelOptions from request.form or request.args.
|
||||||
|
|
||||||
|
FORM_MARKER tells a real submission from a fresh arrival, so unticking
|
||||||
|
every field is honoured instead of silently snapping back to the
|
||||||
|
defaults. Same reasoning as tape_printer.options_from_form.
|
||||||
|
"""
|
||||||
|
submitted = FORM_MARKER in form
|
||||||
|
|
||||||
def number(key, default, cast=float):
|
def number(key, default, cast=float):
|
||||||
try:
|
try:
|
||||||
@@ -134,10 +146,13 @@ def options_from_form(form) -> LabelOptions:
|
|||||||
except (TypeError, ValueError):
|
except (TypeError, ValueError):
|
||||||
return default
|
return default
|
||||||
|
|
||||||
fields = form.getlist('fields') if hasattr(form, 'getlist') else None
|
fields = list(form.getlist('fields')) if hasattr(form, 'getlist') else []
|
||||||
|
if not fields and not submitted:
|
||||||
|
fields = list(DEFAULT_FIELDS)
|
||||||
|
|
||||||
return LabelOptions(
|
return LabelOptions(
|
||||||
preset=form.get('preset') or DEFAULT_PRESET,
|
preset=form.get('preset') or DEFAULT_PRESET,
|
||||||
fields=fields if fields else list(DEFAULT_FIELDS),
|
fields=fields,
|
||||||
offset_x=number('offset_x', 0.0),
|
offset_x=number('offset_x', 0.0),
|
||||||
offset_y=number('offset_y', 0.0),
|
offset_y=number('offset_y', 0.0),
|
||||||
skip=max(0, number('skip', 0, int)),
|
skip=max(0, number('skip', 0, int)),
|
||||||
@@ -325,7 +340,7 @@ def render_pdf(layout, upload_folder):
|
|||||||
if 'location' in fields and label.location:
|
if 'location' in fields and label.location:
|
||||||
meta.append(label.location)
|
meta.append(label.location)
|
||||||
if meta:
|
if meta:
|
||||||
write(' \u00b7 '.join(m for m in meta if m), type_sizes['meta'])
|
write(' · '.join(m for m in meta if m), type_sizes['meta'])
|
||||||
|
|
||||||
pdf.save()
|
pdf.save()
|
||||||
buffer.seek(0)
|
buffer.seek(0)
|
||||||
|
|||||||
Reference in new issue
Block a user