@@ -109,9 +109,45 @@
Loading
109 109
        return serializer.to_representation(page.get_ancestors())
110 110
111 111
112 +
class PageTranslationsField(Field):
113 +
    """
114 +
    Serializes the page's translations.
115 +
116 +
    Example:
117 +
    "translations": [
118 +
        {
119 +
            "id": 1,
120 +
            "meta": {
121 +
                "type": "home.HomePage",
122 +
                "detail_url": "/api/v1/pages/1/",
123 +
                "locale": "es"
124 +
            },
125 +
            "title": "Casa"
126 +
        },
127 +
        {
128 +
            "id": 2,
129 +
            "meta": {
130 +
                "type": "home.HomePage",
131 +
                "detail_url": "/api/v1/pages/2/",
132 +
                "locale": "fr"
133 +
            },
134 +
            "title": "Maison"
135 +
        }
136 +
    ]
137 +
    """
138 +
    def get_attribute(self, instance):
139 +
        return instance
140 +
141 +
    def to_representation(self, page):
142 +
        serializer_class = get_serializer_class(Page, ['id', 'type', 'detail_url', 'html_url', 'locale', 'title', 'admin_display_title'], meta_fields=['type', 'detail_url', 'html_url', 'locale'], base=AdminPageSerializer)
143 +
        serializer = serializer_class(context=self.context, many=True)
144 +
        return serializer.to_representation(page.get_translations())
145 +
146 +
112 147
class AdminPageSerializer(PageSerializer):
113 148
    status = PageStatusField(read_only=True)
114 149
    children = PageChildrenField(read_only=True)
115 150
    descendants = PageDescendantsField(read_only=True)
116 151
    ancestors = PageAncestorsField(read_only=True)
152 +
    translations = PageTranslationsField(read_only=True)
117 153
    admin_display_title = ReadOnlyField(source='get_admin_display_title')

@@ -1,5 +1,6 @@
Loading
1 1
from collections import OrderedDict
2 2
3 +
from django.conf import settings
3 4
from rest_framework.authentication import SessionAuthentication
4 5
5 6
from wagtail.api.v2.views import PagesAPIViewSet
@@ -26,6 +27,7 @@
Loading
26 27
        'descendants',
27 28
        'parent',
28 29
        'ancestors',
30 +
        'translations',
29 31
    ]
30 32
31 33
    body_fields = PagesAPIViewSet.body_fields + [
@@ -47,6 +49,16 @@
Loading
47 49
        'has_children'
48 50
    ])
49 51
52 +
    @classmethod
53 +
    def get_detail_default_fields(cls, model):
54 +
        detail_default_fields = super().get_detail_default_fields(model)
55 +
56 +
        # When i18n is disabled, remove "translations" from default fields
57 +
        if not getattr(settings, 'WAGTAIL_I18N_ENABLED', False):
58 +
            detail_default_fields.remove('translations')
59 +
60 +
        return detail_default_fields
61 +
50 62
    def get_root_page(self):
51 63
        """
52 64
        Returns the page that is used when the `&child_of=root` filter is used.
Files Coverage
wagtail 90.50%
Project Totals (386 files) 90.50%
15371.15
TRAVIS_PYTHON_VERSION=3.8
TRAVIS_OS_NAME=linux
TOXENV=py38-dj22-postgres-elasticsearch7
backend
15371.13
TRAVIS_PYTHON_VERSION=3.6
TRAVIS_OS_NAME=linux
TOXENV=py36-dj22-postgres-elasticsearch5
backend
15371.17
TRAVIS_PYTHON_VERSION=3.8
TRAVIS_OS_NAME=linux
TOXENV=py38-dj31-postgres-elasticsearch7
backend
15371.11
TRAVIS_PYTHON_VERSION=3.8
TRAVIS_OS_NAME=linux
TOXENV=py38-djmaster-postgres-noelasticsearch
backend
15371.18
TRAVIS_PYTHON_VERSION=3.8
TRAVIS_OS_NAME=linux
TOXENV=py38-dj31-postgres-elasticsearch7-emailuser
backend
15371.3
TRAVIS_PYTHON_VERSION=3.7
TRAVIS_OS_NAME=linux
TOXENV=py37-dj22-sqlite-noelasticsearch
backend
15371.4
TRAVIS_PYTHON_VERSION=3.7
TRAVIS_OS_NAME=linux
TOXENV=py37-dj30-sqlite-noelasticsearch
backend
15371.1
TRAVIS_PYTHON_VERSION=3.6
TRAVIS_OS_NAME=linux
TOXENV=py36-dj22-mysql-noelasticsearch
backend
15371.2
TRAVIS_PYTHON_VERSION=3.6
TRAVIS_OS_NAME=linux
TOXENV=py36-dj22-postgres-noelasticsearch
backend
15371.7
TRAVIS_PYTHON_VERSION=3.8
TRAVIS_OS_NAME=linux
TOXENV=py38-dj31-postgres-noelasticsearch
backend
15371.5
TRAVIS_PYTHON_VERSION=3.7
TRAVIS_OS_NAME=linux
TOXENV=py37-dj30-mysql-noelasticsearch
backend
15371.8
TRAVIS_PYTHON_VERSION=3.8
TRAVIS_OS_NAME=linux
TOXENV=py38-dj31-postgres-noelasticsearch-emailuser
backend
15371.10
TRAVIS_PYTHON_VERSION=3.8
TRAVIS_OS_NAME=linux
TOXENV=py38-dj31stable-postgres-noelasticsearch
backend
15371.14
TRAVIS_PYTHON_VERSION=3.7
TRAVIS_OS_NAME=linux
TOXENV=py37-dj22-postgres-elasticsearch6
backend
15371.12
TRAVIS_PYTHON_VERSION=3.6
TRAVIS_OS_NAME=linux
TOXENV=py36-dj22-sqlite-elasticsearch2
backend
1
codecov:
2
  notify:
3
    after_n_builds: 10
4
    require_ci_to_pass: no
5

6
coverage:
7
  status:
8
    project: off
9
    patch: off
10

11
comment: off
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading