Skip to content
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
8 changes: 4 additions & 4 deletions integreat_cms/cms/forms/custom_content_model_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,22 +119,22 @@ def clean_slug(self) -> str:
self.data["slug"] = unique_slug
return unique_slug

def save(self, commit: bool = True, foreign_form_changed: bool = False) -> Any:
def save(self, commit: bool = True) -> Any:
"""
This method extends the default ``save()``-method of the base :class:`~django.forms.ModelForm` to set attributes
which are not directly determined by input fields.

:param commit: Whether or not the changes should be written to the database
:param foreign_form_changed: Whether or not the foreign form of this translation form was changed
:return: The saved content translation object
"""

if commit:
# Delete now outdated link objects
self.instance.links.all().delete()

# If none of the text content fields were changed, but the foreign form was, treat as minor edit (even if checkbox isn't clicked)
if {"title", "content"}.isdisjoint(self.changed_data) and foreign_form_changed:
Comment thread
seluianova marked this conversation as resolved.
# If none of the text content fields were changed, treat as minor edit (even if checkbox isn't clicked)
# so that existing translations in other languages are not incorrectly flagged as outdated
if {"title", "content"}.isdisjoint(self.changed_data):
self.logger.debug("Set 'minor_edit=True' since the content did not change")
self.instance.minor_edit = True

Expand Down
10 changes: 1 addition & 9 deletions integreat_cms/cms/forms/machine_translation_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,22 +139,14 @@ def clean(self) -> dict[str, Any]:
def save(
self,
commit: bool = True,
foreign_form_changed: bool = False,
) -> EventTranslation | (PageTranslation | POITranslation):
"""
Create machine translations and save them to the database

:param commit: Whether or not the changes should be written to the database
:param foreign_form_changed: Whether or not the foreign form of this translation form was changed
:return: The saved content translation object
"""
# If no text content changed, mark the source translation as minor edit so that
# existing translations in other languages are not incorrectly flagged as outdated
if {"title", "content"}.isdisjoint(self.changed_data):
self.instance.minor_edit = True
self.instance: EventTranslation | PageTranslation | POITranslation = (
super().save(commit, foreign_form_changed)
)
self.instance = super().save(commit)

language_nodes = self.cleaned_data["mt_translations_to_create"].union(
self.cleaned_data["mt_translations_to_update"],
Expand Down
7 changes: 3 additions & 4 deletions integreat_cms/cms/models/abstract_content_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,8 @@ def translation_state(self) -> str:

:return: A string describing the state of the translation, one of :data:`~integreat_cms.cms.constants.translation_status.CHOICES`
"""
if not (translation := self.major_version):
translation = self.latest_public_or_draft_version or self.major_version
if not translation:
# If the page does not have a major public version, it is considered "missing" (keep in mind that it might
# have draft versions or public versions that are marked as "minor edit")
return translation_status.MISSING
Expand All @@ -490,16 +491,14 @@ def translation_state(self) -> str:
if not self.source_language:
# If the language of this translation is the root of this region's language tree, it is always "up to date"
return translation_status.UP_TO_DATE

latest_translation = self.latest_public_or_draft_version or translation
if (
# If the source language does not have a major public version, the translation is considered "outdated",
# because the content is not in sync with its source translation
not (source_translation := self.major_source_translation)
# If the source translation is already outdated, this translation is as well
or source_translation.translation_state == translation_status.OUTDATED
# If the translation was edited before the last major change in the source language, it is outdated
or latest_translation.last_updated <= source_translation.last_updated
or translation.last_updated <= source_translation.last_updated
):
return translation_status.OUTDATED
if translation.machine_translated:
Expand Down
6 changes: 1 addition & 5 deletions integreat_cms/cms/views/events/event_form_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,7 @@ def post(self, request: HttpRequest, **kwargs: Any) -> HttpResponse:
request, event_form, recurrence_rule_form
)
):
event_translation_instance = event_translation_form.save(
foreign_form_changed=(
event_form.has_changed() or recurrence_rule_form.has_changed()
),
)
event_translation_form.save()

self.update_recurrence_rule(event_form, recurrence_rule_form)

Expand Down
4 changes: 1 addition & 3 deletions integreat_cms/cms/views/pages/page_form_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,7 @@ def post(
if self.validate_and_save_page(
request, page_form
) and self.validate_page_translation(request, page_translation_form):
page_translation_instance = page_translation_form.save(
foreign_form_changed=page_form.has_changed(),
)
page_translation_form.save()

if page_translation_form.instance.status == status.DRAFT:
self.set_dependent_translations_to_draft(
Expand Down
4 changes: 1 addition & 3 deletions integreat_cms/cms/views/pois/poi_form_ajax_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ def post(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponse:
website = poi_form.data.get("primary_website")

poi_translation_form.instance.poi = poi
poi_translation = poi_translation_form.save(
foreign_form_changed=poi_form.has_changed(),
)
poi_translation = poi_translation_form.save()

generate_primary_contact_from_poi(
website,
Expand Down
4 changes: 1 addition & 3 deletions integreat_cms/cms/views/pois/poi_form_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,7 @@ def post(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponse:
)
):
poi_translation_form.instance.poi = poi_form.instance
poi_translation_instance = poi_translation_form.save(
foreign_form_changed=poi_form.has_changed(),
)
poi_translation_form.save()

generate_primary_contact_from_poi(
website,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,6 @@ def handle(
)
# Save forms
poi_translation_form.instance.poi = poi_form.save()
poi_translation_form.save(foreign_form_changed=poi_form.has_changed())
poi_translation_form.save()
logger.success("Imported %r", poi_form.instance) # type: ignore[attr-defined]
logger.success("✔ Imported CSV file %s", csv_filename) # type: ignore[attr-defined]
2 changes: 2 additions & 0 deletions integreat_cms/release_notes/current/unreleased/4397.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
en: Show UP_TO_DATE translation status when a translation is manually updated without changes
de: Zeige den Übersetzungsstatus UP_TO_DATE an, wenn eine Übersetzung manuell ohne Änderungen aktualisiert wird
Loading