Skip to content

Commit

Permalink
Provide option to only export public versions as XLIFF
Browse files Browse the repository at this point in the history
Fixes #1047
  • Loading branch information
timobrembeck committed Mar 10, 2022
1 parent dfefda0 commit 58627f6
Show file tree
Hide file tree
Showing 24 changed files with 406 additions and 79 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ UNRELEASED
----------

* [ [#1284](https://github.com/digitalfabrik/integreat-cms/issues/1284) ] Inherit status of new translations from source language on XLIFF import
* [ [#1047](https://github.com/digitalfabrik/integreat-cms/issues/1047) ] Provide option to only export public versions as XLIFF


2022.3.3
Expand Down
34 changes: 34 additions & 0 deletions integreat_cms/cms/fixtures/test_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,23 @@
"page": 3
}
},
{
"model": "cms.pagetranslation",
"pk": 76,
"fields": {
"title": "Über die App Integreat Augsburg",
"slug": "uber-die-app-integreat-augsburg",
"status": "DRAFT",
"content": "<p>Unver&ouml;ffentlicher Entwurf</p>",
"language": 1,
"currently_in_translation": false,
"version": 2,
"minor_edit": false,
"last_updated": "2019-08-13T08:05:45.631Z",
"creator": 1,
"page": 3
}
},
{
"model": "cms.pagetranslation",
"pk": 4,
Expand Down Expand Up @@ -606,6 +623,23 @@
"page": 3
}
},
{
"model": "cms.pagetranslation",
"pk": 77,
"fields": {
"title": "About the Integreat App Augsburg",
"slug": "about-the-integreat-app-augsburg",
"status": "DRAFT",
"content": "<p>Unpublished draft</p>",
"language": 2,
"currently_in_translation": false,
"version": 2,
"minor_edit": false,
"last_updated": "2019-08-13T08:05:45.631Z",
"creator": 1,
"page": 3
}
},
{
"model": "cms.pagetranslation",
"pk": 9,
Expand Down
16 changes: 16 additions & 0 deletions integreat_cms/cms/models/abstract_content_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from ..utils.translation_utils import ugettext_many_lazy as __


# pylint: disable=too-many-public-methods
class AbstractContentTranslation(AbstractBaseModel):
"""
Data model representing a translation of some kind of content (e.g. pages or events)
Expand Down Expand Up @@ -267,6 +268,21 @@ def source_translation(self):
return self.foreign_object.get_translation(self.source_language.slug)
return None

@cached_property
def public_source_translation(self):
"""
This property returns the public translation which was used to create the ``self`` translation.
It derives this information from the :class:`~integreat_cms.cms.models.regions.region.Region`'s root
:class:`~integreat_cms.cms.models.languages.language_tree_node.LanguageTreeNode`.
:return: The content translation in the source :class:`~integreat_cms.cms.models.languages.language.Language`
(:obj:`None` if no public source translation exists)
:rtype: ~integreat_cms.cms.models.abstract_content_translation.AbstractContentTranslation
"""
if self.source_language:
return self.foreign_object.get_public_translation(self.source_language.slug)
return None

@cached_property
def major_public_source_translation(self):
"""
Expand Down
21 changes: 14 additions & 7 deletions integreat_cms/cms/templates/pages/page_tree.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,23 @@ <h1 class="heading">{% trans 'Page Tree' %} <button data-show-tutorial="page-tre
{% trans 'Export published pages as PDF' %}
</option>
{% if request.user.expert_mode %}
<option
{% with language_translated_name=language.translated_name %}
{% if language == request.region.default_language %}
disabled
title="{% trans 'You cannot export XLIFF files for the default language' %}"
<option disabled title="{% trans 'You cannot export XLIFF files for the default language' %}">
{% blocktrans %}Export pages (including drafts) for translation to {{ language_translated_name }} as XLIFF{% endblocktrans %}
</option>
<option disabled title="{% trans 'You cannot export XLIFF files for the default language' %}">
{% blocktrans %}Export published pages for translation to {{ language_translated_name }} as XLIFF{% endblocktrans %}
</option>
{% else %}
data-bulk-action="{% url 'download_xliff' region_slug=request.region.slug language_slug=language.slug %}"
<option data-bulk-action="{% url 'download_xliff' region_slug=request.region.slug language_slug=language.slug %}">
{% blocktrans %}Export pages (including drafts) for translation to {{ language_translated_name }} as XLIFF{% endblocktrans %}
</option>
<option data-bulk-action="{% url 'download_xliff_only_public' region_slug=request.region.slug language_slug=language.slug %}">
{% blocktrans %}Export published pages for translation to {{ language_translated_name }} as XLIFF{% endblocktrans %}
</option>
{% endif %}
>
{% trans 'Export XLIFF for translation to' %} {{ language.translated_name }}
</option>
{% endwith %}
{% endif %}
</select>
<button id="bulk-action-execute" class="btn">{% trans 'Execute' %}</button>
Expand Down
6 changes: 6 additions & 0 deletions integreat_cms/cms/urls/protected.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,12 @@
pages.download_xliff,
name="download_xliff",
),
path(
"only-public/",
pages.download_xliff,
{"only_public": True},
name="download_xliff_only_public",
),
path(
"upload/",
pages.upload_xliff,
Expand Down
9 changes: 7 additions & 2 deletions integreat_cms/cms/views/pages/page_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def expand_page_translation_id(request, short_url_id):


@permission_required("cms.view_page")
def download_xliff(request, region_slug, language_slug):
def download_xliff(request, region_slug, language_slug, only_public=False):
"""
Download a zip file of XLIFF files.
The target languages and pages are selected and the source languages automatically determined.
Expand All @@ -299,6 +299,9 @@ def download_xliff(request, region_slug, language_slug):
:param language_slug: The slug of the target language
:type language_slug: str
:param only_public: Whether only public versions should be exported
:type only_public: bool
:return: A redirection to the :class:`~integreat_cms.cms.views.pages.page_tree_view.PageTreeView`
:rtype: ~django.http.HttpResponseRedirect
"""
Expand Down Expand Up @@ -327,7 +330,9 @@ def download_xliff(request, region_slug, language_slug):
parent__isnull=False,
).language

xliff_file_url = pages_to_xliff_file(request, pages, target_language)
xliff_file_url = pages_to_xliff_file(
request, pages, target_language, only_public=only_public
)
if xliff_file_url:
# Insert link with automatic download into success message
messages.success(
Expand Down

0 comments on commit 58627f6

Please sign in to comment.