Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions backend/src/cms_backend/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from uuid import UUID

import pycountry

Expand All @@ -24,4 +25,16 @@ def update_language_codes():
pycountry.languages.add_entry(alpha_3=code) # pyright: ignore[reportUnknownMemberType]


def construct_recipe_link(recipe_id: UUID | None) -> str | None:
if recipe_id is None:
return None
return f"{Context.zimfarm_url}/recipes/{recipe_id}"


def construct_recipe_api_link(recipe_id: UUID | None) -> str | None:
if recipe_id is None:
return None
return f"{Context.zimfarm_api_url}/recipes/{recipe_id}"


update_language_codes()
4 changes: 4 additions & 0 deletions backend/src/cms_backend/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ class Context:
_validate_regex(os.getenv("ZIMCHECK_SCRAPERS_WHITELIST_REGEX"))
)

zimfarm_url: str = field(
default=os.getenv("ZIMFARM_URL", "https://farm.openzim.org")
)

zimfarm_api_url: str = field(
default=os.getenv("ZIMFARM_API_URL", "https://api.farm.openzim.org/v2")
)
8 changes: 1 addition & 7 deletions backend/src/cms_backend/db/book_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from sqlalchemy.orm import Session as OrmSession

from cms_backend.context import Context
from cms_backend import construct_recipe_link
from cms_backend.db.book import (
book_has_flavour_mismatch,
book_has_recipe_issue,
Expand Down Expand Up @@ -40,12 +40,6 @@
)


def construct_recipe_link(recipe_id: UUID | None) -> str | None:
if recipe_id is None:
return None
return f"{Context.zimfarm_api_url}/recipes/{recipe_id}"


def get_book_promotion_actions(
session: OrmSession, *, book_id: UUID
) -> list[BookPromotionAction]:
Expand Down
15 changes: 8 additions & 7 deletions backend/src/cms_backend/schemas/orms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from pydantic import Field, computed_field

from cms_backend.context import Context
from cms_backend import construct_recipe_api_link, construct_recipe_link
from cms_backend.schemas import BaseModel
from cms_backend.schemas.fields import NotEmptyString

Expand All @@ -24,9 +24,12 @@ class TitleFlavourSchema(BaseModel):
@computed_field
@property
def recipe_link(self) -> str | None:
if self.recipe_id is None:
return None
return f"{Context.zimfarm_api_url}/recipes/{self.recipe_id}"
return construct_recipe_link(self.recipe_id)

@computed_field
@property
def recipe_api_link(self) -> str | None:
return construct_recipe_api_link(self.recipe_id)


class TitleLightSchema(BaseModel):
Expand Down Expand Up @@ -181,9 +184,7 @@ class BookFullSchema(BookLightSchema):
@computed_field
@property
def recipe_link(self) -> str | None:
if self.recipe_id is None:
return None
return f"{Context.zimfarm_api_url}/recipes/{self.recipe_id}"
return construct_recipe_link(self.recipe_id)


class BookHistorySchema(BaseModel):
Expand Down
1 change: 1 addition & 0 deletions frontend/src/types/title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface TitleFlavour {
flavour: string
recipe_id: string | null
recipe_link: string | null
recipe_api_link: string | null
}

export interface TitleLight {
Expand Down