From a48ee9e73d7ccbc244bb8edaa0a4cad6a1844a9b Mon Sep 17 00:00:00 2001 From: Stephan Kerkman Date: Thu, 28 May 2026 18:55:16 +0200 Subject: [PATCH] fix: VPC image scraping and show species name on plant edit - vpc.py: target .wp-caption img for hero image (VPC uses Elementor, not standard WooCommerce gallery); skip logo and placeholder images by URL pattern - plant_edit view: pass plant.species as 'species' so the species info banner (including scientific name) appears on the edit form Co-Authored-By: Claude Sonnet 4.6 --- plants/services/vpc.py | 9 +++++---- plants/views/plants.py | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/plants/services/vpc.py b/plants/services/vpc.py index 2cdf740..2911d97 100644 --- a/plants/services/vpc.py +++ b/plants/services/vpc.py @@ -151,12 +151,13 @@ def scrape_plant(slug): h1 = soup.find('h1') name = h1.get_text(strip=True) if h1 else slug.replace('-', ' ').title() - # Hero image + # Hero image — VPC wraps the plant photo in a .wp-caption figure hero_img = '' - for sel in ['.woocommerce-product-gallery img', '.product-images img', 'article img']: + for sel in ['.wp-caption img', 'figure img', '.elementor-widget-image img']: img = soup.select_one(sel) - if img and img.get('src', '').startswith('http'): - hero_img = img['src'] + src = img.get('src', '') if img else '' + if src.startswith('http') and 'Grif_VPC' not in src and 'NoImage' not in src: + hero_img = src break result = { diff --git a/plants/views/plants.py b/plants/views/plants.py index efde4cb..3476380 100644 --- a/plants/views/plants.py +++ b/plants/views/plants.py @@ -101,6 +101,7 @@ def plant_edit(request, pk): return render(request, 'plants/plant_form.html', { 'form': form, 'plant': plant, + 'species': plant.species, 'title': 'Edit Plant', })