nupes-elections/nupes/models/europeennes2024.py

296 lines
16 KiB
Python
Raw Normal View History

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
class BlocEuropeennes2024(Base):
__tablename__ = "europeennes_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))
listes: Mapped[List["ListeEuropeennes2024"]] = relationship("ListeEuropeennes2024", back_populates="bloc")
class NuanceEuropeennes2024(Base):
__tablename__ = "europeennes_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))
listes: Mapped[List["ListeEuropeennes2024"]] = relationship("ListeEuropeennes2024", back_populates="nuance")
class ListeEuropeennes2024(Base):
__tablename__ = "europeennes_2024_liste"
id: Mapped[int] = mapped_column(primary_key=True)
nom: Mapped[str] = mapped_column(String(256), unique=True)
nom_majuscules: Mapped[str] = mapped_column(String(256), unique=True, nullable=True)
numero: Mapped[int] = mapped_column(Integer(), unique=True)
nuance_id: Mapped[str] = mapped_column(ForeignKey("europeennes_2024_nuance.code"))
bloc_id: Mapped[int] = mapped_column(ForeignKey("europeennes_2024_bloc.id"))
nuance: Mapped[NuanceEuropeennes2024] = relationship(NuanceEuropeennes2024, back_populates="listes")
bloc: Mapped[BlocEuropeennes2024] = relationship(BlocEuropeennes2024, back_populates="listes")
candidats: Mapped[List["CandidatEuropeennes2024"]] = relationship("CandidatEuropeennes2024",
back_populates="liste")
resultats_nationaux: Mapped[List["VoixListeFranceEuropeennes2024"]] = relationship(
"VoixListeFranceEuropeennes2024", back_populates="liste")
resultats_par_region: Mapped[List["VoixListeRegionEuropeennes2024"]] = relationship(
"VoixListeRegionEuropeennes2024", back_populates="liste")
resultats_par_departement: Mapped[List[
"VoixListeDepartementEuropeennes2024"]] = relationship(
"VoixListeDepartementEuropeennes2024", back_populates="liste")
resultats_par_circonscription: Mapped[List["VoixListeCirconscriptionEuropeennes2024"]] = relationship(
"VoixListeCirconscriptionEuropeennes2024", back_populates="liste")
resultats_par_commune: Mapped[List["VoixListeCommuneEuropeennes2024"]] = relationship(
"VoixListeCommuneEuropeennes2024", back_populates="liste")
resultats_par_bureau_vote: Mapped[List["VoixListeBureauVoteEuropeennes2024"]] = relationship(
"VoixListeBureauVoteEuropeennes2024", back_populates="liste")
class CandidatEuropeennes2024(Base):
class Genre(enum.Enum):
MASCULIN = "M"
FEMININ = "F"
class Personnalite(enum.Enum):
DEFAUT = ""
EURODEPUTE = "RPE"
DEPUTE = "DEP"
SENATEUR = "SEN"
MINISTRE = "MIN"
PRESIDENT_CONSEIL_REGIONAL = "PCR"
PRESIDENT_CONSEIL_DEPARTEMENTAL = "PCD"
MAIRE = "MAI"
__tablename__ = "europeennes_2024_candidat"
id: Mapped[int] = mapped_column(primary_key=True)
liste_id: Mapped[int] = mapped_column(ForeignKey("europeennes_2024_liste.id"))
ordre: Mapped[int] = mapped_column(Integer())
nom: Mapped[str] = mapped_column(String(256))
prenom: Mapped[str] = mapped_column(String(256))
sexe: Mapped[str] = mapped_column(Enum(Genre))
date_naissance: Mapped[date] = mapped_column(Date())
profession: Mapped[str] = mapped_column(String(256))
code_personnalite: Mapped[str] = mapped_column(Enum(Personnalite))
sortant: Mapped[bool] = mapped_column(Boolean())
liste: Mapped[ListeEuropeennes2024] = relationship(ListeEuropeennes2024, back_populates="candidats")
class ResultatsFranceEuropeennes2024(Base):
__tablename__ = "europeennes_2024_resultats_france"
id: Mapped[int] = mapped_column(primary_key=True)
inscrits: Mapped[int] = mapped_column(Integer(), default=0)
votants: Mapped[int] = mapped_column(Integer(), default=0)
abstentions: Mapped[int] = mapped_column(Integer(), default=0)
exprimes: Mapped[int] = mapped_column(Integer(), default=0)
blancs: Mapped[int] = mapped_column(Integer(), default=0)
nuls: Mapped[int] = mapped_column(Integer(), default=0)
resultats_regions: Mapped[List["ResultatsRegionEuropeennes2024"]] = relationship(
"ResultatsRegionEuropeennes2024", back_populates="resultats_france")
voix_listes: Mapped[List["VoixListeFranceEuropeennes2024"]] = relationship(
"VoixListeFranceEuropeennes2024", back_populates="resultats_france")
class ResultatsRegionEuropeennes2024(Base):
__tablename__ = "europeennes_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("europeennes_2024_resultats_france.id"))
inscrits: Mapped[int] = mapped_column(Integer(), default=0)
votants: Mapped[int] = mapped_column(Integer(), default=0)
abstentions: Mapped[int] = mapped_column(Integer(), default=0)
exprimes: Mapped[int] = mapped_column(Integer(), default=0)
blancs: Mapped[int] = mapped_column(Integer(), default=0)
nuls: Mapped[int] = mapped_column(Integer(), default=0)
region = relationship(Region, back_populates="resultats_europeennes_2024")
resultats_france = relationship(ResultatsFranceEuropeennes2024, back_populates="resultats_regions")
resultats_departements: Mapped[List["ResultatsDepartementEuropeennes2024"]] = relationship(
"ResultatsDepartementEuropeennes2024", back_populates="resultats_region")
voix_listes: Mapped[List["VoixListeRegionEuropeennes2024"]] = relationship(
"VoixListeRegionEuropeennes2024", back_populates="resultats_region")
class ResultatsDepartementEuropeennes2024(Base):
__tablename__ = "europeennes_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("europeennes_2024_resultats_region.id"), nullable=True)
inscrits: Mapped[int] = mapped_column(Integer(), default=0)
votants: Mapped[int] = mapped_column(Integer(), default=0)
abstentions: Mapped[int] = mapped_column(Integer(), default=0)
exprimes: Mapped[int] = mapped_column(Integer(), default=0)
blancs: Mapped[int] = mapped_column(Integer(), default=0)
nuls: Mapped[int] = mapped_column(Integer(), default=0)
departement = relationship(Departement, back_populates="resultats_europeennes_2024")
resultats_region = relationship(ResultatsRegionEuropeennes2024, back_populates="resultats_departements")
resultats_communes: Mapped[List["ResultatsCommuneEuropeennes2024"]] = relationship(
"ResultatsCommuneEuropeennes2024", back_populates="resultats_departement")
resultats_circonscriptions: Mapped[List["ResultatsCirconscriptionEuropeennes2024"]] = relationship(
"ResultatsCirconscriptionEuropeennes2024", back_populates="resultats_departement")
voix_listes: Mapped[List["VoixListeDepartementEuropeennes2024"]] = relationship(
"VoixListeDepartementEuropeennes2024", back_populates="resultats_departement")
class ResultatsCirconscriptionEuropeennes2024(Base):
__tablename__ = "europeennes_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("europeennes_2024_resultats_departement.id"))
inscrits: Mapped[int] = mapped_column(Integer(), default=0)
votants: Mapped[int] = mapped_column(Integer(), default=0)
abstentions: Mapped[int] = mapped_column(Integer(), default=0)
exprimes: Mapped[int] = mapped_column(Integer(), default=0)
blancs: Mapped[int] = mapped_column(Integer(), default=0)
nuls: Mapped[int] = mapped_column(Integer(), default=0)
circonscription = relationship("Circonscription", back_populates="resultats_europeennes_2024")
resultats_departement = relationship(ResultatsDepartementEuropeennes2024,
back_populates="resultats_circonscriptions")
resultats_bureaux_vote: Mapped[List["ResultatsBureauVoteEuropeennes2024"]] = relationship(
"ResultatsBureauVoteEuropeennes2024", back_populates="resultats_circonscription")
voix_listes: Mapped[List["VoixListeCirconscriptionEuropeennes2024"]] = relationship(
"VoixListeCirconscriptionEuropeennes2024", back_populates="resultats_circonscription")
class ResultatsCommuneEuropeennes2024(Base):
__tablename__ = "europeennes_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("europeennes_2024_resultats_departement.id"))
inscrits: Mapped[int] = mapped_column(Integer(), default=0)
votants: Mapped[int] = mapped_column(Integer(), default=0)
abstentions: Mapped[int] = mapped_column(Integer(), default=0)
exprimes: Mapped[int] = mapped_column(Integer(), default=0)
blancs: Mapped[int] = mapped_column(Integer(), default=0)
nuls: Mapped[int] = mapped_column(Integer(), default=0)
commune = relationship(Commune, back_populates="resultats_europeennes_2024")
resultats_departement = relationship(ResultatsDepartementEuropeennes2024, back_populates="resultats_communes")
resultats_bureaux_vote: Mapped[List["ResultatsBureauVoteEuropeennes2024"]] = relationship(
"ResultatsBureauVoteEuropeennes2024", back_populates="resultats_commune")
voix_listes: Mapped[List["VoixListeCommuneEuropeennes2024"]] = relationship(
"VoixListeCommuneEuropeennes2024", back_populates="resultats_commune")
class ResultatsBureauVoteEuropeennes2024(Base):
__tablename__ = "europeennes_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("europeennes_2024_resultats_commune.id"))
resultats_circo_id: Mapped[int] = mapped_column(ForeignKey("europeennes_2024_resultats_circonscription.id"),
nullable=True)
inscrits: Mapped[int] = mapped_column(Integer(), default=0)
votants: Mapped[int] = mapped_column(Integer(), default=0)
abstentions: Mapped[int] = mapped_column(Integer(), default=0)
exprimes: Mapped[int] = mapped_column(Integer(), default=0)
blancs: Mapped[int] = mapped_column(Integer(), default=0)
nuls: Mapped[int] = mapped_column(Integer(), default=0)
bureau_vote = relationship("BureauVote", back_populates="resultats_europeennes_2024")
resultats_commune = relationship(ResultatsCommuneEuropeennes2024, back_populates="resultats_bureaux_vote")
resultats_circonscription = relationship(ResultatsCirconscriptionEuropeennes2024,
back_populates="resultats_bureaux_vote")
voix_listes: Mapped[List["VoixListeBureauVoteEuropeennes2024"]] = relationship(
"VoixListeBureauVoteEuropeennes2024", back_populates="resultats_bureau_vote")
class VoixListeFranceEuropeennes2024(Base):
__tablename__ = "europeennes_2024_voix_france"
liste_id: Mapped[int] = mapped_column(ForeignKey("europeennes_2024_liste.id"), primary_key=True)
resultats_france_id: Mapped[int] = mapped_column(ForeignKey("europeennes_2024_resultats_france.id"),
primary_key=True)
voix: Mapped[int] = mapped_column(Integer(), default=0)
liste: Mapped[ListeEuropeennes2024] = relationship(ListeEuropeennes2024, back_populates="resultats_nationaux")
resultats_france: Mapped[ResultatsFranceEuropeennes2024] = relationship(ResultatsFranceEuropeennes2024,
back_populates="voix_listes")
class VoixListeRegionEuropeennes2024(Base):
__tablename__ = "europeennes_2024_voix_region"
liste_id: Mapped[int] = mapped_column(ForeignKey("europeennes_2024_liste.id"), primary_key=True)
resultats_region_id: Mapped[int] = mapped_column(ForeignKey("europeennes_2024_resultats_region.id"),
primary_key=True)
voix: Mapped[int] = mapped_column(Integer(), default=0)
liste: Mapped[ListeEuropeennes2024] = relationship(ListeEuropeennes2024, back_populates="resultats_par_region")
resultats_region: Mapped[ResultatsRegionEuropeennes2024] = relationship(ResultatsRegionEuropeennes2024,
back_populates="voix_listes")
class VoixListeDepartementEuropeennes2024(Base):
__tablename__ = "europeennes_2024_voix_departement"
liste_id: Mapped[int] = mapped_column(ForeignKey("europeennes_2024_liste.id"), primary_key=True)
resultats_departement_id: Mapped[int] = mapped_column(ForeignKey("europeennes_2024_resultats_departement.id"),
primary_key=True)
voix: Mapped[int] = mapped_column(Integer(), default=0)
liste: Mapped[ListeEuropeennes2024] = relationship(ListeEuropeennes2024, back_populates="resultats_par_departement")
resultats_departement: Mapped[ResultatsDepartementEuropeennes2024] = relationship(
ResultatsDepartementEuropeennes2024, back_populates="voix_listes")
class VoixListeCirconscriptionEuropeennes2024(Base):
__tablename__ = "europeennes_2024_voix_circonscription"
liste_id: Mapped[int] = mapped_column(ForeignKey("europeennes_2024_liste.id"), primary_key=True)
resultats_circonscription_id: Mapped[int] = mapped_column(
ForeignKey("europeennes_2024_resultats_circonscription.id"), primary_key=True)
voix: Mapped[int] = mapped_column(Integer(), default=0)
liste: Mapped[ListeEuropeennes2024] = relationship(ListeEuropeennes2024,
back_populates="resultats_par_circonscription")
resultats_circonscription: Mapped[ResultatsCirconscriptionEuropeennes2024] = relationship(
ResultatsCirconscriptionEuropeennes2024, back_populates="voix_listes")
class VoixListeCommuneEuropeennes2024(Base):
__tablename__ = "europeennes_2024_voix_commune"
liste_id: Mapped[int] = mapped_column(ForeignKey("europeennes_2024_liste.id"), primary_key=True)
resultats_commune_id: Mapped[int] = mapped_column(ForeignKey("europeennes_2024_resultats_commune.id"),
primary_key=True)
voix: Mapped[int] = mapped_column(Integer(), default=0)
liste: Mapped[ListeEuropeennes2024] = relationship(ListeEuropeennes2024, back_populates="resultats_par_commune")
resultats_commune: Mapped[ResultatsCommuneEuropeennes2024] = relationship(ResultatsCommuneEuropeennes2024,
back_populates="voix_listes")
class VoixListeBureauVoteEuropeennes2024(Base):
__tablename__ = "europeennes_2024_voix_bureau_vote"
liste_id: Mapped[int] = mapped_column(ForeignKey("europeennes_2024_liste.id"), primary_key=True)
resultats_bureau_vote_id: Mapped[int] = mapped_column(ForeignKey("europeennes_2024_resultats_bureau_vote.id"),
primary_key=True)
voix: Mapped[int] = mapped_column(Integer(), default=0)
liste: Mapped[ListeEuropeennes2024] = relationship(ListeEuropeennes2024, back_populates="resultats_par_bureau_vote")
resultats_bureau_vote: Mapped[ResultatsBureauVoteEuropeennes2024] = relationship(ResultatsBureauVoteEuropeennes2024,
back_populates="voix_listes")