Skip to content

Commit

Permalink
Merge pull request #11 from energie360/feature/replace-id-with-pk
Browse files Browse the repository at this point in the history
Replace id lookup with pk
  • Loading branch information
andre-dasilva authored Dec 12, 2024
2 parents d982af1 + d242eb8 commit b5d4671
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions djangocms_xliff/cms_toolbars.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ def update_language_menu(self, obj):
if not language_menu:
return None

content_type_id = ContentType.objects.get_for_model(obj.__class__).id
content_type_id = ContentType.objects.get_for_model(obj.__class__).pk
reverse_xliff = partial(
reverse,
kwargs={
"content_type_id": content_type_id,
"obj_id": obj.id,
"obj_id": obj.pk,
"current_language": self.current_lang,
},
)
Expand Down
2 changes: 1 addition & 1 deletion djangocms_xliff/exports.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def convert_obj_to_xliff_context(obj: XliffObj, source_language: str, target_lan
source_language=source_language,
target_language=target_language,
content_type_id=content_type_id,
obj_id=obj.id,
obj_id=obj.pk,
path=get_path(obj=obj, language=target_language),
units=extract_units_from_obj(obj, target_language),
)
Expand Down
2 changes: 1 addition & 1 deletion djangocms_xliff/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def save_xliff_context(xliff_context: XliffContext) -> None:


def validate_page_with_xliff_context(obj: XliffObj, xliff_context: XliffContext, current_language: str):
obj_id = obj.id
obj_id = obj.pk
xliff_obj_id = xliff_context.obj_id
if obj_id != xliff_obj_id:
error_message = _('Selected page id: "%(obj_id)s" is not the same as xliff page id: "%(xliff_obj_id)s"')
Expand Down
2 changes: 1 addition & 1 deletion djangocms_xliff/management/commands/xliff_page_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def handle(self, *args, **options):

self.stdout.write(
self.style.SUCCESS(
f"Found {len(units)} xliff units on page with id: {obj.id} and language: {current_language}"
f"Found {len(units)} xliff units on page with id: {obj.pk} and language: {current_language}"
)
)
self.stdout.write()
Expand Down
2 changes: 1 addition & 1 deletion djangocms_xliff/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def parse_tool_element(self) -> Tuple[int, int]:
# For backwards compatibility, if there are existing xliff files
# with just the page_id as the tool-id
obj_id = tool_element.attrib["tool-id"]
content_type_id = ContentType.objects.get_for_model(Page).id
content_type_id = ContentType.objects.get_for_model(Page).pk

return int(content_type_id), int(obj_id)

Expand Down
8 changes: 4 additions & 4 deletions djangocms_xliff/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ def get_metadata_fields_for_model(obj: XliffObj) -> Dict[str, str]:


def get_plugin_id_for_extension_obj(obj) -> str:
content_type_id = ContentType.objects.get_for_model(obj).id
return UNIT_ID_DELIMITER.join([UNIT_ID_EXTENSION_DATA_ID, str(content_type_id), str(obj.id)])
content_type_id = ContentType.objects.get_for_model(obj).pk
return UNIT_ID_DELIMITER.join([UNIT_ID_EXTENSION_DATA_ID, str(content_type_id), str(obj.pk)])


def get_plugin_id_for_metadata_obj(obj) -> str:
content_type_id = ContentType.objects.get_for_model(obj).id
return UNIT_ID_DELIMITER.join([UNIT_ID_METADATA_ID, str(content_type_id), str(obj.id)])
content_type_id = ContentType.objects.get_for_model(obj).pk
return UNIT_ID_DELIMITER.join([UNIT_ID_METADATA_ID, str(content_type_id), str(obj.pk)])
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def _create_xliff_page_context(units, source_language="de", target_language="fr"
return XliffContext(
source_language=source_language,
target_language=target_language,
content_type_id=ContentType.objects.get_for_model(Page).id,
content_type_id=ContentType.objects.get_for_model(Page).pk,
obj_id=obj_id,
path=path,
units=units,
Expand Down
6 changes: 3 additions & 3 deletions tests/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


def test_parse_xliff_version_1_2_simple(create_xliff_page_context):
content_type_id = ContentType.objects.get_for_model(Page).id
content_type_id = ContentType.objects.get_for_model(Page).pk
file_content = f"""<?xml version="1.0" encoding="utf-8" standalone="no"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
<file original="test" datatype="plaintext" source-language="en" target-language="de">
Expand Down Expand Up @@ -51,7 +51,7 @@ def test_parse_xliff_version_1_2_simple(create_xliff_page_context):


def test_parse_xliff_version_1_2_utf_8_characters(create_xliff_page_context):
content_type_id = ContentType.objects.get_for_model(Page).id
content_type_id = ContentType.objects.get_for_model(Page).pk
file_content = f"""<?xml version="1.0" encoding="utf-8" standalone="no"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
<file original="test/example" datatype="plaintext" source-language="de" target-language="fr">
Expand Down Expand Up @@ -112,7 +112,7 @@ def test_parse_xliff_version_1_2_utf_8_characters(create_xliff_page_context):


def test_parse_xliff_version_1_2_html(create_xliff_page_context):
content_type_id = ContentType.objects.get_for_model(Page).id
content_type_id = ContentType.objects.get_for_model(Page).pk
file_content = f"""<?xml version="1.0" encoding="utf-8" standalone="no"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
<file original="test/example" datatype="plaintext" source-language="de" target-language="fr">
Expand Down
2 changes: 1 addition & 1 deletion tests/test_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_create_xliff_version_1_2_simple(create_xliff_page_context):

xliff_context = create_xliff_page_context(units)

content_type_id = ContentType.objects.get_for_model(Page).id
content_type_id = ContentType.objects.get_for_model(Page).pk

expected = f"""<?xml version="1.0" encoding="utf-8" standalone="no"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
Expand Down

0 comments on commit b5d4671

Please sign in to comment.