Skip to content

Commit

Permalink
Merge pull request #139 from ecmwf-projects/copds-2231-hidden-contents
Browse files Browse the repository at this point in the history
catalogue manager stores a boolean flag to hide contents
  • Loading branch information
alex75 authored Dec 17, 2024
2 parents 9caff54 + bfbb0e1 commit a524de8
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 2 deletions.
29 changes: 29 additions & 0 deletions alembic/versions/6ac5a2abf5f5_hidden_contents_bool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""add boolean flag to hidden contents.
Revision ID: 6ac5a2abf5f5
Revises: e5875ac4a047
Create Date: 2024-12-17 10:26:33.649562
"""

import sqlalchemy as sa

import alembic

# revision identifiers, used by Alembic.
revision = "6ac5a2abf5f5"
down_revision = "e5875ac4a047"
branch_labels = None
depends_on = None


def upgrade() -> None:
alembic.op.add_column(
"contents", sa.Column("hidden", sa.Boolean, default=True, nullable=True)
)
alembic.op.execute("UPDATE contents SET hidden = FALSE")
alembic.op.alter_column("contents", "hidden", nullable=False)


def downgrade() -> None:
alembic.op.drop_column("contents", "hidden")
1 change: 1 addition & 0 deletions cads_catalogue/contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def load_content_folder(
"link": data.get("link"),
"keywords": data.get("keywords", []),
"data": data.get("data"),
"hidden": data.get("hidden", False),
# managed below:
# "image": None,
# "layout": None,
Expand Down
1 change: 1 addition & 0 deletions cads_catalogue/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class Content(BaseModel):
content_update = sa.Column(sa.TIMESTAMP, nullable=False)
data = sa.Column(dialect_postgresql.JSONB)
description = sa.Column(sa.String, nullable=False)
hidden = sa.Column(sa.Boolean, default=False, nullable=False)
image = sa.Column(sa.String)
layout = sa.Column(sa.String)
link = sa.Column(sa.String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"site": ["ads"],
"publication_date": "2024-09-13T10:01:50Z",
"update_date": "2024-09-16T02:10:22Z",
"layout": "./layout.json"
"layout": "./layout.json",
"hidden": false
}
3 changes: 2 additions & 1 deletion tests/data/cads-contents-json/how-to-api/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"site": ["cds", "ads"],
"publication_date": "2024-09-13T10:01:50Z",
"update_date": "2024-09-16T02:10:22Z",
"layout": "./layout.json"
"layout": "./layout.json",
"hidden": true
}
7 changes: 7 additions & 0 deletions tests/test_15_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def test_load_content_folder() -> None:
{
"slug": "copernicus-interactive-climates-atlas",
"publication_date": "2024-09-13T00:00:00Z",
"hidden": False,
"description": "The Copernicus Interactive Climate Atlas provides graphical "
"information about recent past trends and future changes "
"(for different scenarios and global warming levels)",
Expand Down Expand Up @@ -83,6 +84,7 @@ def test_load_content_folder() -> None:
{
"slug": "how-to-api-templated",
"publication_date": "2024-09-13T10:01:50Z",
"hidden": False,
"description": "Access 33 items of ADS Data Store catalogue, "
"with search and availability features",
"image": None,
Expand Down Expand Up @@ -110,6 +112,7 @@ def test_load_contents() -> None:
{
"slug": "copernicus-interactive-climates-atlas",
"publication_date": "2024-09-13T00:00:00Z",
"hidden": False,
"description": "The Copernicus Interactive Climate Atlas provides graphical "
"information about recent past trends and future changes "
"(for different scenarios and global warming levels)",
Expand Down Expand Up @@ -142,6 +145,7 @@ def test_load_contents() -> None:
{
"slug": "how-to-api",
"publication_date": "2024-09-13T10:01:50Z",
"hidden": True,
"description": "Access the full data store catalogue, "
"with search and availability features",
"image": None,
Expand All @@ -157,6 +161,7 @@ def test_load_contents() -> None:
{
"slug": "how-to-api",
"publication_date": "2024-09-13T10:01:50Z",
"hidden": True,
"description": "Access the full data store catalogue, "
"with search and availability features",
"image": None,
Expand All @@ -172,6 +177,7 @@ def test_load_contents() -> None:
{
"slug": "how-to-api-templated",
"publication_date": "2024-09-13T10:01:50Z",
"hidden": False,
"description": "Access 33 items of ADS Data Store catalogue, "
"with search and availability features",
"image": None,
Expand Down Expand Up @@ -214,6 +220,7 @@ def test_content_sync(
content1 = {
"slug": "copernicus-interactive-climates-atlas",
"publication_date": "2024-09-13T00:00:00Z",
"hidden": True,
"description": "The Copernicus Interactive Climate Atlas provides graphical "
"information about recent past trends and future changes "
"(for different scenarios and global warming levels)",
Expand Down

0 comments on commit a524de8

Please sign in to comment.