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

Update metadata import for cms pages #10

Merged
merged 3 commits into from
Apr 8, 2024
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
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": "always",
"source.organizeImports": "always"
},
},
}
2 changes: 1 addition & 1 deletion djangocms_xliff/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def save_xliff_units_for_metadata(units: List[Unit], target_language: str, lazy_
obj = lazy_xliff_obj()

if type(obj) == Page:
obj = obj.get_title_obj()
obj = obj.get_title_obj(language=target_language)

target = unit.target
setattr(obj, field_name, target)
Expand Down
29 changes: 26 additions & 3 deletions djangocms_xliff/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
from dataclasses import asdict
from typing import Type

from django.contrib.admin import site
from cms.admin.pageadmin import PageAdmin
from cms.models import Page
from django.contrib import admin
from django.contrib.admin.views.decorators import staff_member_required
from django.forms import Form
from django.http import HttpResponse
Expand Down Expand Up @@ -171,7 +173,28 @@ def post(self, request, content_type_id: int, obj_id: int, *args, **kwargs):

# Determine the HttpResponse for the change_view stage.
obj = get_obj(content_type_id, obj_id)
admin = site._registry[obj._meta.model]
return admin.response_change(request, obj)

if type(obj) == Page:
title_obj = obj.get_title_obj(xliff_context.target_language)
page_metadata = {
"language": xliff_context.target_language,
"title": title_obj.title,
"slug": title_obj.slug,
"menu_title": title_obj.menu_title,
"page_title": title_obj.page_title,
"meta_description": title_obj.meta_description,
"_save": "save",
}
updated_request_post = request.POST.copy()
updated_request_post.pop("xliff_json", None)
updated_request_post.update(page_metadata)

request.POST = updated_request_post

page_admin = PageAdmin(Page, admin.site)
return page_admin.change_view(request, str(obj.pk))

model_admin = admin.site._registry[obj._meta.model]
return model_admin.response_change(request, obj)
except XliffError as e:
return self.error_response(e)
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ line-length = 120
exclude_dirs = ["tests"]
skips = ["B101", "B405"]

[tool.isort]
profile = "black"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ deps =
dj42: Django>=4.2,<5.0
cms39: django-cms>=3.9,<3.10
cms310: django-cms>=3.10,<3.11
cms311: django-cms>=3.11
cms311: django-cms>=3.11,<4.0
commands =
pytest .

Expand Down
Loading