45 lines
2.6 KiB
Python
45 lines
2.6 KiB
Python
from sqlalchemy import select
|
|
from sqlalchemy.orm import Session
|
|
from ..models import DemandFeatureCard, DemandForm, DemandHero, DestinationHero, HeroSlide, VehicleOption, VehicleServiceConfig
|
|
from ..serializers import model_dict
|
|
|
|
|
|
def public_model_dict(item) -> dict:
|
|
result = model_dict(item)
|
|
result.pop("deptId", None)
|
|
result.pop("createdById", None)
|
|
return result
|
|
|
|
|
|
def site_config(db: Session, active_only: bool, include_public_extras: bool = True) -> dict:
|
|
hero_stmt = select(HeroSlide).order_by(HeroSlide.sortOrder.asc())
|
|
destination_hero_stmt = select(DestinationHero).order_by(DestinationHero.sortOrder.asc())
|
|
vehicle_stmt = select(VehicleOption).order_by(VehicleOption.sortOrder.asc())
|
|
demand_hero_stmt = select(DemandHero).order_by(DemandHero.sortOrder.asc())
|
|
demand_feature_card_stmt = select(DemandFeatureCard).order_by(DemandFeatureCard.sortOrder.asc())
|
|
demand_form_stmt = select(DemandForm).order_by(DemandForm.createdAt.asc())
|
|
vehicle_service_stmt = select(VehicleServiceConfig).order_by(VehicleServiceConfig.createdAt.asc())
|
|
if active_only:
|
|
hero_stmt = hero_stmt.where(HeroSlide.isActive.is_(True))
|
|
destination_hero_stmt = destination_hero_stmt.where(DestinationHero.isActive.is_(True))
|
|
vehicle_stmt = vehicle_stmt.where(VehicleOption.isActive.is_(True))
|
|
demand_hero_stmt = demand_hero_stmt.where(DemandHero.isActive.is_(True))
|
|
demand_feature_card_stmt = demand_feature_card_stmt.where(DemandFeatureCard.isActive.is_(True))
|
|
demand_form_stmt = demand_form_stmt.where(DemandForm.isActive.is_(True))
|
|
vehicle_service_stmt = vehicle_service_stmt.where(VehicleServiceConfig.isActive.is_(True))
|
|
|
|
hero_slides = db.scalars(hero_stmt).all()
|
|
destination_hero = db.scalars(destination_hero_stmt).all()
|
|
result = {
|
|
"heroSlides": [public_model_dict(item) for item in hero_slides],
|
|
"destinationHero": [public_model_dict(item) for item in destination_hero],
|
|
}
|
|
if include_public_extras:
|
|
result["vehicleOptions"] = [public_model_dict(item) for item in db.scalars(vehicle_stmt).all()]
|
|
vehicle_service = db.scalars(vehicle_service_stmt).first()
|
|
result["vehicleService"] = public_model_dict(vehicle_service) if vehicle_service else None
|
|
result["demandHero"] = [public_model_dict(item) for item in db.scalars(demand_hero_stmt).all()]
|
|
result["demandFeatureCards"] = [public_model_dict(item) for item in db.scalars(demand_feature_card_stmt).all()]
|
|
result["demandForm"] = [public_model_dict(item) for item in db.scalars(demand_form_stmt).all()]
|
|
return result
|