fix printer batch vendor resolution + base url
This commit is contained in:
@@ -364,12 +364,29 @@ UNIVERSAL_INSTALL_VENDORS = frozenset({'HP', 'Xerox'})
|
||||
|
||||
def _batch_base_url():
|
||||
"""Base URL the generated .bat downloads installers from. Prefer the
|
||||
configured site_base_url (already includes the /shopdb mount); fall back to
|
||||
the request root so a site that never set it still produces a usable batch."""
|
||||
configured site_base_url (it already includes scheme + the /shopdb mount).
|
||||
|
||||
Fallback matters: behind IIS the app sees http on a loopback port and its
|
||||
url_root drops the mount, so a naive request.url_root yields a broken
|
||||
http://127.0.0.1/installers/... URL. Rebuild from the forwarded Host + the
|
||||
mount (script_root) and force https instead."""
|
||||
base = (Setting.get('site_base_url') or '').strip().rstrip('/')
|
||||
if base:
|
||||
return base
|
||||
return request.url_root.rstrip('/')
|
||||
host = request.headers.get('X-Forwarded-Host') or request.host
|
||||
root = (request.script_root or '').rstrip('/')
|
||||
return 'https://%s%s' % (host, root)
|
||||
|
||||
|
||||
def _printer_vendor(printer):
|
||||
"""Vendor name for install grouping. The legacy import sets the printer's
|
||||
model but not its direct vendorid, so resolve via the model's vendor (as the
|
||||
classic installprinter.asp did) when the printer has no direct vendor."""
|
||||
if printer.vendor:
|
||||
return (printer.vendor.vendor or '').strip()
|
||||
if printer.model and printer.model.vendor:
|
||||
return (printer.model.vendor.vendor or '').strip()
|
||||
return ''
|
||||
|
||||
|
||||
def _installer_url(installpath, base):
|
||||
@@ -429,7 +446,7 @@ def printer_install_batch():
|
||||
name = _install_name(printer, asset)
|
||||
if not name:
|
||||
continue
|
||||
vendor = (printer.vendor.vendor if printer.vendor else '').strip()
|
||||
vendor = _printer_vendor(printer)
|
||||
installpath = (printer.installpath or '').strip()
|
||||
if vendor in UNIVERSAL_INSTALL_VENDORS:
|
||||
universal.append(name)
|
||||
|
||||
Reference in New Issue
Block a user