def returnAllSites(): get_all_sites = models.TSite.query.order_by('ref_site').all() sites = site_schema.dump(get_all_sites) for site in sites: if len(site.get("t_photos")) > 0: if site.get('main_photo') == None: first_photo = site.get("t_photos") main_photo = models.TPhoto.query.filter_by( id_photo=first_photo[0]).one_or_none() else: main_photo = models.TPhoto.query.filter_by( id_photo=site.get('main_photo')).one_or_none() if main_photo: photo_schema = models.TPhotoSchema() main_photo = photo_schema.dump(main_photo) site['main_photo'] = utils.getThumbnail(main_photo).get( 'output_name') else: site["main_photo"] = "no_photo" else: site["main_photo"] = "no_photo" return jsonify(sites)
import models import utils import random from models import (db) from config import DATA_IMAGES_PATH, IGN_KEY import json from datetime import datetime from flask_babel import format_datetime, gettext, ngettext main = Blueprint('main', __name__, template_folder='tpl') db = SQLAlchemy() dicotheme_schema = models.DicoThemeSchema(many=True) dicostheme_schema = models.DicoSthemeSchema(many=True) photo_schema = models.TPhotoSchema(many=True) site_schema = models.TSiteSchema(many=True) themes_sthemes_schema = models.CorSthemeThemeSchema(many=True) villes_schema = models.VilleSchema(many=True) communes_schema = models.CommunesSchema(many=True) @main.route('/') def home(): """ sql = text("SELECT value FROM geopaysages.conf WHERE key = 'home_blocks'") rows = db.engine.execute(sql).fetchall() id_photos = json.loads(rows[0]['value']) get_photos = models.TPhoto.query.filter( models.TPhoto.id_photo.in_(id_photos)) dump_pĥotos = photo_schema.dump(get_photos).data