Repository: digitalfabrik/integreat-cms

Issue:
Creating pages not possible
Due to a JavaScript error, it is currently not possible to submit the page form if the page is not yet existing.
Creating pages not possible
Due to a JavaScript error, it is currently not possible to submit the page form if the page is not yet existing.


Discussion:

Resolving patch:
diff --git a/backend/cms/models/page.py b/backend/cms/models/page.py
--- a/backend/cms/models/page.py
+++ b/backend/cms/models/page.py
@@ -39,7 +39,7 @@ class Page(MPTTModel):
     region = models.ForeignKey(Region, related_name='pages', on_delete=models.CASCADE)
     archived = models.BooleanField(default=False)
     mirrored_page = models.ForeignKey('self', null=True, blank=True, on_delete=models.PROTECT)
-    mirrored_page_first = models.BooleanField(default=True)
+    mirrored_page_first = models.BooleanField(default=True, null=True, blank=True)
     editors = models.ManyToManyField(settings.AUTH_USER_MODEL, related_name='editors', blank=True)
     publishers = models.ManyToManyField(settings.AUTH_USER_MODEL, related_name='publishers', blank=True)
     created_date = models.DateTimeField(default=timezone.now)
@@ -170,7 +170,7 @@ class PageTranslation(models.Model):
     )
     slug = models.SlugField(max_length=200, blank=True, allow_unicode=True)
     title = models.CharField(max_length=250)
-    text = models.TextField()
+    text = models.TextField(blank=True)
     status = models.CharField(max_length=6, choices=status.CHOICES, default=status.DRAFT)
     currently_in_translation = models.BooleanField(default=False)
     version = models.PositiveIntegerField(default=0)
diff --git a/backend/cms/views/pages/page.py b/backend/cms/views/pages/page.py
--- a/backend/cms/views/pages/page.py
+++ b/backend/cms/views/pages/page.py
@@ -533,6 +533,6 @@ def save_mirrored_page(request):
         page.mirrored_page = None
     else:
         page.mirrored_page = Page.objects.get(id=int(decoded_json['mirrored_page']))
-        page.mirrored_page_first = int(decoded_json['mirrored_page_first']) == 1
+        page.mirrored_page_first = decoded_json['mirrored_page_first'] == 'True'
     page.save()
     return JsonResponse({'code': True})
diff --git a/backend/cms/views/pages/page_form.py b/backend/cms/views/pages/page_form.py
--- a/backend/cms/views/pages/page_form.py
+++ b/backend/cms/views/pages/page_form.py
@@ -7,6 +7,7 @@
 from django.contrib.auth import get_user_model
 from django.contrib.auth.models import Permission
 from django.db.models import Q
+from django.utils.translation import ugettext as _
 
 from ..utils.slug_utils import generate_unique_slug
 from ...constants import position, status
@@ -59,10 +60,13 @@ class PageForm(forms.ModelForm):
     publishers = forms.ModelChoiceField(queryset=get_user_model().objects.all(), required=False)
     mirrored_page_region = forms.ModelChoiceField(queryset=Region.objects.all(), required=False)
     mirrored_page = MirrorPageField(queryset=Page.objects.all(), required=False)
-    mirrored_page_first = forms.TypedChoiceField(
-        coerce=lambda x: x == 'True',
-        choices=((False, 'False'), (True, 'True')),
-        widget=forms.RadioSelect)
+    TRUE_FALSE_CHOICES = (
+        (True, _('Embed mirrored page before this page')),
+        (False, _('Embed mirrored page after this page'))
+    )
+    mirrored_page_first = forms.ChoiceField(choices=TRUE_FALSE_CHOICES,
+                                            widget=forms.Select(),
+                                            required=False)
 
     class Meta:
         model = Page
@@ -116,10 +120,7 @@ def __init__(self, *args, **kwargs):
             self.fields['parent'].initial = self.instance.parent
 
         self.mirrored_page = forms.ModelChoiceField(queryset=Page.objects.all(), required=False)
-        self.mirrored_page_first = forms.TypedChoiceField(
-            coerce=lambda x: x == 'True',
-            choices=((False, 'False'), (True, 'True')),
-            widget=forms.RadioSelect)
+
         if self.instance.mirrored_page:
             self.fields['mirrored_page'].queryset = Page.objects.filter(region=self.instance.mirrored_page.region)
             self.fields['mirrored_page'].initial = self.instance.mirrored_page
@@ -148,7 +149,6 @@ def save(self, *args, **kwargs):
             # only update these values when page is created
             page.region = self.region
         page.archived = bool(self.data.get('submit_archive'))
-        page.mirrored_page_first = self.cleaned_data['mirrored_page_first']
         page.mirrored_page = self.cleaned_data['mirrored_page']
         page.save()
         page.move_to(self.cleaned_data['parent'], self.cleaned_data['position'])


Test patch: