Skip to content

Commit

Permalink
Carte - Popup : Afficher la photo principale main_photo
Browse files Browse the repository at this point in the history
FIX : Affiche la vignette de la photo définie comme principale pour chaque site (champ ``main_photo``).
  • Loading branch information
xavyeah39 authored Mar 16, 2022
1 parent 31da9b9 commit 3311525
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion backend/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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'))
return render_template('db-page.html', name='about', page=utils.getDbPage('about'))

1 comment on commit 3311525

@xavyeah39
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

en référence à #106

Please sign in to comment.