Skip to content

Commit

Permalink
Update metadata import for cms pages
Browse files Browse the repository at this point in the history
  • Loading branch information
andre-dasilva committed Apr 4, 2024
1 parent c8a3848 commit c69080c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
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)

0 comments on commit c69080c

Please sign in to comment.