Repository: django-cms/django-cms

Issue:
language chooser at page creation time



Discussion:
test with page types


Resolving patch:
diff --git a/cms/admin/forms.py b/cms/admin/forms.py
--- a/cms/admin/forms.py
+++ b/cms/admin/forms.py
@@ -60,6 +60,9 @@ def save_permissions(data, obj):
 
 
 class PageForm(forms.ModelForm):
+    language = forms.ChoiceField(label=_("Language"), choices=get_language_tuple(),
+                                 help_text=_('The current language of the content fields.'))
+    page_type = forms.ChoiceField(label=_("Page type"), required=False)
     title = forms.CharField(label=_("Title"), widget=forms.TextInput(),
                             help_text=_('The default title'))
     slug = forms.CharField(label=_("Slug"), widget=forms.TextInput(),
@@ -73,9 +76,6 @@ class PageForm(forms.ModelForm):
                                        widget=forms.Textarea(attrs={'maxlength': '155', 'rows': '4'}),
                                        help_text=_('A description of the page used by search engines.'),
                                        max_length=155)
-    language = forms.ChoiceField(label=_("Language"), choices=get_language_tuple(),
-                                 help_text=_('The current language of the content fields.'))
-    page_type = forms.ChoiceField(label=_("Page type"), required=False)
 
     class Meta:
         model = Page
diff --git a/cms/admin/pageadmin.py b/cms/admin/pageadmin.py
--- a/cms/admin/pageadmin.py
+++ b/cms/admin/pageadmin.py
@@ -258,9 +258,8 @@ def get_form(self, request, obj=None, **kwargs):
         if 'page_type' in form.base_fields:
             if 'copy_target' in request.GET or 'add_page_type' in request.GET or obj:
                 del form.base_fields['page_type']
-            else:
-                if not Page.objects.filter(parent__reverse_id=PAGE_TYPES_ID).count():
-                    del form.base_fields['page_type']
+            elif not Title.objects.filter(page__parent__reverse_id=PAGE_TYPES_ID, language=language).count():
+                del form.base_fields['page_type']
         if 'add_page_type' in request.GET:
             del form.base_fields['menu_title']
             del form.base_fields['meta_description']
@@ -368,6 +367,8 @@ def add_view(self, request, form_url='', extra_context=None):
             extra_context.update({
                 'title':  _("Add Page Copy"),
             })
+        else:
+            extra_context = self.update_language_tab_context(request, context=extra_context)
         extra_context.update(self.get_unihandecode_context(language))
         return super(PageAdmin, self).add_view(request, form_url, extra_context=extra_context)
 
@@ -425,13 +426,15 @@ def render_change_form(self, request, context, add=False, change=False, form_url
         })
         return super(PageAdmin, self).render_change_form(request, context, add, change, form_url, obj)
 
-    def _get_site_languages(self, obj):
+    def _get_site_languages(self, obj=None):
         site_id = None
         if obj:
             site_id = obj.site_id
+        else:
+            site_id = Site.objects.get_current().pk
         return get_language_tuple(site_id)
 
-    def update_language_tab_context(self, request, obj, context=None):
+    def update_language_tab_context(self, request, obj=None, context=None):
         if not context:
             context = {}
         language = get_language_from_request(request, obj)


Test patch: