import enum from datetime import date from typing import List from sqlalchemy import Boolean, Date, Enum, ForeignKey, Integer, String from sqlalchemy.orm import mapped_column, Mapped, relationship from nupes.models import Base, Region, Departement, Commune, Circonscription, Genre class BlocLegislatives2024(Base): __tablename__ = "legislatives_2024_bloc" id: Mapped[int] = mapped_column(primary_key=True) nom: Mapped[str] = mapped_column(String(32), unique=True) couleur: Mapped[str] = mapped_column(String(7)) candidats: Mapped[List["CandidatLegislatives2024"]] = relationship("CandidatLegislatives2024", back_populates="bloc") nuances: Mapped[List["NuanceLegislatives2024"]] = relationship( "NuanceLegislatives2024", back_populates="bloc") class NuanceLegislatives2024(Base): __tablename__ = "legislatives_2024_nuance" code: Mapped[str] = mapped_column(String(8), primary_key=True) nom: Mapped[str] = mapped_column(String(64), unique=True) couleur: Mapped[str] = mapped_column(String(7)) bloc_id: Mapped[int] = mapped_column(ForeignKey("legislatives_2024_bloc.id")) bloc: Mapped[BlocLegislatives2024] = relationship(BlocLegislatives2024, back_populates="nuances") candidats: Mapped[List["CandidatLegislatives2024"]] = relationship( "CandidatLegislatives2024", back_populates="nuance") resultats_nationaux: Mapped[List["VoixFranceLegislatives2024"]] = relationship( "VoixFranceLegislatives2024", back_populates="nuance") resultats_par_region: Mapped[List["VoixRegionLegislatives2024"]] = relationship( "VoixRegionLegislatives2024", back_populates="nuance") resultats_par_departement: Mapped[List["VoixDepartementLegislatives2024"]] = relationship( "VoixDepartementLegislatives2024", back_populates="nuance") resultats_par_commune: Mapped[List["VoixCommuneLegislatives2024"]] = relationship( "VoixCommuneLegislatives2024", back_populates="nuance") class CandidatLegislatives2024(Base): __tablename__ = "legislatives_2024_candidat" id: Mapped[int] = mapped_column(primary_key=True) circonscription_id: Mapped[str] = mapped_column(ForeignKey("circonscription.id")) numero: Mapped[int] = mapped_column(Integer()) nuance_id: Mapped[str] = mapped_column(ForeignKey("legislatives_2024_nuance.code")) bloc_id: Mapped[int] = mapped_column(ForeignKey("legislatives_2024_bloc.id")) nom: Mapped[str] = mapped_column(String(256)) prenom: Mapped[str] = mapped_column(String(256)) sexe: Mapped[str] = mapped_column(Enum(Genre, name="legislatives_2024_genre")) date_naissance: Mapped[date] = mapped_column(Date()) profession: Mapped[str] = mapped_column(String(256)) sortant: Mapped[bool] = mapped_column(Boolean()) nom_suppleance: Mapped[str] = mapped_column(String(256)) prenom_suppleance: Mapped[str] = mapped_column(String(256)) sexe_suppleance: Mapped[str] = mapped_column(Enum(Genre, name="legislatives_2024_genre_suppl")) date_naissance_suppleance: Mapped[date] = mapped_column(Date()) sortant_suppleance: Mapped[bool] = mapped_column(Boolean()) circonscription: Mapped[Circonscription] = relationship( "Circonscription", back_populates="candidats_legislatives_2024") nuance: Mapped[NuanceLegislatives2024] = relationship(NuanceLegislatives2024, back_populates="candidats") bloc: Mapped[BlocLegislatives2024] = relationship(BlocLegislatives2024, back_populates="candidats") resultats_par_circonscription: Mapped[List["VoixCirconscriptionLegislatives2024"]] = relationship( "VoixCirconscriptionLegislatives2024", back_populates="candidat") resultats_par_bureau_vote: Mapped[List["VoixBureauVoteLegislatives2024"]] = relationship( "VoixBureauVoteLegislatives2024", back_populates="candidat") class ResultatsFranceLegislatives2024(Base): __tablename__ = "legislatives_2024_resultats_france" id: Mapped[int] = mapped_column(primary_key=True) inscrits_t1: Mapped[int] = mapped_column(Integer(), default=0) votants_t1: Mapped[int] = mapped_column(Integer(), default=0) abstentions_t1: Mapped[int] = mapped_column(Integer(), default=0) exprimes_t1: Mapped[int] = mapped_column(Integer(), default=0) blancs_t1: Mapped[int] = mapped_column(Integer(), default=0) nuls_t1: Mapped[int] = mapped_column(Integer(), default=0) inscrits_t2: Mapped[int] = mapped_column(Integer(), default=0) votants_t2: Mapped[int] = mapped_column(Integer(), default=0) abstentions_t2: Mapped[int] = mapped_column(Integer(), default=0) exprimes_t2: Mapped[int] = mapped_column(Integer(), default=0) blancs_t2: Mapped[int] = mapped_column(Integer(), default=0) nuls_t2: Mapped[int] = mapped_column(Integer(), default=0) resultats_regions: Mapped[List["ResultatsRegionLegislatives2024"]] = relationship( "ResultatsRegionLegislatives2024", back_populates="resultats_france") voix: Mapped[List["VoixFranceLegislatives2024"]] = relationship( "VoixFranceLegislatives2024", back_populates="resultats_france") class ResultatsRegionLegislatives2024(Base): __tablename__ = "legislatives_2024_resultats_region" id: Mapped[int] = mapped_column(primary_key=True) region_id: Mapped[str] = mapped_column(ForeignKey("region.code_insee")) resultats_france_id: Mapped[int] = mapped_column(ForeignKey("legislatives_2024_resultats_france.id")) inscrits_t1: Mapped[int] = mapped_column(Integer(), default=0) votants_t1: Mapped[int] = mapped_column(Integer(), default=0) abstentions_t1: Mapped[int] = mapped_column(Integer(), default=0) exprimes_t1: Mapped[int] = mapped_column(Integer(), default=0) blancs_t1: Mapped[int] = mapped_column(Integer(), default=0) nuls_t1: Mapped[int] = mapped_column(Integer(), default=0) inscrits_t2: Mapped[int] = mapped_column(Integer(), default=0) votants_t2: Mapped[int] = mapped_column(Integer(), default=0) abstentions_t2: Mapped[int] = mapped_column(Integer(), default=0) exprimes_t2: Mapped[int] = mapped_column(Integer(), default=0) blancs_t2: Mapped[int] = mapped_column(Integer(), default=0) nuls_t2: Mapped[int] = mapped_column(Integer(), default=0) region = relationship(Region, back_populates="resultats_legislatives_2024") resultats_france = relationship(ResultatsFranceLegislatives2024, back_populates="resultats_regions") resultats_departements: Mapped[List["ResultatsDepartementLegislatives2024"]] = relationship( "ResultatsDepartementLegislatives2024", back_populates="resultats_region") voix: Mapped[List["VoixRegionLegislatives2024"]] = relationship( "VoixRegionLegislatives2024", back_populates="resultats_region") class ResultatsDepartementLegislatives2024(Base): __tablename__ = "legislatives_2024_resultats_departement" id: Mapped[int] = mapped_column(primary_key=True) dpt_id: Mapped[str] = mapped_column(ForeignKey("departement.code_insee")) resultats_region_id: Mapped[int] = mapped_column(ForeignKey("legislatives_2024_resultats_region.id"), nullable=True) inscrits_t1: Mapped[int] = mapped_column(Integer(), default=0) votants_t1: Mapped[int] = mapped_column(Integer(), default=0) abstentions_t1: Mapped[int] = mapped_column(Integer(), default=0) exprimes_t1: Mapped[int] = mapped_column(Integer(), default=0) blancs_t1: Mapped[int] = mapped_column(Integer(), default=0) nuls_t1: Mapped[int] = mapped_column(Integer(), default=0) inscrits_t2: Mapped[int] = mapped_column(Integer(), default=0) votants_t2: Mapped[int] = mapped_column(Integer(), default=0) abstentions_t2: Mapped[int] = mapped_column(Integer(), default=0) exprimes_t2: Mapped[int] = mapped_column(Integer(), default=0) blancs_t2: Mapped[int] = mapped_column(Integer(), default=0) nuls_t2: Mapped[int] = mapped_column(Integer(), default=0) departement = relationship(Departement, back_populates="resultats_legislatives_2024") resultats_region = relationship(ResultatsRegionLegislatives2024, back_populates="resultats_departements") resultats_communes: Mapped[List["ResultatsCommuneLegislatives2024"]] = relationship( "ResultatsCommuneLegislatives2024", back_populates="resultats_departement") resultats_circonscriptions: Mapped[List["ResultatsCirconscriptionLegislatives2024"]] = relationship( "ResultatsCirconscriptionLegislatives2024", back_populates="resultats_departement") voix: Mapped[List["VoixDepartementLegislatives2024"]] = relationship( "VoixDepartementLegislatives2024", back_populates="resultats_departement") class ResultatsCirconscriptionLegislatives2024(Base): __tablename__ = "legislatives_2024_resultats_circonscription" id: Mapped[int] = mapped_column(primary_key=True) circo_id: Mapped[str] = mapped_column(ForeignKey("circonscription.id")) resultats_departement_id: Mapped[int] = mapped_column(ForeignKey("legislatives_2024_resultats_departement.id")) inscrits_t1: Mapped[int] = mapped_column(Integer(), default=0) votants_t1: Mapped[int] = mapped_column(Integer(), default=0) abstentions_t1: Mapped[int] = mapped_column(Integer(), default=0) exprimes_t1: Mapped[int] = mapped_column(Integer(), default=0) blancs_t1: Mapped[int] = mapped_column(Integer(), default=0) nuls_t1: Mapped[int] = mapped_column(Integer(), default=0) inscrits_t2: Mapped[int] = mapped_column(Integer(), default=0) votants_t2: Mapped[int] = mapped_column(Integer(), default=0) abstentions_t2: Mapped[int] = mapped_column(Integer(), default=0) exprimes_t2: Mapped[int] = mapped_column(Integer(), default=0) blancs_t2: Mapped[int] = mapped_column(Integer(), default=0) nuls_t2: Mapped[int] = mapped_column(Integer(), default=0) circonscription = relationship("Circonscription", back_populates="resultats_legislatives_2024") resultats_departement = relationship(ResultatsDepartementLegislatives2024, back_populates="resultats_circonscriptions") resultats_bureaux_vote: Mapped[List["ResultatsBureauVoteLegislatives2024"]] = relationship( "ResultatsBureauVoteLegislatives2024", back_populates="resultats_circonscription") voix: Mapped[List["VoixCirconscriptionLegislatives2024"]] = relationship( "VoixCirconscriptionLegislatives2024", back_populates="resultats_circonscription") class ResultatsCommuneLegislatives2024(Base): __tablename__ = "legislatives_2024_resultats_commune" id: Mapped[int] = mapped_column(primary_key=True) commune_id: Mapped[str] = mapped_column(ForeignKey("commune.code_insee")) resultats_dpt_id: Mapped[int] = mapped_column(ForeignKey("legislatives_2024_resultats_departement.id")) inscrits_t1: Mapped[int] = mapped_column(Integer(), default=0) votants_t1: Mapped[int] = mapped_column(Integer(), default=0) abstentions_t1: Mapped[int] = mapped_column(Integer(), default=0) exprimes_t1: Mapped[int] = mapped_column(Integer(), default=0) blancs_t1: Mapped[int] = mapped_column(Integer(), default=0) nuls_t1: Mapped[int] = mapped_column(Integer(), default=0) inscrits_t2: Mapped[int] = mapped_column(Integer(), default=0) votants_t2: Mapped[int] = mapped_column(Integer(), default=0) abstentions_t2: Mapped[int] = mapped_column(Integer(), default=0) exprimes_t2: Mapped[int] = mapped_column(Integer(), default=0) blancs_t2: Mapped[int] = mapped_column(Integer(), default=0) nuls_t2: Mapped[int] = mapped_column(Integer(), default=0) commune = relationship(Commune, back_populates="resultats_legislatives_2024") resultats_departement = relationship(ResultatsDepartementLegislatives2024, back_populates="resultats_communes") resultats_bureaux_vote: Mapped[List["ResultatsBureauVoteLegislatives2024"]] = relationship( "ResultatsBureauVoteLegislatives2024", back_populates="resultats_commune") voix: Mapped[List["VoixCommuneLegislatives2024"]] = relationship( "VoixCommuneLegislatives2024", back_populates="resultats_commune") class ResultatsBureauVoteLegislatives2024(Base): __tablename__ = "legislatives_2024_resultats_bureau_vote" id: Mapped[int] = mapped_column(primary_key=True) bv_id: Mapped[str] = mapped_column(ForeignKey("bureau_vote.id")) resultats_commune_id: Mapped[int] = mapped_column(ForeignKey("legislatives_2024_resultats_commune.id")) resultats_circo_id: Mapped[int] = mapped_column(ForeignKey("legislatives_2024_resultats_circonscription.id"), nullable=True) inscrits_t1: Mapped[int] = mapped_column(Integer(), default=0) votants_t1: Mapped[int] = mapped_column(Integer(), default=0) abstentions_t1: Mapped[int] = mapped_column(Integer(), default=0) exprimes_t1: Mapped[int] = mapped_column(Integer(), default=0) blancs_t1: Mapped[int] = mapped_column(Integer(), default=0) nuls_t1: Mapped[int] = mapped_column(Integer(), default=0) inscrits_t2: Mapped[int] = mapped_column(Integer(), default=0) votants_t2: Mapped[int] = mapped_column(Integer(), default=0) abstentions_t2: Mapped[int] = mapped_column(Integer(), default=0) exprimes_t2: Mapped[int] = mapped_column(Integer(), default=0) blancs_t2: Mapped[int] = mapped_column(Integer(), default=0) nuls_t2: Mapped[int] = mapped_column(Integer(), default=0) bureau_vote = relationship("BureauVote", back_populates="resultats_legislatives_2024") resultats_commune = relationship(ResultatsCommuneLegislatives2024, back_populates="resultats_bureaux_vote") resultats_circonscription = relationship(ResultatsCirconscriptionLegislatives2024, back_populates="resultats_bureaux_vote") voix: Mapped[List["VoixBureauVoteLegislatives2024"]] = relationship( "VoixBureauVoteLegislatives2024", back_populates="resultats_bureau_vote") class VoixFranceLegislatives2024(Base): __tablename__ = "legislatives_2024_voix_france" id: Mapped[int] = mapped_column(primary_key=True) nuance_id: Mapped[str] = mapped_column(ForeignKey("legislatives_2024_nuance.code")) resultats_france_id: Mapped[int] = mapped_column(ForeignKey("legislatives_2024_resultats_france.id")) voix_t1: Mapped[int] = mapped_column(Integer(), default=0) voix_t2: Mapped[int] = mapped_column(Integer(), default=0) nuance: Mapped[NuanceLegislatives2024] = relationship( NuanceLegislatives2024, back_populates="resultats_nationaux") resultats_france: Mapped[ResultatsFranceLegislatives2024] = relationship( ResultatsFranceLegislatives2024, back_populates="voix") class VoixRegionLegislatives2024(Base): __tablename__ = "legislatives_2024_voix_region" id: Mapped[int] = mapped_column(primary_key=True) nuance_id: Mapped[str] = mapped_column(ForeignKey("legislatives_2024_nuance.code")) resultats_region_id: Mapped[int] = mapped_column(ForeignKey("legislatives_2024_resultats_region.id")) voix_t1: Mapped[int] = mapped_column(Integer(), default=0) voix_t2: Mapped[int] = mapped_column(Integer(), default=0) nuance: Mapped[NuanceLegislatives2024] = relationship( NuanceLegislatives2024, back_populates="resultats_par_region") resultats_region: Mapped[ResultatsRegionLegislatives2024] = relationship( ResultatsRegionLegislatives2024, back_populates="voix") class VoixDepartementLegislatives2024(Base): __tablename__ = "legislatives_2024_voix_departement" id: Mapped[int] = mapped_column(primary_key=True) nuance_id: Mapped[str] = mapped_column(ForeignKey("legislatives_2024_nuance.code")) resultats_departement_id: Mapped[int] = mapped_column(ForeignKey("legislatives_2024_resultats_departement.id")) voix_t1: Mapped[int] = mapped_column(Integer(), default=0) voix_t2: Mapped[int] = mapped_column(Integer(), default=0) nuance: Mapped[NuanceLegislatives2024] = relationship( NuanceLegislatives2024, back_populates="resultats_par_departement") resultats_departement: Mapped[ResultatsDepartementLegislatives2024] = relationship( ResultatsDepartementLegislatives2024, back_populates="voix") class VoixCirconscriptionLegislatives2024(Base): __tablename__ = "legislatives_2024_voix_circonscription" id: Mapped[int] = mapped_column(primary_key=True) candidat_id: Mapped[int] = mapped_column(ForeignKey("legislatives_2024_candidat.id")) resultats_circonscription_id: Mapped[int] = mapped_column( ForeignKey("legislatives_2024_resultats_circonscription.id")) voix_t1: Mapped[int] = mapped_column(Integer(), default=0) voix_t2: Mapped[int] = mapped_column(Integer(), default=0) candidat: Mapped[CandidatLegislatives2024] = relationship( CandidatLegislatives2024, back_populates="resultats_par_circonscription") resultats_circonscription: Mapped[ResultatsCirconscriptionLegislatives2024] = relationship( ResultatsCirconscriptionLegislatives2024, back_populates="voix") class VoixCommuneLegislatives2024(Base): __tablename__ = "legislatives_2024_voix_commune" id: Mapped[int] = mapped_column(primary_key=True) nuance_id: Mapped[str] = mapped_column(ForeignKey("legislatives_2024_nuance.code")) resultats_commune_id: Mapped[int] = mapped_column(ForeignKey("legislatives_2024_resultats_commune.id")) voix_t1: Mapped[int] = mapped_column(Integer(), default=0) voix_t2: Mapped[int] = mapped_column(Integer(), default=0) nuance: Mapped[NuanceLegislatives2024] = relationship( NuanceLegislatives2024, back_populates="resultats_par_commune") resultats_commune: Mapped[ResultatsCommuneLegislatives2024] = relationship( ResultatsCommuneLegislatives2024, back_populates="voix") class VoixBureauVoteLegislatives2024(Base): __tablename__ = "legislatives_2024_voix_bureau_vote" id: Mapped[int] = mapped_column(primary_key=True) candidat_id: Mapped[int] = mapped_column(ForeignKey("legislatives_2024_candidat.id")) resultats_bureau_vote_id: Mapped[int] = mapped_column(ForeignKey("legislatives_2024_resultats_bureau_vote.id")) voix_t1: Mapped[int] = mapped_column(Integer(), default=0) voix_t2: Mapped[int] = mapped_column(Integer(), default=0) candidat: Mapped[CandidatLegislatives2024] = relationship(CandidatLegislatives2024, back_populates="resultats_par_bureau_vote") resultats_bureau_vote: Mapped[ResultatsBureauVoteLegislatives2024] = relationship( ResultatsBureauVoteLegislatives2024, back_populates="voix")