@frontend.route('/objects/<int:object_id>/label')
@object_permissions_required(Permissions.READ, on_unauthorized=on_unauthorized)
def print_object_label(object_id):
    mode = flask.request.args.get('mode', 'mixed')
    if (mode == 'fixed-width'):
        create_mixed_labels = False
        create_long_labels = False
        include_qrcode_in_long_labels = None
        paper_format = flask.request.args.get('width-paper-format', '')
        if (paper_format not in PAGE_SIZES):
            paper_format = DEFAULT_PAPER_FORMAT
        maximum_width = math.floor(((PAGE_SIZES[paper_format][0] / mm) - (2 * HORIZONTAL_LABEL_MARGIN)))
        maximum_height = math.floor(((PAGE_SIZES[paper_format][1] / mm) - (2 * VERTICAL_LABEL_MARGIN)))
        ghs_classes_side_by_side = ('side-by-side' in flask.request.args)
        label_minimum_width = 20
        if ghs_classes_side_by_side:
            label_minimum_width = 40
        try:
            label_width = float(flask.request.args.get('label-width', '20'))
        except ValueError:
            label_width = 0
        if math.isnan(label_width):
            label_width = 0
        if (label_width < label_minimum_width):
            label_width = label_minimum_width
        if (label_width > maximum_width):
            label_width = maximum_width
        try:
            label_minimum_height = float(flask.request.args.get('label-minimum-height', '0'))
        except ValueError:
            label_minimum_height = 0
        if math.isnan(label_minimum_height):
            label_minimum_height = 0
        if (label_minimum_height < 0):
            label_minimum_height = 0
        if (label_minimum_height > maximum_height):
            label_minimum_height = maximum_height
        qrcode_width = 18
        centered = ('centered' in flask.request.args)
    elif (mode == 'minimum-height'):
        create_mixed_labels = False
        create_long_labels = True
        paper_format = flask.request.args.get('height-paper-format', '')
        if (paper_format not in PAGE_SIZES):
            paper_format = DEFAULT_PAPER_FORMAT
        maximum_width = math.floor(((PAGE_SIZES[paper_format][0] / mm) - (2 * HORIZONTAL_LABEL_MARGIN)))
        include_qrcode_in_long_labels = ('include-qrcode' in flask.request.args)
        label_width = 0
        label_minimum_height = 0
        try:
            label_minimum_width = float(flask.request.args.get('label-minimum-width', '0'))
        except ValueError:
            label_minimum_width = 0
        if math.isnan(label_minimum_width):
            label_minimum_width = 0
        if (label_minimum_width < 0):
            label_minimum_width = 0
        if (label_minimum_width > maximum_width):
            label_minimum_width = maximum_width
        qrcode_width = 0
        ghs_classes_side_by_side = None
        centered = None
    else:
        create_mixed_labels = True
        create_long_labels = None
        include_qrcode_in_long_labels = None
        paper_format = flask.request.args.get('mixed-paper-format', '')
        if (paper_format not in PAGE_SIZES):
            paper_format = DEFAULT_PAPER_FORMAT
        label_width = 0
        label_minimum_height = 0
        qrcode_width = 0
        label_minimum_width = 0
        ghs_classes_side_by_side = None
        centered = None
    object = get_object(object_id=object_id)
    object_log_entries = object_log.get_object_log_entries(object_id=object_id, user_id=flask_login.current_user.id)
    for object_log_entry in object_log_entries:
        if (object_log_entry.type in (ObjectLogEntryType.CREATE_OBJECT, ObjectLogEntryType.CREATE_BATCH)):
            creation_date = object_log_entry.utc_datetime.strftime('%Y-%m-%d')
            creation_user = get_user(object_log_entry.user_id).name
            break
    else:
        creation_date = _('Unknown')
        creation_user = _('Unknown')
    if (('created' in object.data) and ('_type' in object.data['created']) and (object.data['created']['_type'] == 'datetime')):
        creation_date = object.data['created']['utc_datetime'].split(' ')[0]
    if (('name' in object.data) and ('_type' in object.data['name']) and (object.data['name']['_type'] == 'text')):
        object_name = get_translated_text(object.data['name']['text'])
    else:
        object_name = _('Unknown Object')
    object_url = flask.url_for('.object', object_id=object_id, _external=True)
    if (('hazards' in object.data) and ('_type' in object.data['hazards']) and (object.data['hazards']['_type'] == 'hazards')):
        hazards = object.data['hazards']['hazards']
    else:
        hazards = []
    pdf_data = create_labels(object_id=object_id, object_name=object_name, object_url=object_url, creation_user=creation_user, creation_date=creation_date, ghs_classes=hazards, paper_format=paper_format, create_mixed_labels=create_mixed_labels, create_long_labels=create_long_labels, include_qrcode_in_long_labels=include_qrcode_in_long_labels, label_width=label_width, label_minimum_height=label_minimum_height, label_minimum_width=label_minimum_width, qrcode_width=qrcode_width, ghs_classes_side_by_side=ghs_classes_side_by_side, centered=centered)
    return flask.send_file(io.BytesIO(pdf_data), mimetype='application/pdf', cache_timeout=(- 1))
@frontend.route('/objects/<int:object_id>/label')
@object_permissions_required(Permissions.READ, on_unauthorized=on_unauthorized)
def print_object_label(object_id):
    mode = flask.request.args.get('mode', 'mixed')
    if (mode == 'fixed-width'):
        create_mixed_labels = False
        create_long_labels = False
        include_qrcode_in_long_labels = None
        paper_format = flask.request.args.get('width-paper-format', )
        if (paper_format not in PAGE_SIZES):
            paper_format = DEFAULT_PAPER_FORMAT
        maximum_width = math.floor(((PAGE_SIZES[paper_format][0] / mm) - (2 * HORIZONTAL_LABEL_MARGIN)))
        maximum_height = math.floor(((PAGE_SIZES[paper_format][1] / mm) - (2 * VERTICAL_LABEL_MARGIN)))
        ghs_classes_side_by_side = ('side-by-side' in flask.request.args)
        label_minimum_width = 20
        if ghs_classes_side_by_side:
            label_minimum_width = 40
        try:
            label_width = float(flask.request.args.get('label-width', '20'))
        except ValueError:
            label_width = 0
        if math.isnan(label_width):
            label_width = 0
        if (label_width < label_minimum_width):
            label_width = label_minimum_width
        if (label_width > maximum_width):
            label_width = maximum_width
        try:
            label_minimum_height = float(flask.request.args.get('label-minimum-height', '0'))
        except ValueError:
            label_minimum_height = 0
        if math.isnan(label_minimum_height):
            label_minimum_height = 0
        if (label_minimum_height < 0):
            label_minimum_height = 0
        if (label_minimum_height > maximum_height):
            label_minimum_height = maximum_height
        qrcode_width = 18
        centered = ('centered' in flask.request.args)
    elif (mode == 'minimum-height'):
        create_mixed_labels = False
        create_long_labels = True
        paper_format = flask.request.args.get('height-paper-format', )
        if (paper_format not in PAGE_SIZES):
            paper_format = DEFAULT_PAPER_FORMAT
        maximum_width = math.floor(((PAGE_SIZES[paper_format][0] / mm) - (2 * HORIZONTAL_LABEL_MARGIN)))
        include_qrcode_in_long_labels = ('include-qrcode' in flask.request.args)
        label_width = 0
        label_minimum_height = 0
        try:
            label_minimum_width = float(flask.request.args.get('label-minimum-width', '0'))
        except ValueError:
            label_minimum_width = 0
        if math.isnan(label_minimum_width):
            label_minimum_width = 0
        if (label_minimum_width < 0):
            label_minimum_width = 0
        if (label_minimum_width > maximum_width):
            label_minimum_width = maximum_width
        qrcode_width = 0
        ghs_classes_side_by_side = None
        centered = None
    else:
        create_mixed_labels = True
        create_long_labels = None
        include_qrcode_in_long_labels = None
        paper_format = flask.request.args.get('mixed-paper-format', )
        if (paper_format not in PAGE_SIZES):
            paper_format = DEFAULT_PAPER_FORMAT
        label_width = 0
        label_minimum_height = 0
        qrcode_width = 0
        label_minimum_width = 0
        ghs_classes_side_by_side = None
        centered = None
    object = get_object(object_id=object_id)
    object_log_entries = object_log.get_object_log_entries(object_id=object_id, user_id=flask_login.current_user.id)
    for object_log_entry in object_log_entries:
        if (object_log_entry.type in (ObjectLogEntryType.CREATE_OBJECT, ObjectLogEntryType.CREATE_BATCH)):
            creation_date = object_log_entry.utc_datetime.strftime('%Y-%m-%d')
            creation_user = get_user(object_log_entry.user_id).name
            break
    else:
        creation_date = _('Unknown')
        creation_user = _('Unknown')
    if (('created' in object.data) and ('_type' in object.data['created']) and (object.data['created']['_type'] == 'datetime')):
        creation_date = object.data['created']['utc_datetime'].split(' ')[0]
    if (('name' in object.data) and ('_type' in object.data['name']) and (object.data['name']['_type'] == 'text')):
        object_name = get_translated_text(object.data['name']['text'])
    else:
        object_name = _('Unknown Object')
    object_url = flask.url_for('.object', object_id=object_id, _external=True)
    if (('hazards' in object.data) and ('_type' in object.data['hazards']) and (object.data['hazards']['_type'] == 'hazards')):
        hazards = object.data['hazards']['hazards']
    else:
        hazards = []
    pdf_data = create_labels(object_id=object_id, object_name=object_name, object_url=object_url, creation_user=creation_user, creation_date=creation_date, ghs_classes=hazards, paper_format=paper_format, create_mixed_labels=create_mixed_labels, create_long_labels=create_long_labels, include_qrcode_in_long_labels=include_qrcode_in_long_labels, label_width=label_width, label_minimum_height=label_minimum_height, label_minimum_width=label_minimum_width, qrcode_width=qrcode_width, ghs_classes_side_by_side=ghs_classes_side_by_side, centered=centered)
    return flask.send_file(io.BytesIO(pdf_data), mimetype='application/pdf', cache_timeout=(- 1))