From b3166811e57b40e1bde204387e5c38aa0311cdbe Mon Sep 17 00:00:00 2001 From: Niklas Meinzer Date: Wed, 29 Oct 2025 10:31:09 +0100 Subject: [PATCH] Started with area page --- src/allmende_payment_system/api/shop.py | 10 +++++ src/allmende_payment_system/app.py | 3 ++ src/allmende_payment_system/models.py | 14 ++++++- .../static/img/placeholder.jpg | Bin 0 -> 5924 bytes .../templates/area.html.jinja | 36 ++++++++++++++++++ .../templates/shop.html.jinja | 4 +- src/allmende_payment_system/tools.py | 14 +++++++ 7 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 src/allmende_payment_system/static/img/placeholder.jpg create mode 100644 src/allmende_payment_system/templates/area.html.jinja diff --git a/src/allmende_payment_system/api/shop.py b/src/allmende_payment_system/api/shop.py index 71be710..9a7d868 100644 --- a/src/allmende_payment_system/api/shop.py +++ b/src/allmende_payment_system/api/shop.py @@ -18,3 +18,13 @@ async def get_shop(request: Request, session: SessionDep): "shop.html.jinja", context={"request": request, "areas": areas}, ) + + +@shop_router.get("/shop/area/{area_id}") +async def get_shop(request: Request, session: SessionDep, area_id: int): + query = select(Area).where(Area.id == area_id) + area = session.scalars(query).one() + return templates.TemplateResponse( + "area.html.jinja", + context={"request": request, "area": area}, + ) diff --git a/src/allmende_payment_system/app.py b/src/allmende_payment_system/app.py index c51e0bf..d7ae837 100644 --- a/src/allmende_payment_system/app.py +++ b/src/allmende_payment_system/app.py @@ -1,3 +1,5 @@ +import locale + from fastapi import Depends, FastAPI from fastapi.staticfiles import StaticFiles @@ -5,6 +7,7 @@ from allmende_payment_system.api import root_router from allmende_payment_system.api.dependencies import get_user from allmende_payment_system.api.shop import shop_router +locale.setlocale(locale.LC_ALL, "de_DE.UTF-8") app = FastAPI(dependencies=[Depends(get_user)]) diff --git a/src/allmende_payment_system/models.py b/src/allmende_payment_system/models.py index b9bff74..9400be1 100644 --- a/src/allmende_payment_system/models.py +++ b/src/allmende_payment_system/models.py @@ -55,6 +55,15 @@ class Area(Base): description: Mapped[str] = mapped_column(nullable=True) image_path: Mapped[str] = mapped_column(nullable=True) + products: Mapped[list["Product"]] = relationship("Product") + + +UnitsOfMeasure = typing.Literal[ + "g", + "kg", + "piece", +] + class Product(Base): __tablename__ = TABLE_PREFIX + "product" @@ -62,11 +71,14 @@ class Product(Base): name: Mapped[str] = mapped_column(nullable=False, unique=True) price: Mapped[decimal.Decimal] = mapped_column(Numeric(10, 2)) + unit_of_measure: Mapped[UnitsOfMeasure] = mapped_column(nullable=False) # TODO: limit this to actually used vat rates? vat_rate: Mapped[decimal.Decimal] = mapped_column(Numeric(10, 2)) area_id: Mapped[int] = mapped_column(ForeignKey(TABLE_PREFIX + "area.id")) - area: Mapped["Area"] = relationship("Area") + area: Mapped["Area"] = relationship("Area", back_populates="products") + + image_path: Mapped[str] = mapped_column(nullable=True) TransactionTypes = typing.Literal[ diff --git a/src/allmende_payment_system/static/img/placeholder.jpg b/src/allmende_payment_system/static/img/placeholder.jpg new file mode 100644 index 0000000000000000000000000000000000000000..9602b3d3aa4c8c8dc4b0700cc72bc36a2d27e97c GIT binary patch literal 5924 zcmeHL3p7;w8voCXcS_@(=NLLC!aR^z9(6s-`!$N@W~b^!u z6iNxzsT74Hl}AKzk~~sTBd_NEH+r3W?po)b`&f6a>$CRu`~Sc1`|WT4_P5sF-|#wl zPr%B}mYXaA3IzZP{sCT}0M3HV@B?7eCJi7201yGo02-bFh=m702_s>k0fC=k@kNaI zLl`tSljeSHml*DJUr`@gNBbrV0uOt`HJhp(Kfw zRQjil_cOo>fqh^f289P`EDD1~@#=sA(gI$5PL=-jmXO1rw!F&^{1;NQC>cSj6## z2Zcqe@VbB~2G)VaV1X%^O8{<{2rjn!{%SqbT~&AZa?Sp4{v^crrsVu15C?pfXPbBAJz6cRHpC=p$4Aq13>g$ zXhy!Yxq)r#vM-qxW3HrLNRu{6D$Fl0GxM*YkVVq!a`ZPpb@LV}m`#?*=v=PrZLeV} za%eIKx2MuSI=XcFI1hAw2D{o^H`>@wCuE$AmA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f}wc;#2`PjemKWDhK} z<-7^F-{g4PQ=+7L$T=tdl>E!_v7}x>qxXgZFK+1^=>Aobn9y~XvqlNvNrem}+Sk0`6;K5!CSdt=wA2`6#) z31`j$56zKEkruhP4!&=~b12c6!fAPW0U?NTxo3|@`|ur(9reVI{$9oLQ{3Z^OV*0T zct!v4T030LYFoFLx!Cr%7SxxGEoC{XZBlVp2`1OsS;IQbk+J-Tyq}~ec=xqEOJzMD zZs$m}a}>+RO>?-z{oFB5Pme#xtJKD|XyS~AgZtl69Cn=WG7mVn)@<$O^Y&Hg*)9^j zQG*{YtyFZ{cq)=BQ5O}LIXio#f3m7QxnE|>_cu2W#W|hS(__`H{iQfJ*J0DpAnAmh zJUzc9jB=o7Pf3SJNwX7`O8MHW=-?DL+dyWrfA9$)bJtm=kU TsS)l+{%qjK`}$pg;ywHu{`hlp literal 0 HcmV?d00001 diff --git a/src/allmende_payment_system/templates/area.html.jinja b/src/allmende_payment_system/templates/area.html.jinja new file mode 100644 index 0000000..b7ec129 --- /dev/null +++ b/src/allmende_payment_system/templates/area.html.jinja @@ -0,0 +1,36 @@ +{% extends "base.html.jinja" %} +{% block content %} + +
+

{{ area.name }}

+

{{ area.description or ''}}

+
+ + + +{% endblock %} diff --git a/src/allmende_payment_system/templates/shop.html.jinja b/src/allmende_payment_system/templates/shop.html.jinja index 71176ea..d2288cf 100644 --- a/src/allmende_payment_system/templates/shop.html.jinja +++ b/src/allmende_payment_system/templates/shop.html.jinja @@ -9,13 +9,13 @@