From 3311525e43e5d393a8b995ace5b78e1d320f4ac8 Mon Sep 17 00:00:00 2001 From: Xavier Arbez <16793813+xavyeah39@users.noreply.github.com> Date: Wed, 16 Mar 2022 22:36:22 +0100 Subject: [PATCH] Carte - Popup : Afficher la photo principale main_photo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FIX : Affiche la vignette de la photo définie comme principale pour chaque site (champ ``main_photo``). --- backend/routes.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/backend/routes.py b/backend/routes.py index 3fc92516..99df992a 100755 --- a/backend/routes.py +++ b/backend/routes.py @@ -364,6 +364,34 @@ def sites(): 'subthemes': subthemes, 'township': townships } + + photo_ids = [] + sites_without_photo = [] + for site in sites: + photo_id = site.get('main_photo') + if photo_id: + photo_ids.append(site.get('main_photo')) + else: + sites_without_photo.append(str(site.get('id_site'))) + + query_photos = models.TPhoto.query.filter( + models.TPhoto.id_photo.in_(photo_ids) + ) + dump_photos = photo_schema.dump(query_photos).data + + if len(sites_without_photo): + sql_missing_photos_str = "select distinct on (id_site) * from geopaysages.t_photo where id_site IN (" + ",".join(sites_without_photo) + ") order by id_site, filter_date desc" + sql_missing_photos = text(sql_missing_photos_str) + missing_photos_result = db.engine.execute(sql_missing_photos).fetchall() + missing_photos = [dict(row) for row in missing_photos_result] + for missing_photo in missing_photos: + missing_photo['t_site'] = missing_photo.get('id_site') + dump_photos.append(missing_photo) + + for site in sites: + id_site = site.get('id_site') + photo = next(photo for photo in dump_photos if (photo.get('t_site') == id_site)) + site['photo'] = utils.getThumbnail(photo).get('output_url') def getItem(name, id): return next(item for item in dbs.get(name) if item.get('id') == id) @@ -393,4 +421,4 @@ def about(): if (not utils.isDbPagePublished('about')): return abort(404) - return render_template('db-page.html', name='about', page=utils.getDbPage('about')) \ No newline at end of file + return render_template('db-page.html', name='about', page=utils.getDbPage('about'))