Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add internationalized page creation when creation is forced. #2967

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
36 changes: 22 additions & 14 deletions invenio_app_rdm/fixtures/pages.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2022-2024 CERN.
# Copyright (C) 2025 University of Münster.
#
# Invenio App RDM is free software; you can redistribute it and/or modify
# it under the terms of the MIT License; see LICENSE file for more details.
@@ -12,6 +13,7 @@
from flask import current_app
from invenio_access.permissions import system_identity
from invenio_db import db
from invenio_i18n.proxies import current_i18n
from invenio_pages.proxies import current_pages_service
from invenio_pages.records.errors import PageNotFoundError
from invenio_rdm_records.fixtures.fixture import FixtureMixin
@@ -25,6 +27,7 @@ def __init__(self, search_paths, filename, pages_path, force=False):
super().__init__(search_paths, filename)
self._force = force
self._pages_path = pages_path
self._supported_languages = current_i18n.get_languages()

def load(self):
"""Load the static pages."""
@@ -34,27 +37,32 @@ def load(self):
super().load()
db.session.commit()

def page_data(self, page):
def page_data(self, page, lang):
"""Returns content of template."""
for path in self._pages_path:
filepath = path / page
filepath = Path(str(path / page) + "." + lang)

if not filepath.exists():
continue
filepath = path / page

if not filepath.exists():
continue

return Path(filepath).read_bytes().decode("utf8")

def create(self, entry):
"""Load a single page."""
url = entry["url"]
try:
current_pages_service.read_by_url(system_identity, url)
except PageNotFoundError:
data = {
"url": url,
"title": entry.get("title", ""),
"content": self.page_data(entry["template"]),
"description": entry.get("description", ""),
"template_name": current_app.config["PAGES_DEFAULT_TEMPLATE"],
}
current_pages_service.create(system_identity, data)
for lang in self._supported_languages:
try:
current_pages_service.read_by_url(system_identity, url, lang[0])
except PageNotFoundError:
data = {
"url": url,
"title": entry.get("title", ""),
"content": self.page_data(entry["template"], lang[0]),
"lang": lang[0],
"description": entry.get("description", ""),
"template_name": current_app.config["PAGES_DEFAULT_TEMPLATE"],
}
current_pages_service.create(system_identity, data)
Loading