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 14, 2022
1 parent 89aed50 commit 9db3d36
Show file tree
Hide file tree
Showing 25 changed files with 411 additions and 82 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ UNRELEASED

* [ [#1108](https://github.com/digitalfabrik/integreat-cms/issues/1108) ] Support SVG images in PDF export
* [ [#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
20 changes: 13 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,22 @@ <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 %}
{% blocktrans asvar xliff_export_all %}Export all pages for {{ language_translated_name }} translation{% endblocktrans %}
{% blocktrans asvar xliff_export_public %}Export only published pages for {{ language_translated_name }} translation{% endblocktrans %}
{% if language == request.region.default_language %}
disabled
title="{% trans 'You cannot export XLIFF files for the default language' %}"
{% blocktrans asvar xliff_export_disabled %}You cannot export XLIFF files for the default language{% endblocktrans %}
<option disabled title="{{ xliff_export_disabled }}">{{ xliff_export_all }} ({{ XLIFF_EXPORT_VERSION|upper }})</option>
<option disabled title="{{ xliff_export_disabled }}">{{ xliff_export_public }} ({{ XLIFF_EXPORT_VERSION|upper }})</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 %}">
{{ xliff_export_all }} ({{ XLIFF_EXPORT_VERSION|upper }})
</option>
<option data-bulk-action="{% url 'download_xliff_only_public' region_slug=request.region.slug language_slug=language.slug %}">
{{ xliff_export_public }} ({{ XLIFF_EXPORT_VERSION|upper }})
</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
2 changes: 2 additions & 0 deletions integreat_cms/cms/views/pages/page_tree_view.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging

from django.conf import settings
from django.contrib import messages
from django.shortcuts import render, redirect
from django.utils.decorators import method_decorator
Expand Down Expand Up @@ -116,6 +117,7 @@ def get(self, request, *args, **kwargs):
"language": language,
"languages": region.active_languages,
"filter_form": filter_form,
"XLIFF_EXPORT_VERSION": settings.XLIFF_EXPORT_VERSION,
},
)
# Disable browser cache of page tree to prevent subpages from being expanded after using "back"-button
Expand Down

0 comments on commit 9db3d36

Please sign in to comment.