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

Issue:
Picture plugin form shows both public and draft pages
When editing the picture plugin, both _draft_ and _public_ pages are shown in the `Page` form field.
Only one version should be loaded.



Discussion:

Resolving patch:
diff --git a/cms/plugins/picture/models.py b/cms/plugins/picture/models.py
--- a/cms/plugins/picture/models.py
+++ b/cms/plugins/picture/models.py
@@ -23,6 +23,7 @@ class Picture(CMSPlugin):
     url = models.CharField(_("link"), max_length=255, blank=True, null=True,
         help_text=_("If present, clicking on image will take user to link."))
     page_link = models.ForeignKey(Page, verbose_name=_("page"), null=True,
+        limit_choices_to={'publisher_is_draft': True},
         blank=True, help_text=_("If present, clicking on image will take user \
         to specified page."))
     alt = models.CharField(_("alternate text"), max_length=255, blank=True,


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

Issue:
Moving plugin to non page placeholder fails (v3.0)
If plugin is moved to a non page placeholder it fails as it cant find a template in [move_plugin](https://github.com/divio/django-cms/blob/develop/cms/admin/placeholderadmin.py#L315) because page is None [here](https://github.com/divio/django-cms/blob/develop/cms/admin/pageadmin.py#L580). If its supposed to be this way which I doubt i.e. no moving plugin to non page placeholder then it should be prevented in the front end.



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
@@ -568,7 +568,8 @@ def post_clear_placeholder(self, request, placeholder):
 
     def get_placeholder_template(self, request, placeholder):
         page = placeholder.page
-        return page.get_template()
+        if page:
+            return page.get_template()
 
     def changelist_view(self, request, extra_context=None):
         "The 'change list' admin view for this model."


Test patch:
diff --git a/cms/test_utils/cli.py b/cms/test_utils/cli.py
--- a/cms/test_utils/cli.py
+++ b/cms/test_utils/cli.py
@@ -178,6 +178,7 @@ def configure(db_url, **extra):
             ('col_three.html', gettext('three columns')),
             ('nav_playground.html', gettext('navigation examples')),
             ('simple.html', 'simple'),
+            ('stacks.html', 'stacks'),
         ),
         CMS_PLACEHOLDER_CONF={
             'col_sidebar': {
diff --git a/cms/test_utils/project/templates/stacks.html b/cms/test_utils/project/templates/stacks.html
new file mode 100644
--- /dev/null
+++ b/cms/test_utils/project/templates/stacks.html
@@ -0,0 +1,27 @@
+{% extends "base.html" %}
+{% load i18n cms_tags stack_tags %}
+
+{% block tpl_id %}tpl_col_two{% endblock %}
+
+{% block content %}
+	<h1>{% show_editable_page_title %}</h1>
+
+    {% stack "logo" %}
+
+	<div id="col1" class="grid_3">
+		{% include "sidebar_submenu.html" %}
+		{% block col_sidebar %}
+			{% with "220" as width %}
+	    		{% placeholder col_sidebar %}
+			{% endwith %}
+		{% endblock %}
+    </div>
+
+    <div id="col2" class="grid_9">
+		{% block col_left %}
+			{% with "640" as width %}
+				{% placeholder col_left %}
+			{% endwith %}
+		{% endblock %}
+    </div>
+{% endblock %}
\ No newline at end of file
Repository: django-cms/django-cms

Issue:
404 while adding child plugin in a non-page placeholder
If I try to add a child plugin to a parent plugin held by a placeholder from an app hook defined in models I get a 404 error. I spotted the error in the placeholderadmin.py on line 161:

```
# in-plugin add-plugin
        else:
            parent = get_object_or_404(CMSPlugin, pk=parent_id)
            placeholder = parent.placeholder
            page = placeholder.page if placeholder else None
            if not page: # Make sure we do have a page
                raise Http404()
            position = request.POST.get('plugin_order',
                                        CMSPlugin.objects.filter(language=language, parent=parent).count())
            # placeholder (non-page) add-plugin
```

There is already a comment for the given case but no code. Is it lost or any other reason the test for page has to be made? The test should be skipped if the placeholder isn't a page placeholder. Is there a possibility to do this?



Discussion:

Resolving patch:
diff --git a/cms/admin/placeholderadmin.py b/cms/admin/placeholderadmin.py
--- a/cms/admin/placeholderadmin.py
+++ b/cms/admin/placeholderadmin.py
@@ -157,9 +157,6 @@ def add_plugin(self, request):
         else:
             parent = get_object_or_404(CMSPlugin, pk=parent_id)
             placeholder = parent.placeholder
-            page = placeholder.page if placeholder else None
-            if not page: # Make sure we do have a page
-                raise Http404()
             position = request.POST.get('plugin_order',
                                         CMSPlugin.objects.filter(language=language, parent=parent).count())
             # placeholder (non-page) add-plugin


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

Issue:
make django-admin-style a fixed dependency 
and add it to the tutorial



Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -37,6 +37,7 @@
         'html5lib',
         'django-mptt>=0.5.1,<0.5.3',
         'django-sekizai>=0.7',
+	'djangocms-admin-style'
     ],
     tests_require=[
         'django-reversion>=1.6.6',


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

Issue:
allow the toolbar to have different colors depending on if DEBUG=True or False...
usefull for dev, stage and live instances.



Discussion:
couldn't this be done in "user-space" CSS? As in, without adding explicit support for this in the CMS? Maybe just document the CSS class needed?

@ojii we could add a class cms_debug and the user can than define their own style.
I would not redefine the entire toolbar on that, just a subtle hint.

Can we not just write next to the site name (in the menu) (DEBUG)?


Resolving patch:
diff --git a/cms/templatetags/cms_tags.py b/cms/templatetags/cms_tags.py
--- a/cms/templatetags/cms_tags.py
+++ b/cms/templatetags/cms_tags.py
@@ -17,6 +17,7 @@
 from cms.utils.moderator import use_draft
 from cms.utils.page_resolver import get_page_queryset
 from cms.utils.placeholder import validate_placeholder_name
+from cms import __version__
 from django import template
 from django.conf import settings
 from django.contrib.sites.models import Site
@@ -553,6 +554,7 @@ def render(self, context):
         language = request.toolbar.language
         with force_language(language):
             request.toolbar.populate()
+            context['cms_version'] = __version__
             content = super(CMSToolbar, self).render(context)
         return content
 


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

Issue:
FIxes doc issues listed in #2148
Index stops yielding 404
Link to changes of 3.0 works.



Discussion:

Resolving patch:
diff --git a/docs/conf.py b/docs/conf.py
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -38,7 +38,7 @@
 }
 
 # Add any paths that contain templates here, relative to this directory.
-templates_path = ['templates']
+#templates_path = ['templates']
 
 # The suffix of source filenames.
 source_suffix = '.rst'


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

Issue:
NoReverseMatch raised if apphook doesn't exist
when I add an app to INSTALLED_APPS that defines menu  entries which in turn call `reverse()` to get some urls, I get NoReverseMatch errors if there's no Page apphooked to that app, even though I don't see why that menu shoud be being processed.

I'm seeing this with `cmsplugin_zinnia`, I'm not sure if this is a `cmsplugin_zinnia` or a `django-cms` issue



Discussion:
Experienced the same with cmsplugin_news.


Resolving patch:
diff --git a/menus/menu_pool.py b/menus/menu_pool.py
--- a/menus/menu_pool.py
+++ b/menus/menu_pool.py
@@ -1,14 +1,21 @@
 # -*- coding: utf-8 -*-
+from logging import getLogger
 from cms.utils import get_cms_setting
 from cms.utils.django_load import load
+
 from django.conf import settings
 from django.contrib.sites.models import Site
 from django.core.cache import cache
+from django.core.urlresolvers import NoReverseMatch
 from django.utils.translation import get_language
 from menus.exceptions import NamespaceAllreadyRegistered
 from menus.models import CacheKey
+from django.utils.translation import ugettext_lazy as _
+from django.contrib import messages
 import copy
 
+logger = getLogger('menus')
+
 def _build_nodes_inner_for_one_menu(nodes, menu_class_name):
     '''
     This is an easier to test "inner loop" building the menu tree structure
@@ -132,7 +139,16 @@ def _build_nodes(self, request, site_id):
         
         final_nodes = []
         for menu_class_name in self.menus:
-            nodes = self.menus[menu_class_name].get_nodes(request)
+            try:
+                nodes = self.menus[menu_class_name].get_nodes(request)
+            except NoReverseMatch:
+                # Apps might raise NoReverseMatch if an apphook does not yet
+                # exist, skip them instead of crashing
+                nodes = []
+                toolbar = getattr(request, 'toolbar', None)
+                if toolbar and toolbar.is_staff:
+                    messages.error(request, _('Menu %s cannot be loaded. Please, make sure all its urls exist and can be resolved.') % menu_class_name)
+                    logger.error("Menu %s could not be loaded." % menu_class_name, exc_info=True)
             # nodes is a list of navigation nodes (page tree in cms + others)
             final_nodes += _build_nodes_inner_for_one_menu(nodes, menu_class_name)
         cache.set(key, final_nodes, get_cms_setting('CACHE_DURATIONS')['menus'])


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

Issue:
PlaceholderFields and Frontend editing will not work for existing objects if any PlaceholderFields are added to a model.
PlaceholderFields added to models after objects have already been created don't appear to have been initialized properly and this prevents them from appearing (AT ALL) on the frontend and front-end editing for these model instances will fail when saving with an error:

```
'NoneType' object has no attribute 'slot'
Request Method: POST
Request URL:    http://127.0.0.1:8000/en/.../.../2/?language=en
Django Version: 1.5.4
Exception Type: AttributeError
Exception Value:    
'NoneType' object has no attribute 'slot'
Exception Location: /.../.virtualenvs/.../src/django-cms/cms/models/fields.py in pre_save, line 41
Python Version: 2.7.2
```



Discussion:
This might be related to `PlaceholderField.pre_save()` method.

Real issue behind #2248 


Resolving patch:
diff --git a/cms/models/fields.py b/cms/models/fields.py
--- a/cms/models/fields.py
+++ b/cms/models/fields.py
@@ -38,6 +38,9 @@ def pre_save(self, model_instance, add):
         else:
             slot = self._get_placeholder_slot(model_instance)
             placeholder = getattr(model_instance, self.name)
+            if not placeholder:
+                setattr(model_instance, self.name, self._get_new_placeholder(model_instance))
+                placeholder = getattr(model_instance, self.name)
             if placeholder.slot != slot:
                 placeholder.slot = slot
                 placeholder.save()


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

Issue:
Live/Draft switch causes 404
If the page hasn't been published yet clicking on the draft/live switch in the cms toolbar causes to load ?edit_off which is a 404. The button maybe should be disabled if the page is not published.



Discussion:

Resolving patch:
diff --git a/cms/cms_toolbar.py b/cms/cms_toolbar.py
--- a/cms/cms_toolbar.py
+++ b/cms/cms_toolbar.py
@@ -178,7 +178,7 @@ def populate(self):
                     self.toolbar.add_button(title, url=publish_url, extra_classes=classes, side=self.toolbar.RIGHT,
                                         disabled=not dirty)
         if self.page:
-            if self.page.has_change_permission(self.request):
+            if self.page.has_change_permission(self.request) and self.page.published:
                 self.add_draft_live()
             elif statics:
                 for static_placeholder in statics:


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

Issue:
Deleting model objects via FE editing does nothing
Enabling front-end editing on my models works great (way cool!), but, unfortunately, pressing the delete button appears to do nothing.  I don't think even an AJAX request makes it to the server. No JS errors either.

Using latest django-cms with Django 1.5.4, Python 2.7.x using runserver on Chrome (latest) on a Mac.

I'm able to delete the objects without issue in the sidebar admin. And, I've tested this on multiple models and their objects. I can't get any of them to do anything with the delete button on the FE. All other FE behaviours seem fine.



Discussion:
Wondering if having the `delete` and `add another` buttons is sensible in model frontend editing.

Apparently the `href` attribute for `a.deletelink` is not copied from the changeform in the iframe to che modal window iframe.
There should be something to fix in this code https://github.com/divio/django-cms/blob/develop/cms/static/cms/js/plugins/cms.toolbar.js#L1064

My vote is we keep the functionality but we fix it.

Agreed with @FinalAngel to fix it instead of removing it

might this be fixed now?

Do you mean fixed in current develop?
I'll check later

Any updates @yakky ?

@FinalAngel ATM there is no way from the delete view to redirect the main browser window to another URL.
Both deleting pages and django models from the frontend results in 404 as the URL the browser is on, no longer exists

Deassigning as this will first need decision on proper redirect after delete policy


Resolving patch:
diff --git a/cms/templatetags/cms_tags.py b/cms/templatetags/cms_tags.py
--- a/cms/templatetags/cms_tags.py
+++ b/cms/templatetags/cms_tags.py
@@ -704,6 +704,13 @@ def get_context(self, context, instance, attribute, edit_fields, language,
                     url_base = reverse(view_url, args=(instance.pk, language))
                     querystring['edit_fields'] = ",".join(context['edit_fields'])
             context['edit_url'] = "%s?%s" % (url_base, urlencode(querystring))
+            context['refresh_page'] = True
+            # We may be outside the CMS (e.g.: an application which is not attached via Apphook
+            # in this case we may only go back to the home page
+            if hasattr(context['request'], 'current_page'):
+                context['redirect_on_close'] = context['request'].current_page.get_absolute_url(language)
+            else:
+                context['redirect_on_close'] = ''
         # content is for non-edit template content.html
         # rendered_content is for edit template plugin.html
         # in this templatetag both hold the same content


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

Issue:
Unpublished pages hidden from navigation in draft mode
It would make sense to show unpublished pages in the menu while in draft mode.



Discussion:

Resolving patch:
diff --git a/cms/menu.py b/cms/menu.py
--- a/cms/menu.py
+++ b/cms/menu.py
@@ -9,7 +9,7 @@
 from cms.utils.conf import get_cms_setting
 from cms.utils.i18n import get_fallback_languages, hide_untranslated
 from cms.utils.page_resolver import get_page_queryset
-from cms.utils.moderator import get_title_queryset
+from cms.utils.moderator import get_title_queryset, use_draft
 from cms.utils.plugins import current_site
 from menus.base import Menu, NavigationNode, Modifier
 from menus.menu_pool import menu_pool
@@ -231,7 +231,9 @@ def get_nodes(self, request):
         if hide_untranslated(lang, site.pk):
             filters['title_set__language'] = lang
 
-        pages = page_queryset.published().filter(**filters).order_by("tree_id", "lft")
+        if not use_draft(request):
+            page_queryset = page_queryset.published()
+        pages = page_queryset.filter(**filters).order_by("tree_id", "lft")
         ids = {}
         nodes = []
         first = True
diff --git a/cms/middleware/toolbar.py b/cms/middleware/toolbar.py
--- a/cms/middleware/toolbar.py
+++ b/cms/middleware/toolbar.py
@@ -5,6 +5,7 @@
 from cms.plugin_pool import plugin_pool
 from cms.toolbar.toolbar import CMSToolbar
 from cms.utils.compat.dj import force_unicode
+from menus.menu_pool import menu_pool
 from django.http import HttpResponse
 from django.template.loader import render_to_string
 from cms.utils.placeholder import get_toolbar_plugin_struct
@@ -46,10 +47,14 @@ def process_request(self, request):
         request.toolbar. Then call the request_hook on the toolbar.
         """
         if 'edit' in request.GET and not request.session.get('cms_edit', False):
+            if not request.session.get('cms_edit', False):
+                menu_pool.clear()
             request.session['cms_edit'] = True
             if request.session.get('cms_build', False):
                 request.session['cms_build'] = False
         if 'edit_off' in request.GET and request.session.get('cms_edit', True):
+            if request.session.get('cms_edit', True):
+                menu_pool.clear()
             request.session['cms_edit'] = False
             if request.session.get('cms_build', False):
                 request.session['cms_build'] = False


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

Issue:
RC1: Menu order
sometimes, when adding another menu and publishing it, the menu order gets weird.
when I unplublish all pages and than publish them in order, it works again.



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
@@ -1034,11 +1034,14 @@ def _publisher_save_public(self, obj):
 
         if not self.publisher_public_id:  # first time published
             # is there anybody on left side?
-            if public_prev_sib:
-                obj.insert_at(public_prev_sib, position='right', save=False)
+            if not self.parent_id:
+                obj.insert_at(self, position='right', save=False)
             else:
-                if public_parent:
-                    obj.insert_at(public_parent, position='first-child', save=False)
+                if public_prev_sib:
+                    obj.insert_at(public_prev_sib, position='right', save=False)
+                else:
+                    if public_parent:
+                        obj.insert_at(public_parent, position='first-child', save=False)
         else:
             # check if object was moved / structural tree change
             prev_public_sibling = obj.get_previous_filtered_sibling()


Test patch:
diff --git a/cms/tests/publisher.py b/cms/tests/publisher.py
--- a/cms/tests/publisher.py
+++ b/cms/tests/publisher.py
@@ -304,6 +304,27 @@ def test_publish_ordering(self):
                               ('pageB', 4, 5),
                               ('pageC', 6, 7)], public_titles)
 
+    def test_publish_ordering2(self):
+        page = self.create_page('parent', published=False)
+        pageA = self.create_page('pageA', published=False)
+        pageC = self.create_page('pageC', published=False, parent=pageA)
+        pageB = self.create_page('pageB', published=False, parent=pageA)
+        page = page.reload()
+        pageA.publish('en')
+        pageB.publish('en')
+        pageC.publish('en')
+        page.publish('en')
+
+        drafts = Page.objects.filter(publisher_is_draft=True).order_by('tree_id', 'lft')
+        publics = Page.objects.filter(publisher_is_draft=False).order_by('tree_id', 'lft')
+
+        x = 0
+        for draft in drafts:
+            self.assertEqual(draft.publisher_public_id, publics[x].pk)
+            x += 1
+
+
+
 
     def test_unpublish_unpublish(self):
         name = self._testMethodName
Repository: django-cms/django-cms

Issue:
Plugins not refreshed when reverting a page
When reverting a page to a previous version (from the toolbar; History > View History ... > Pick a version > Save) a message is shown saying "_The page "My Page" was reverted successfully. You may edit it again below._" but the plugins are not updated until refreshing the page manually.



Discussion:

Resolving patch:
diff --git a/cms/cms_toolbar.py b/cms/cms_toolbar.py
--- a/cms/cms_toolbar.py
+++ b/cms/cms_toolbar.py
@@ -289,15 +289,16 @@ def add_page_menu(self):
             nav_title = _("Display in navigation")
         nav_action = reverse('admin:cms_page_change_innavigation', args=(self.page.pk,))
         current_page_menu.add_ajax_item(nav_title, action=nav_action, disabled=not_edit_mode)
-        # publisher
-        if self.title.published:
-            publish_title = _('Unpublish page')
-            publish_url = reverse('admin:cms_page_unpublish', args=(self.page.pk, self.current_lang))
-        else:
-            publish_title = _('Publish page')
-            publish_url = reverse('admin:cms_page_publish_page', args=(self.page.pk, self.current_lang))
+        if self.title:
+            # publisher
+            if self.title.published:
+                publish_title = _('Unpublish page')
+                publish_url = reverse('admin:cms_page_unpublish', args=(self.page.pk, self.current_lang))
+            else:
+                publish_title = _('Publish page')
+                publish_url = reverse('admin:cms_page_publish_page', args=(self.page.pk, self.current_lang))
 
-        current_page_menu.add_ajax_item(publish_title, action=publish_url, disabled=not_edit_mode)
+            current_page_menu.add_ajax_item(publish_title, action=publish_url, disabled=not_edit_mode)
         current_page_menu.add_break(PAGE_MENU_THIRD_BREAK)
         # delete
         delete_url = reverse('admin:cms_page_delete', args=(self.page.pk,))


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

Issue:
unfolding subitem in page tree leaves them without title
See attached file. When I am unfolding a branch of the tree, the page names are not there. Upon reloading the page, all the unfolded branches contain their page names. 
When inspecting the DOM, the a tag is there, but no content.

![branches-without-title](https://f.cloud.github.com/assets/5563460/2175618/c73c3124-95c2-11e3-998c-5d45a7b691cd.png)



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
@@ -729,7 +729,7 @@ def validate_title(title):
 
         if not hasattr(self, 'title_cache'):
             self.title_cache = {}
-            for title in self.title_set:
+            for title in self.title_set.all():
                 self.title_cache[title.language] = title
         if not language in self.title_cache or not validate_title(self.title_cache.get(language, EmptyTitle(language))):
             fallback_langs = i18n.get_fallback_languages(language)


Test patch: