internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: django-cms/django-cms

Issue:
can't delete translations of parents with children



Discussion:

Resolving patch:
diff --git a/cms/admin/pageadmin.py b/cms/admin/pageadmin.py
--- a/cms/admin/pageadmin.py
+++ b/cms/admin/pageadmin.py
@@ -1249,9 +1249,12 @@ def resolve(self, request):
             return HttpResponse('', content_type='text/plain')
         if request.session.get('cms_log_latest', False):
             log = LogEntry.objects.get(pk=request.session['cms_log_latest'])
-            obj = log.get_edited_object()
+            try:
+                obj = log.get_edited_object()
+            except ObjectDoesNotExist:
+                obj = None
             del request.session['cms_log_latest']
-            if obj.__class__ in toolbar_pool.get_watch_models() and hasattr(obj, 'get_absolute_url'):
+            if obj and obj.__class__ in toolbar_pool.get_watch_models() and hasattr(obj, 'get_absolute_url'):
                 try:
                     return HttpResponse(force_unicode(obj.get_absolute_url()), content_type='text/plain')
                 except:
diff --git a/cms/models/pagemodel.py b/cms/models/pagemodel.py
--- a/cms/models/pagemodel.py
+++ b/cms/models/pagemodel.py
@@ -687,7 +687,7 @@ def mark_descendants_pending(self, language):
         public_page = self.publisher_public
         from cms.models import Title
         if public_page:
-            descendants = public_page.get_descendants()
+            descendants = public_page.get_descendants().filter(title_set__language=language)
             for child in descendants:
                 try:
                     child.set_publisher_state(language, PUBLISHER_STATE_PENDING, published=False)


Test patch:
Repository: django-cms/django-cms

Issue:
redirect preview only in draft



Discussion:

Resolving patch:
diff --git a/cms/views.py b/cms/views.py
--- a/cms/views.py
+++ b/cms/views.py
@@ -106,7 +106,7 @@ def details(request, slug):
                     if new_language in get_public_languages():
                         with force_language(new_language):
                             pages_root = reverse('pages-root')
-                            if hasattr(request, 'toolbar') and request.user.is_staff and request.toolbar.show_toolbar:
+                            if hasattr(request, 'toolbar') and request.user.is_staff and request.toolbar.edit_mode:
                                 request.toolbar.redirect_url = pages_root
                             elif pages_root not in own_urls:
                                 return HttpResponseRedirect(pages_root)
@@ -126,7 +126,7 @@ def details(request, slug):
                         # In the case where the page is not available in the
                     # preferred language, *redirect* to the fallback page. This
                     # is a design decision (instead of rendering in place)).
-                    if hasattr(request, 'toolbar') and request.user.is_staff and request.toolbar.show_toolbar:
+                    if hasattr(request, 'toolbar') and request.user.is_staff and request.toolbar.edit_mode:
                         request.toolbar.redirect_url = path
                     elif path not in own_urls:
                         return HttpResponseRedirect(path)
@@ -170,7 +170,7 @@ def details(request, slug):
             redirect_url = "/%s/%s" % (current_language, redirect_url.lstrip("/"))
             # prevent redirect to self
 
-        if hasattr(request, 'toolbar') and request.user.is_staff and request.toolbar.show_toolbar:
+        if hasattr(request, 'toolbar') and request.user.is_staff and request.toolbar.edit_mode:
             request.toolbar.redirect_url = redirect_url
         elif redirect_url not in own_urls:
             return HttpResponseRedirect(redirect_url)


Test patch:
diff --git a/cms/tests/multilingual.py b/cms/tests/multilingual.py
--- a/cms/tests/multilingual.py
+++ b/cms/tests/multilingual.py
@@ -175,7 +175,7 @@ def test_frontend_lang(self):
                 response = self.client.get("/en/page2/")
                 self.assertEqual(response.status_code, 200)
                 response = self.client.get("/en/page4/")
-                self.assertEqual(response.status_code, 200)
+                self.assertEqual(response.status_code, 302)
             self.client.logout()
             response = self.client.get("/en/page4/")
             self.assertEqual(response.status_code, 404)
Repository: django-cms/django-cms

Issue:
Revert trhows 500 error ('NoneType' object has no attribute 'cmsplugin_ptr')
```

/Users/finalangel/Sites/django-cms/cms/admin/pageadmin.py in revert_page
        page.revert(language) ...
▶ Local vars
/Users/finalangel/Sites/django-cms/cms/models/pagemodel.py in revert
        public._copy_contents(self, language) ...
▶ Local vars
/Users/finalangel/Sites/django-cms/cms/models/pagemodel.py in _copy_contents
        # TODO: Make this into a "graceful" copy instead of deleting and overwriting
        # copy the placeholders (and plugins on those placeholders!)
        from cms.plugin_pool import plugin_pool
        plugin_pool.set_plugin_meta()
        for plugin in CMSPlugin.objects.filter(placeholder__page=target, language=language).order_by('-level'):
            inst, cls = plugin.get_plugin_instance()
            inst.cmsplugin_ptr._no_reorder = True ...
            inst.delete()
        for ph in self.placeholders.all():
            plugins = ph.get_plugins_list(language)
            try:
                ph = target.placeholders.get(slot=ph.slot)
            except Placeholder.DoesNotExist:
▶ Local vars
```



Discussion:

Resolving patch:
diff --git a/cms/models/pagemodel.py b/cms/models/pagemodel.py
--- a/cms/models/pagemodel.py
+++ b/cms/models/pagemodel.py
@@ -246,8 +246,12 @@ def _copy_contents(self, target, language):
         plugin_pool.set_plugin_meta()
         for plugin in CMSPlugin.objects.filter(placeholder__page=target, language=language).order_by('-level'):
             inst, cls = plugin.get_plugin_instance()
-            inst.cmsplugin_ptr._no_reorder = True
-            inst.delete()
+            if inst:
+                inst.cmsplugin_ptr._no_reorder = True
+                inst.delete()
+            else:
+                plugin._no_reorder = True
+                plugin.delete()
         for ph in self.placeholders.all():
             plugins = ph.get_plugins_list(language)
             try:
diff --git a/cms/models/static_placeholder.py b/cms/models/static_placeholder.py
--- a/cms/models/static_placeholder.py
+++ b/cms/models/static_placeholder.py
@@ -60,8 +60,12 @@ def publish(self, request, language, force=False):
         if force or self.has_publish_permission(request):
             for plugin in CMSPlugin.objects.filter(placeholder=self.public, language=language).order_by('-level'):
                 inst, cls = plugin.get_plugin_instance()
-                inst.cmsplugin_ptr._no_reorder = True
-                inst.delete()
+                if inst:
+                    inst.cmsplugin_ptr._no_reorder = True
+                    inst.delete()
+                else:
+                    plugin._no_reorder = True
+                    plugin.delete()
             plugins = self.draft.get_plugins_list(language=language)
             copy_plugins_to(plugins, self.public, no_signals=True)
             self.dirty = False


Test patch:
Repository: django-cms/django-cms

Issue:
error messages not displayed if i publish in sideframe



Discussion:

Resolving patch:
diff --git a/cms/admin/pageadmin.py b/cms/admin/pageadmin.py
--- a/cms/admin/pageadmin.py
+++ b/cms/admin/pageadmin.py
@@ -1021,7 +1021,7 @@ def publish_page(self, request, page_id, language):
             # if request comes from tree..
             return admin_utils.render_admin_menu_item(request, page)
         referrer = request.META.get('HTTP_REFERER', '')
-        path = '../../'
+        path = reverse("admin:cms_page_changelist")
         if 'admin' not in referrer:
             if all_published:
                 if page:
@@ -1067,7 +1067,7 @@ def unpublish(self, request, page_id, language):
         except ValidationError:
             exc = sys.exc_info()[1]
             messages.error(request, exc.message)
-        return admin_utils.render_admin_menu_item(request, page)
+        return HttpResponseRedirect(reverse("admin:cms_page_changelist"))
 
     @transaction.commit_on_success
     def revert_page(self, request, page_id, language):


Test patch:
diff --git a/cms/tests/admin.py b/cms/tests/admin.py
--- a/cms/tests/admin.py
+++ b/cms/tests/admin.py
@@ -618,7 +618,7 @@ def test_change_publish_unpublish(self):
             self.assertTrue(page.is_published('en'))
 
             response = self.admin_class.unpublish(request, page.pk, "en")
-            self.assertEqual(response.status_code, 200)
+            self.assertEqual(response.status_code, 302)
 
             page = self.reload(page)
             self.assertFalse(page.is_published('en'))
Repository: django-cms/django-cms

Issue:
Can't open two levels of menu items
Steps to reproduce:
Go to: /manage/cms/page/

Click the [+] to expand the tree. Then click a [+] in a page below that. A URL like `/manage/cms/page/139/None/descendants/` is generated which results in a traceback: ValueError: invalid literal for int() with base 10: '139/None/descendants'

Regression introduced in 2b30ead4



Discussion:

Resolving patch:
diff --git a/cms/templatetags/cms_admin.py b/cms/templatetags/cms_admin.py
--- a/cms/templatetags/cms_admin.py
+++ b/cms/templatetags/cms_admin.py
@@ -124,12 +124,12 @@ def get_context(self, context, page):
             filtered = context['filtered']
 
 
-
+        language = context['preview_language']
         # following function is newly used for getting the context per item (line)
         # if something more will be required, then get_admin_menu_item_context
         # function have to be updated. 
         # This is done because item can be reloaded after some action over ajax.
-        context.update(get_admin_menu_item_context(request, page, filtered))
+        context.update(get_admin_menu_item_context(request, page, filtered, language))
 
         # this here is just context specific for menu rendering - items itself does
         # not use any of following variables


Test patch:
diff --git a/cms/tests/admin.py b/cms/tests/admin.py
--- a/cms/tests/admin.py
+++ b/cms/tests/admin.py
@@ -516,6 +516,7 @@ def test_changelist_tree(self):
         self.assertContains(response, 'id="page_%s"' % second_level_page_bottom.pk)
         # but not any further down the tree
         self.assertNotContains(response, 'id="page_%s"' % third_level_page.pk)
+        self.assertNotContains(response, 'None')
 
     def test_unihandecode_doesnt_break_404_in_admin(self):
         self.get_superuser()
Repository: django-cms/django-cms

Issue:
publishing & unpublishing changes language of tree view



Discussion:

Resolving patch:
diff --git a/cms/admin/pageadmin.py b/cms/admin/pageadmin.py
--- a/cms/admin/pageadmin.py
+++ b/cms/admin/pageadmin.py
@@ -1021,7 +1021,10 @@ def publish_page(self, request, page_id, language):
             # if request comes from tree..
             return admin_utils.render_admin_menu_item(request, page)
         referrer = request.META.get('HTTP_REFERER', '')
+
         path = reverse("admin:cms_page_changelist")
+        if request.GET.get('redirect_language'):
+            path = "%s?language=%s&page_id=%s" % (path, request.GET.get('redirect_language'), request.GET.get('redirect_page_id'))
         if 'admin' not in referrer:
             if all_published:
                 if page:
@@ -1067,7 +1070,10 @@ def unpublish(self, request, page_id, language):
         except ValidationError:
             exc = sys.exc_info()[1]
             messages.error(request, exc.message)
-        return HttpResponseRedirect(reverse("admin:cms_page_changelist"))
+        path = reverse("admin:cms_page_changelist")
+        if request.GET.get('redirect_language'):
+            path = "%s?language=%s&page_id=%s" % (path, request.GET.get('redirect_language'), request.GET.get('redirect_page_id'))
+        return HttpResponseRedirect(path)
 
     @transaction.commit_on_success
     def revert_page(self, request, page_id, language):


Test patch:
Repository: django-cms/django-cms

Issue:
Redirect path incorrect
Selecting a redirect with the new redirect widget result in the `Title.path` to be assigned to the field, instead of `Title.page.get_absolute_url`



Discussion:
Ack, will fix this today. Quick thought, is there something available to deal with page that change URL after the redirect has been set? Eg: page 2 redirects to page 1, page 1's URL is changed by the user, the redirect of page 2 is now broken. Is this use case covered?


Resolving patch:
diff --git a/cms/admin/pageadmin.py b/cms/admin/pageadmin.py
--- a/cms/admin/pageadmin.py
+++ b/cms/admin/pageadmin.py
@@ -1356,20 +1356,27 @@ def get_published_pagelist(self, *args, **kwargs):
             query_term = request.GET.get('q','').strip('/')
 
             language_code = request.GET.get('language_code', settings.LANGUAGE_CODE)
-            published_pages = Page.objects.published().public().filter(
+            matching_published_pages = Page.objects.published().public().filter(
                 Q(title_set__title__icontains=query_term, title_set__language=language_code)
                 | Q(title_set__path__icontains=query_term, title_set__language=language_code)
                 | Q(title_set__menu_title__icontains=query_term, title_set__language=language_code)
                 | Q(title_set__page_title__icontains=query_term, title_set__language=language_code)
             ).distinct()
 
-            return HttpResponse(json.dumps(list(published_pages.values(
-                'id',
-                'title_set__path',
-                'title_set__title',
-            ))), content_type='application/json')
+            results = []
+            for page in matching_published_pages:
+                results.append(
+                    {
+                        'path': page.get_path(language=language_code),
+                        'title': page.get_title(language=language_code),
+                        'redirect_url': page.get_absolute_url(language=language_code)
+                    }
+                )
 
-        return HttpResponseForbidden()
+            return HttpResponse(json.dumps(results), content_type='application/json')
+
+        else:
+            return HttpResponseForbidden()
 
     def add_plugin(self, *args, **kwargs):
         with create_revision():
diff --git a/cms/forms/widgets.py b/cms/forms/widgets.py
--- a/cms/forms/widgets.py
+++ b/cms/forms/widgets.py
@@ -149,8 +149,8 @@ def render(self, name=None, value=None, attrs=None):
                         more: false,
                         results: $.map(data, function(item, i){
                             return {
-                                'id':item.title_set__path,
-                                'text': item.title_set__title + ' (/' + item.title_set__path + ')'}
+                                'id':item.redirect_url,
+                                'text': item.title + ' (/' + item.path + ')'}
                             }
                         )
                     };


Test patch:
Repository: django-cms/django-cms

Issue:
PageSmartLinkWidget should use URL reversing
Admin URLs do not necessary start with a language code and "admin". In my case, the URL path is `/manage/cms/page/published-pages/`.
https://github.com/divio/django-cms/blob/develop/cms/forms/widgets.py#L139



Discussion:

Resolving patch:
diff --git a/cms/admin/pageadmin.py b/cms/admin/pageadmin.py
--- a/cms/admin/pageadmin.py
+++ b/cms/admin/pageadmin.py
@@ -134,7 +134,7 @@ def get_urls(self):
             pat(r'^([0-9]+)/([a-z\-]+)/revert/$', self.revert_page),
             pat(r'^([0-9]+)/([a-z\-]+)/preview/$', self.preview_page),
             pat(r'^add-page-type/$', self.add_page_type),
-            url(r'^published-pages/$', self.get_published_pagelist),
+            pat(r'^published-pages/$', self.get_published_pagelist),
             url(r'^resolve/$', self.resolve, name="cms_page_resolve"),
         )
 
diff --git a/cms/forms/widgets.py b/cms/forms/widgets.py
--- a/cms/forms/widgets.py
+++ b/cms/forms/widgets.py
@@ -1,6 +1,7 @@
 # -*- coding: utf-8 -*-
 
 from django.contrib.sites.models import Site
+from django.core.urlresolvers import reverse
 from django.forms.widgets import Select, MultiWidget, TextInput
 from cms.utils.compat.dj import force_unicode
 from django.utils.safestring import mark_safe
@@ -136,7 +137,7 @@ def render(self, name=None, value=None, attrs=None):
             placeholder: "%(placeholder_text)s",
             minimumInputLength: 3,
             ajax: {
-                url: "/%(language_code)s/admin/cms/page/published-pages/",
+                url: "%(ajax_url)s",
                 dataType: 'json',
                 data: function (term, page) {
                     return {
@@ -169,7 +170,8 @@ def render(self, name=None, value=None, attrs=None):
 </script>''' % {
             'element_id': id_,
             'placeholder_text': final_attrs.get('placeholder_text', ''),
-            'language_code': self.language
+            'language_code': self.language,
+            'ajax_url': reverse("admin:cms_page_get_published_pagelist")
         }]
 
         output.append(super(PageSmartLinkWidget, self).render(name, value, attrs))


Test patch:
Repository: django-cms/django-cms

Issue:
(Un-)publishing a normal pages gives spews warning message on console re: app url changes
Latest dev. 3.0b4.dev14

Simply publishing a page or unpublishing it spews this into the console (on runserver):

“Application url changed and urls_need_reloading signal fired. Please reload the urls.py or restart the server”

I thought this was for app-hooks? Is it for regular pages now?



Discussion:
Issue confirmed, if you have a cms page adiacent to a page with apphook.
I bet mptt tree updating triggers the `post_save_page` signal which in turns triggers the message.

mmh i will need to investigate this..... but not a blocker for me.

Me neither if the only result is an ill-informed console message. That is not client-facing.


Resolving patch:
diff --git a/cms/signals/apphook.py b/cms/signals/apphook.py
--- a/cms/signals/apphook.py
+++ b/cms/signals/apphook.py
@@ -47,7 +47,7 @@ def apphook_post_title_checker(instance, **kwargs):
             old_title.published, old_title.page.application_urls, old_title.page.application_namespace, old_title.path)
         new_values = (
             instance.published, instance.page.application_urls, instance.page.application_namespace, instance.path)
-        if old_values != new_values:
+        if old_values != new_values and (old_values[2] or new_values[2]):
             request_finished.connect(trigger_restart, dispatch_uid=DISPATCH_UID)
 
 


Test patch:
Repository: django-cms/django-cms

Issue:
'EmptyTitle' object has no attribute 'publisher_state'
cms.models.pagemodel in get_publisher_state
AttributeError: 'EmptyTitle' object has no attribute 'publisher_state'



Discussion:

Resolving patch:
diff --git a/cms/models/pagemodel.py b/cms/models/pagemodel.py
--- a/cms/models/pagemodel.py
+++ b/cms/models/pagemodel.py
@@ -522,7 +522,7 @@ def get_publisher_state(self, language, force_reload=False):
 
         try:
             return self.get_title_obj(language, False, force_reload=force_reload).publisher_state
-        except Title.DoesNotExist:
+        except (Title.DoesNotExist, AttributeError):
             return None
 
     def set_publisher_state(self, language, state, published=None):


Test patch:
Repository: django-cms/django-cms

Issue:
Place "Page settings" button same as "Publish changes"
![image](https://f.cloud.github.com/assets/270307/2420803/0d4f2282-ab78-11e3-8746-1cf49105b9a3.png)

![image](https://f.cloud.github.com/assets/270307/2420813/2c3302c2-ab78-11e3-9ebf-cdbaf0e48a87.png)



Discussion:
Can I propose that, since there are changes being made up there, that we also consider swapping the positions of "Content" and "Structure"? My rationale is simply that Structure is like a wireframe, then Content is already like a preview of the page, then Live is the page. It just feels like the buttons should progress in the same order.

+1

sounds reasonable :)


Resolving patch:
diff --git a/cms/cms_toolbar.py b/cms/cms_toolbar.py
--- a/cms/cms_toolbar.py
+++ b/cms/cms_toolbar.py
@@ -76,10 +76,10 @@ def post_template_populate(self):
     def add_structure_mode(self):
         switcher = self.toolbar.add_button_list('Mode Switcher', side=self.toolbar.RIGHT,
                                                 extra_classes=['cms_toolbar-item-cms-mode-switcher'])
-        switcher.add_button(_("Content"), '?edit', active=not self.toolbar.build_mode,
-                            disabled=self.toolbar.build_mode)
         switcher.add_button(_("Structure"), '?build', active=self.toolbar.build_mode,
                             disabled=not self.toolbar.build_mode)
+        switcher.add_button(_("Content"), '?edit', active=not self.toolbar.build_mode,
+                            disabled=self.toolbar.build_mode)
 
 
 @toolbar_pool.register
@@ -224,6 +224,13 @@ def post_template_populate(self):
                     if static_placeholder.has_change_permission(self.request):
                         self.add_draft_live()
                         break
+            if not self.title:
+                self.toolbar.add_modal_button(
+                    _("Page settings"),
+                    "%s?language=%s" % (reverse('admin:cms_page_change', args=[self.page.pk]), self.toolbar.language),
+                    side=self.toolbar.RIGHT,
+                    extra_classes=["cms_btn-action"],
+                )
         else:
             added = False
             if statics:
@@ -397,14 +404,6 @@ def add_page_menu(self):
 
         current_page_menu.add_modal_item(_('Delete page'), url=delete_url, on_close=on_delete_redirect_url,
                                          disabled=not_edit_mode)
-
-        if not self.title:
-            self.toolbar.add_modal_button(
-                _("Page settings"),
-                "%s?language=%s" % (reverse('admin:cms_page_change', args=[self.page.pk]), self.toolbar.language),
-                side=self.toolbar.RIGHT,
-                extra_classes=["cms_btn-action"],
-            )
         current_page_menu.add_break(PAGE_MENU_LAST_BREAK)
         current_page_menu.add_modal_item(
             _("Save as Page Type"),
@@ -415,7 +414,6 @@ def add_page_menu(self):
             disabled=not_edit_mode
         )
 
-
     def add_history_menu(self):
         # history menu
         history_menu = self.toolbar.get_or_create_menu('history', _('History'), position=2)


Test patch: