Showing
5 changed files
with
67 additions
and
4 deletions
| ... | @@ -385,14 +385,14 @@ def get_header_value(headers, key): | ... | @@ -385,14 +385,14 @@ def get_header_value(headers, key): |
| 385 | 385 | ||
| 386 | 386 | ||
| 387 | def get_client_ip(headers): | 387 | def get_client_ip(headers): |
| 388 | - real_ip = get_header_value(headers, b"x-real-ip") | ||
| 389 | - if real_ip: | ||
| 390 | - return real_ip.strip() | ||
| 391 | - | ||
| 392 | forwarded_for = get_header_value(headers, b"x-forwarded-for") | 388 | forwarded_for = get_header_value(headers, b"x-forwarded-for") |
| 393 | if forwarded_for: | 389 | if forwarded_for: |
| 394 | return forwarded_for.split(",", 1)[0].strip() | 390 | return forwarded_for.split(",", 1)[0].strip() |
| 395 | 391 | ||
| 392 | + real_ip = get_header_value(headers, b"x-real-ip") | ||
| 393 | + if real_ip: | ||
| 394 | + return real_ip.strip() | ||
| 395 | + | ||
| 396 | return None | 396 | return None |
| 397 | 397 | ||
| 398 | 398 | ... | ... |
models/ubigeo.py
0 → 100644
| 1 | +from sqlalchemy.orm import Mapped, mapped_column | ||
| 2 | +from presupuestov1.model import Base | ||
| 3 | + | ||
| 4 | +from sqlalchemy import ( | ||
| 5 | + Integer, | ||
| 6 | + String, | ||
| 7 | + Text, | ||
| 8 | + Numeric, | ||
| 9 | + Index, | ||
| 10 | + MetaData, | ||
| 11 | +) | ||
| 12 | + | ||
| 13 | +class ProyectoResumenes(Base): | ||
| 14 | + __tablename__ = "ubigeo_resumenes" | ||
| 15 | + __table_args__ = ( | ||
| 16 | + Index("idx_proyecto_resumenes_gestion", "gestion"), | ||
| 17 | + {"schema": "web"}, | ||
| 18 | + ) | ||
| 19 | + | ||
| 20 | + id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True) | ||
| 21 | + | ||
| 22 | + gestion: Mapped[int] = mapped_column(Integer) | ||
| 23 | + ubigeo: Mapped[int] = mapped_column(String(9)) | ||
| 24 | + | ||
| 25 | + desc_ubigeo: Mapped[str | None] = mapped_column(Text) | ||
| 26 | + desc_departamento: Mapped[str | None] = mapped_column(Text) | ||
| 27 | + monto: Mapped[float | None] = mapped_column(Numeric(30, 15)) | ||
| 28 | + per_capita: Mapped[float | None] = mapped_column(Numeric) | ||
| 29 | + ranking: Mapped[int | None] = mapped_column(Integer) |
| ... | @@ -64,6 +64,24 @@ def fetch_entidad( | ... | @@ -64,6 +64,24 @@ def fetch_entidad( |
| 64 | 64 | ||
| 65 | return entidad | 65 | return entidad |
| 66 | 66 | ||
| 67 | +@router_ubigeo.get('/todo', response_model=List[schemas.ubigeo.UbigeoResumenes]) | ||
| 68 | +@not_found | ||
| 69 | +def fetch_ubigeo_todo( | ||
| 70 | + db: Session = Depends(model.get_db), | ||
| 71 | + query: schema.QueryParams = Depends(), | ||
| 72 | +): | ||
| 73 | + gestion = query.gestion is not None else 0 | ||
| 74 | + | ||
| 75 | + UbigeoResumenesSchema = schemas.ubigeo.UbigeoResumenes | ||
| 76 | + UbigeoResumenes = model.ubigeo.UbigeoResumenes | ||
| 77 | + | ||
| 78 | + schema_fields = UbigeoResumenesSchema.model_fields.keys() | ||
| 79 | + cols = [getattr(UbigeoResumenes, name) for name in schema_fields] | ||
| 80 | + | ||
| 81 | + return db.execute( | ||
| 82 | + select(*cols).where(UbigeoResumenes.gestion == gestion) | ||
| 83 | + ).mappings().all() | ||
| 84 | + | ||
| 67 | 85 | ||
| 68 | @router_ubigeo.get('/{ubigeo_id:str}', response_model=schemas.entity.ClasGeograficoIngresosGastos) | 86 | @router_ubigeo.get('/{ubigeo_id:str}', response_model=schemas.entity.ClasGeograficoIngresosGastos) |
| 69 | @not_found | 87 | @not_found | ... | ... |
schemas/ubigeo.py
0 → 100644
| 1 | +from typing import List | ||
| 2 | + | ||
| 3 | +from presupuestov1.schema import OrmBaseModel | ||
| 4 | +from presupuestov1 import schemas | ||
| 5 | + | ||
| 6 | + | ||
| 7 | +class UbigeoResumenes(OrmBaseModel): | ||
| 8 | + gestion: int | ||
| 9 | + ubigeo: str | ||
| 10 | + desc_ubigeo: str | ||
| 11 | + desc_departamento: str | ||
| 12 | + mont: float | ||
| 13 | + per_capita: str | ||
| 14 | + ranking: int | ||
| 15 | + n_entidades: int |
-
Please register or login to post a comment