Repository: digitalfabrik/integreat-cms

Issue:
XLIFF import after page deletion
### Describe the Bug
<!-- A clear and concise description of what the bug is. -->
When the user imports XLIFF file to non existing page, nothing happens.

### Steps to Reproduce

1. Select a page
2. export it as XLIFF
3. delete the page
4. import the XLIFF again

### Expected Behavior
<!-- A clear and concise description of what you expected to happen. -->
The user should be notified, that he tries to add a translation for a page that does not exist.

### Actual Behavior
<!-- A clear and concise description of what actually happened. -->
Nothing shows up

### Additional Information
<!-- Add any other context (e.g. logs, screenshots, etc.) about the problem here. -->
When a bundle of XLIFFs is imported, only these with existing pages should actually be imported, for all others there should be a notification: "Action not possible". 




Discussion:

Resolving patch:
diff --git a/src/cms/page_xliff_converter.py b/src/cms/page_xliff_converter.py
--- a/src/cms/page_xliff_converter.py
+++ b/src/cms/page_xliff_converter.py
@@ -479,10 +479,10 @@ def generate_xliff_import_diff(self, xliff_paths):
         :param xliff_paths: list of paths to XLIFF files
         :type xliff_paths: [ str ]
 
-        :return: dictionaries containing diffs between XLIFF and current translation versions
+        :return: dictionaries containing diffs between XLIFF and current translation versions or an error message
         :rtype: list [ dict ]
         """
-        diffs = []
+        results = []
         for xliff_path in xliff_paths:
             if xliff_path.endswith((".xlf", ".xliff")) and os.path.isfile(xliff_path):
                 with open(xliff_path, "r", encoding="utf-8") as f:
@@ -491,12 +491,21 @@ def generate_xliff_import_diff(self, xliff_paths):
                     trans_fields = converter.xliff_to_translation_data()
                     if trans_fields is None:
                         continue
-                    diffs.append(
-                        self.generate_translation_diff(
-                            trans_fields, os.path.basename(xliff_path)
-                        )
+                    diff = self.generate_translation_diff(
+                        trans_fields, os.path.basename(xliff_path)
                     )
-        return diffs
+                    if diff is None:
+                        results.append(
+                            {
+                                "error": True,
+                                "page_id": trans_fields["page_id"],
+                                "title": trans_fields["title"],
+                                "tgt_lang_code": trans_fields["tgt_lang_code"],
+                            }
+                        )
+                    else:
+                        results.append(diff)
+        return results
 
     @staticmethod
     def generate_translation_diff(trans_fields, xliff_name):
@@ -515,7 +524,7 @@ def generate_translation_diff(trans_fields, xliff_name):
         page = Page.objects.filter(id=int(trans_fields["page_id"])).first()
         tgt_lang = Language.objects.filter(code=trans_fields["tgt_lang_code"]).first()
         if tgt_lang is None or page is None:
-            return False
+            return None
         tgt_trans = PageTranslation.objects.filter(page=page, language=tgt_lang).first()
         if tgt_trans is None:
             tgt_trans = PageTranslation()


Test patch: