Repository: digitalfabrik/integreat-cms

Issue:
Pages API not working
### Describe the Bug
We run into an error, when we call any of the pages API (see screenshot).

This is probably broken since the adding of the page mirroring feature.


### Additional Information
![grafik](https://user-images.githubusercontent.com/15608678/109014324-522ffe80-76b4-11eb-8e33-dee02bf6a250.png)




Discussion:

Resolving patch:
diff --git a/src/cms/models/pages/page.py b/src/cms/models/pages/page.py
--- a/src/cms/models/pages/page.py
+++ b/src/cms/models/pages/page.py
@@ -152,7 +152,7 @@ def get_siblings(self, include_self=False):
             super().get_siblings(include_self=include_self).filter(region=self.region)
         )
 
-    def get_mirrored_page(self, language_code):
+    def get_mirrored_page_translation(self, language_code):
         """
         Mirrored content always includes the live content from another page. This content needs to be added when
         delivering content to end users.
diff --git a/src/cms/models/pages/page_translation.py b/src/cms/models/pages/page_translation.py
--- a/src/cms/models/pages/page_translation.py
+++ b/src/cms/models/pages/page_translation.py
@@ -109,12 +109,14 @@ def combined_text(self):
         :return: The combined content of this page and the mirrored page
         :rtype: str
         """
-        attached_text = self.page.get_mirrored_page(self.language.code).text
-        if attached_text is None:
+        mirrored_page_translation = self.page.get_mirrored_page_translation(
+            self.language.code
+        )
+        if not mirrored_page_translation or not mirrored_page_translation.text:
             return self.text
         if self.page.mirrored_page_first:
-            return attached_text + self.text
-        return self.text + attached_text
+            return mirrored_page_translation.text + self.text
+        return self.text + mirrored_page_translation.text
 
     @property
     def combined_last_updated(self):
@@ -126,8 +128,15 @@ def combined_last_updated(self):
         :return: The last_updated date of this or the mirrored page translation
         :rtype: ~datetime.datetime
         """
-        if self.page.get_mirrored_page and not self.text:
-            return self.page.get_mirrored_page(self.language.code).last_updated
+        mirrored_page_translation = self.page.get_mirrored_page_translation(
+            self.language.code
+        )
+        if (
+            not self.text
+            and mirrored_page_translation
+            and mirrored_page_translation.text
+        ):
+            return mirrored_page_translation.last_updated
         return self.last_updated
 
     @classmethod
diff --git a/src/cms/views/pages/page_actions.py b/src/cms/views/pages/page_actions.py
--- a/src/cms/views/pages/page_actions.py
+++ b/src/cms/views/pages/page_actions.py
@@ -161,7 +161,7 @@ def view_page(request, page_id, region_slug, language_code):
     template_name = "pages/page_view.html"
 
     page_translation = page.get_translation(language_code)
-    mirrored_translation = page.get_mirrored_page(language_code)
+    mirrored_translation = page.get_mirrored_page_translation(language_code)
 
     return render(
         request,


Test patch: