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

Issue:
show_menu_below_id fails to render menu using an id outside of current softroot path.
Given a menu structure of:

/about
/whole-new-section (softroot)
/legal - (id:legal)
  --terms
  --disclaimer

In base template, an attempt to display links under the 'legal' reverse_id renders on /about, but not on the /whole-new-section softroot. 

```
{% show_menu_below_id "legal" %}
```

@evildmp 



Discussion:

Resolving patch:
diff --git a/cms/menu.py b/cms/menu.py
--- a/cms/menu.py
+++ b/cms/menu.py
@@ -399,7 +399,8 @@ class SoftRootCutter(Modifier):
 
     def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb):
         # only apply this modifier if we're pre-cut (since what we do is cut)
-        if post_cut:
+        # or if no id argument is provided, indicating {% show_menu_below_id %}
+        if post_cut or root_id:
             return nodes
         selected = None
         root_nodes = []


Test patch:
diff --git a/cms/tests/menu.py b/cms/tests/menu.py
--- a/cms/tests/menu.py
+++ b/cms/tests/menu.py
@@ -881,6 +881,36 @@ def test_not_in_navigation_num_queries(self):
                 tpl = Template("{% load menu_tags %}{% show_menu_below_id 'a' 0 100 100 100 %}")
                 tpl.render(context)
 
+    def test_menu_in_soft_root(self):
+        """
+        Test for issue 3504
+        
+        Build the following tree:
+        
+            A
+            |-B
+            C (soft_root)
+        """
+        a = create_page('A', 'nav_playground.html', 'en', published=True,
+                        in_navigation=True, reverse_id='a')
+        b = create_page('B', 'nav_playground.html', 'en', parent=a,
+                       published=True, in_navigation=True)
+        c = create_page('C', 'nav_playground.html', 'en', published=True, 
+                        in_navigation=True, soft_root=True)
+        context = self.get_context(a.get_absolute_url())
+        tpl = Template("{% load menu_tags %}{% show_menu_below_id 'a' %}")
+        tpl.render(context)
+        nodes = context['children']
+        self.assertEqual(len(nodes), 1)
+        node = nodes[0]
+        self.assertEqual(node.id, b.publisher_public.id)
+        context = self.get_context(c.get_absolute_url())
+        tpl = Template("{% load menu_tags %}{% show_menu_below_id 'a' %}")
+        tpl.render(context)
+        nodes = context['children']
+        self.assertEqual(len(nodes), 1)
+        node = nodes[0]
+        self.assertEqual(node.id, b.publisher_public.id)
 
 class ViewPermissionMenuTests(SettingsOverrideTestCase):
     settings_overrides = {
Repository: django-cms/django-cms

Issue:
CMSSitemaps display overlapping URLs when multiple sites exist
Adding a sitemap [per the guide](http://docs.django-cms.org/en/latest/advanced/sitemap.html) ignores the Sites framework, giving URLs for all Sites.

So if I have the sites:
- example.com
- foo.com
- bar.com

a sitemap at example.com/en/sitemap.xml would display URLs consisting of the domain example.com but with pages from foo.com and bar.com.



Discussion:

Resolving patch:
diff --git a/cms/sitemaps/cms_sitemap.py b/cms/sitemaps/cms_sitemap.py
--- a/cms/sitemaps/cms_sitemap.py
+++ b/cms/sitemaps/cms_sitemap.py
@@ -1,6 +1,7 @@
 # -*- coding: utf-8 -*-
 
 from django.contrib.sitemaps import Sitemap
+from django.contrib.sites.models import Site
 from django.db.models import Q
 from django.utils import translation
 
@@ -47,7 +48,8 @@ def items(self):
         #
         all_titles = Title.objects.public().filter(
             Q(redirect='') | Q(redirect__isnull=True),
-            page__login_required=False
+            page__login_required=False,
+            page__site=Site.objects.get_current(),
         ).order_by('page__path')
         return all_titles
 


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

Issue:
Monkey patching of get_models breaks
The monkey patch doesn't work, @yakky knows what it was for.

```
TypeError: get_models_patched() takes at least 1 argument (0 given)
```

Firstly, it doesn't work. I'm not into why partial() is used here. Secondly, it doesn't render any return value.

PR coming in......



Discussion:

Resolving patch:
diff --git a/cms/utils/setup.py b/cms/utils/setup.py
--- a/cms/utils/setup.py
+++ b/cms/utils/setup.py
@@ -1,5 +1,3 @@
-from functools import partial
-
 from django.conf import settings
 from django.core.exceptions import ImproperlyConfigured
 
@@ -37,15 +35,14 @@ def setup():
         # requires paching the AppCache. 1.7 provides a cleaner way to handle
         # this in AppConfig and thus the patching is left for older version only
         from django.db.models import loading
-
-        def get_models_patched(self, app_mod=None, include_auto_created=False,
-                               include_deferred=False, only_installed=True):
-            loading.AppCache.get_models(self, app_mod, include_auto_created,
-                                        include_deferred, only_installed)
+        old_get_models = loading.AppCache.get_models
+        
+        def get_models_patched(self, **kwargs):
+            ret_value = old_get_models(self, **kwargs)
             from cms.plugin_pool import plugin_pool
             plugin_pool.set_plugin_meta()
+            return ret_value
 
-        loading.cache.get_models = get_models_patched
-        loading.get_models = partial(get_models_patched, loading.cache)
+        loading.AppCache.get_models = get_models_patched
     validate_dependencies()
     validate_settings()


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

Issue:
Incorrect preview URL after changing in menu state
When change "in menu" state from pages list generated URL contains `None` instead of a language code.

Example:
Instead of `103/bg/preview/` the `href` attribute is `103/None/preview/`

Steps to reproduce:
1. Open pages list in navigation.
2. Click on the icon in the "Menu" column to change the state of a given page.
3. Click on the name of the page

This will open a 404 page with URL similar to this: `http://localhost:8000/admin/cms/page/<pageid>/None/preview`



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
@@ -1323,7 +1323,8 @@ def change_innavigation(self, request, page_id):
         page = get_object_or_404(Page, pk=page_id)
         if page.has_change_permission(request):
             page.toggle_in_navigation()
-            return admin_utils.render_admin_menu_item(request, page)
+            language = request.GET.get('language') or get_language_from_request(request)
+            return admin_utils.render_admin_menu_item(request, page, language=language)
         return HttpResponseForbidden(force_unicode(_("You do not have permission to change this page's in_navigation status")))
 
     def descendants(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
@@ -659,6 +659,9 @@ def test_change_innavigation(self):
             request = self.get_request(post_data={'no': 'data'})
             old = page.in_navigation
             response = self.admin_class.change_innavigation(request, page.pk)
+            # These asserts are for #3589
+            self.assertContains(response, 'lang="en"')
+            self.assertContains(response, './%s/en/preview/' % page.pk)
             self.assertEqual(response.status_code, 200)
             page = self.reload(page)
             self.assertEqual(old, not page.in_navigation)
Repository: django-cms/django-cms

Issue:
Fixes missing add_sideframe_button method.
When trying to use the `CMSToolbar.add_sideframe_button()` method an exception is thrown because `add_sideframe_button()` is not implemented on `ButtonList()`.  This implements the missing method based on the pattern of the other methods in `ButtonList()`.



Discussion:

Resolving patch:
diff --git a/cms/toolbar/items.py b/cms/toolbar/items.py
--- a/cms/toolbar/items.py
+++ b/cms/toolbar/items.py
@@ -451,6 +451,16 @@ def add_modal_button(self, name, url, active=False, disabled=False, extra_classe
         self.buttons.append(item)
         return item
 
+    def add_sideframe_button(self, name, url, active=False, disabled=False, extra_classes=None, on_close=None):
+        item = SideframeButton(name, url,
+                      active=active,
+                      disabled=disabled,
+                      extra_classes=extra_classes,
+                      on_close=on_close,
+        )
+        self.buttons.append(item)
+        return item
+
     def get_context(self):
         return {
             'buttons': self.buttons,


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

Issue:
urls no longer take into account setting of APPEND_SLASH
This commit: https://github.com/divio/django-cms/commit/c2cd800b4ea9038b027b1079ac3d6cc8914005c7

seems to have accidentally made the `'pages-details-by-slug'` regex the same regardless of what `APPEND_SLASH` is set to. Presumably this will re-introduce whatever problem was in this issue: https://github.com/divio/django-cms/issues/284



Discussion:

Resolving patch:
diff --git a/cms/urls.py b/cms/urls.py
--- a/cms/urls.py
+++ b/cms/urls.py
@@ -8,10 +8,11 @@
 
 # This is a constant, really, but must live here due to import order
 SLUG_REGEXP = '[0-9A-Za-z-_.//]+'
+
 if settings.APPEND_SLASH:
     regexp = r'^(?P<slug>%s)/$' % SLUG_REGEXP
 else:
-    regexp = r'^(?P<slug>%s)/$' % SLUG_REGEXP
+    regexp = r'^(?P<slug>%s)$' % SLUG_REGEXP
 
 if apphook_pool.get_apphooks():
     # If there are some application urls, use special resolver,


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

Issue:
Get rid of 'ugly hack' for mptt
According to [this line](https://github.com/divio/django-cms/blob/develop/cms/models/pluginmodel.py#L229), we still have an 'ugly hack' in the code to address an issue with mptt. If this problem was solved by the move to django-treebeard, let's lose this technical debt.



Discussion:
There is another instance in the [page model save method](https://github.com/divio/django-cms/blob/develop/cms/models/pagemodel.py#L443)


Resolving patch:
diff --git a/cms/models/pluginmodel.py b/cms/models/pluginmodel.py
--- a/cms/models/pluginmodel.py
+++ b/cms/models/pluginmodel.py
@@ -226,19 +226,16 @@ def get_instance_icon_alt(self):
         return force_text(plugin.icon_alt(instance)) if instance else u''
 
     def save(self, no_signals=False, *args, **kwargs):
-        if no_signals:  # ugly hack because of mptt
-            super(CMSPlugin, self).save_base()
-        else:
-            if not self.depth:
-                if self.parent_id or self.parent:
-                    self.parent.add_child(instance=self)
-                else:
-                    if not self.position and not self.position == 0:
-                        self.position == CMSPlugin.objects.filter(parent__isnull=True,
-                                                                  placeholder_id=self.placeholder_id).count()
-                    self.add_root(instance=self)
-                return
-            super(CMSPlugin, self).save()
+        if not self.depth:
+            if self.parent_id or self.parent:
+                self.parent.add_child(instance=self)
+            else:
+                if not self.position and not self.position == 0:
+                    self.position == CMSPlugin.objects.filter(parent__isnull=True,
+                                                              placeholder_id=self.placeholder_id).count()
+                self.add_root(instance=self)
+            return
+        super(CMSPlugin, self).save()
 
     def reload(self):
         return CMSPlugin.objects.get(pk=self.pk)


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

Issue:
TypeError: 'dict_keys' object does not support indexing
I get a "TypeError: 'dict_keys' object does not support indexing" in "cms/models/pagemodel.py", line 819, in get_admin_tree_title":

![error](https://cloud.githubusercontent.com/assets/71315/6037953/27e3778c-ac59-11e4-8da1-07d9bffe7a4c.PNG)

Maybe this has been fixed, because the current version looks completely different: https://github.com/divio/django-cms/blob/develop/cms/models/pagemodel.py

His error happens with:
Django  1.7.4
django CMS  3.0.9



Discussion:
When does this exception pops up? Which cache backend are you using?

cache backend: `django.core.cache.backends.locmem.LocMemCache`

Seems that this happens if no Title exist.

Think `language = self.title_cache.keys()[0]` is just not python 3 compatible.
Fix: `language = list(self.title_cache.keys())[0]`

Which operation triggers the error?

Access the admin pages.


Resolving patch:
diff --git a/cms/models/pagemodel.py b/cms/models/pagemodel.py
--- a/cms/models/pagemodel.py
+++ b/cms/models/pagemodel.py
@@ -816,7 +816,7 @@ def validate_title(title):
                     language = lang
             if not found:
                 if self.title_cache.keys():
-                    language = self.title_cache.keys()[0]
+                    language = list(self.title_cache.keys())[0]
                 else:
                     language = None
         if not language:


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

Issue:
{% placeholder %} still has a deprecation warning for width
Looking the releases, the [width deprecation warning](https://github.com/divio/django-cms/blob/2be1893021650b15d1b5dbbf07b55a85b12e95ea/cms/templatetags/cms_tags.py#L296) still exists, which has been there since [2.1.4](https://github.com/divio/django-cms/blob/6ffb9988bb4fc8feb58587ca12e4daaf5f92a6c4/cms/templatetags/cms_tags.py#L206) three years ago, or four releases (2.2, 2.3, 2.4, 3.x). Surely that's more than long enough.



Discussion:
Yep, you're right.
@digi604 how about removing it in 3.1?


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
@@ -273,8 +273,6 @@ class Placeholder(Tag):
 
     Keyword arguments:
     name -- the name of the placeholder
-    width -- additional width attribute (integer) which gets added to the plugin context
-    (deprecated, use `{% with 320 as width %}{% placeholder "foo"}{% endwith %}`)
     inherit -- optional argument which if given will result in inheriting
         the content of the placeholder with the same name on parent pages
     or -- optional argument which if given will make the template tag a block


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

Issue:
Non-existent method Page.get_title_object
If you specify a language to `ExtensionToolbar.get_title_extension_admin`, it calls `Page.get_title_object`, which doesn’t exist.  This should probably be `Page.get_title_obj` instead.



Discussion:

Resolving patch:
diff --git a/cms/extensions/toolbar.py b/cms/extensions/toolbar.py
--- a/cms/extensions/toolbar.py
+++ b/cms/extensions/toolbar.py
@@ -123,7 +123,7 @@ def get_title_extension_admin(self, language=None):
         page = self._get_page()
         urls = []
         if language:
-            titles = page.get_title_object(language),
+            titles = page.get_title_obj(language),
         else:
             titles = page.title_set.all()
         # Titles


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

Issue:
Frontend glitch for get_extra_local_plugin_menu_items() 
I'm trying to add an additional item to content menu for a custom plugin. So I added this to my plugin.

```
    def get_extra_local_plugin_menu_items(self, request, plugin):
        return [
            PluginMenuItem(
                _('Preview Wrapper'),
                admin_reverse('responsive_wrapper_preview_mode'),
                data={
                    'plugin_id': plugin.pk,
                    'csrfmiddlewaretoken': get_token(request),
                },
            )
        ]
```

However the `PluginMenuItem` is not displayed :-( 

![screen shot 2014-11-30 at 23 53 51](https://cloud.githubusercontent.com/assets/1264089/5239937/3e927c6c-78ec-11e4-99af-533dcf6ce249.png)

When I inspected the element, it looks like the generated HTML is incorrect. 

```
<div class="cms_submenu-item">
    <a href="" data-rel="ajax" data-on-success="REFRESH_PAGE"></a>
</div> 
```

This is how it should look like:

```
<div class="cms_submenu-item">
    <a href="/manage/cms/page/plugin/responsive_wrapper_plugin/preview/"  
        data-rel="ajax" data-post="..."  data-on-success="REFRESH_PAGE">
        Preview Wrapper
    </a>
</div>
```

*\* `data-post` content has been omitted.

Screenshot:

![screen shot 2014-12-01 at 00 04 52](https://cloud.githubusercontent.com/assets/1264089/5239971/bc08fc38-78ed-11e4-8977-d15c7ee5c2b3.png)

I was able to get the 'PluginMenuItem' to show up using:

```
def get_extra_global_plugin_menu_items(self, request, plugin):
    [...]
```

But this means `PluginMenuItem` will be added to every plugin context menu.

Am I doing something wrong?



Discussion:
Completely able to reproduce. Now looking for the issue...


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
@@ -439,7 +439,7 @@ def get_context(self, context, obj):
             plugin_class_inst = plugin.get_plugin_class_instance()
             item = plugin_class_inst.get_extra_local_plugin_menu_items(request, plugin)
             if item:
-                items.append(item)
+                items += item
             plugin_classes = plugin_pool.get_all_plugins()
             for plugin_class in plugin_classes:
                 plugin_class_inst = plugin_class()


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

Issue:
Move the South requirement to an extra install in setup.py
With Django 1.7 removing the dependency on South. Perhaps it is time to move South to an extra require.

Like so:

```
setup(
    author="Patrick Lauber",
    author_email="digi@treepy.com",
    name='django-cms',
    version=cms.__version__,
    description='An Advanced Django CMS',
    long_description=open(os.path.join(os.path.dirname(__file__), 'README.rst')).read(),
    url='https://www.django-cms.org/',
    license='BSD License',
    platforms=['OS Independent'],
    classifiers=CLASSIFIERS,
    install_requires=[
        'Django>=1.4',
        'django-classy-tags>=0.5',
        'html5lib',
        'django-treebeard==2.0',
        'django-sekizai>=0.7',
        'djangocms-admin-style'
    ],
    tests_require=[
        'django-reversion==1.8.2',
        'Pillow==2.5.3',
        'Sphinx==1.2.2',
        'Jinja2==2.7.3',
        'Pygments==1.6',
        'dj-database-url==0.3.0',
        'django-hvad',
        'djangocms-text-ckeditor>=2.1.1',
        'djangocms-column',
        'djangocms-style',
    ],
    extras_require = {
        'south': ['south>=0.7.2'],
    },
    packages=find_packages(exclude=["project", "project.*"]),
    include_package_data=True,
    zip_safe=False,
    test_suite='runtests.main',
)
```

Users will install via:

`pip install django-cms[south]==3.0.5`
or in their requirement.txt file
`django-cms[south]==3.0.5`



Discussion:
Looks like a good idea.
This must be properly documented in the documentation, though, as newcomers may be confused.
@evildmp: will this make it harder to properly install django-cms for first-time users?

I think it could make it slightly more difficult to install, although I'd think we should encourage newbies to use Django 1.7 anyway.


Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -32,14 +32,16 @@
     platforms=['OS Independent'],
     classifiers=CLASSIFIERS,
     install_requires=[
-        'Django>=1.4',
+        'Django>=1.6',
         'django-classy-tags>=0.5',
-        'south>=0.7.2',
         'html5lib',
         'django-treebeard==3.0',
         'django-sekizai>=0.7',
         'djangocms-admin-style'
     ],
+    extras_require={
+        'south': ['south>=1.0.0'],
+    },
     packages=find_packages(exclude=["project", "project.*"]),
     include_package_data=True,
     zip_safe=False,


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

Issue:
PageField-Choices only available on first Inline
When using the PageField() in a model which has a ForeignKey to another model, the available Page-Choices are only available on the first row in the inline-admin.

So I have for example the following models:

```
class NewsEntry(models.Model):
    title = models.CharField(verbose_name='Titel', max_length=255)
    slug = models.SlugField(verbose_name='Slug', help_text='Dient zur Bildung der URL', unique=True)
    lead = models.TextField(verbose_name='Lead')
    date = models.DateTimeField(verbose_name='Datum')
    read_amount = models.IntegerField(verbose_name='Anzahl gelesen', default=0, editable=False)


class NewsEntryLink(models.Model):
    title = models.CharField(max_length=255, verbose_name='Titel')
    entry = models.ForeignKey(NewsEntry, verbose_name='News-Eintrag', related_name='links')
    page_link = PageField(verbose_name='Seite', blank=True, null=True, help_text=u'Hat höhere Priorität gegenüber dem externen Link.')
    external_link = models.URLField(verbose_name='Externer Link', blank=True, null=True)
```

And defined them for admin with InlineAdmin:

```
class NewsEntryLinkAdmin(admin.TabularInline):
    model = NewsEntryLink
    extra = 1

class NewsEntryAdmin(admin.ModelAdmin):
    inlines = [NewsEntryLinkAdmin, ]


admin.site.register(NewsEntry, NewsEntryAdmin)
```

With this, it's not possible to add more than one related data set, because the available pages are only listed in the first row of the inline admin.

There's also a js-error thrown when opening the add-new-item page:

```
Uncaught TypeError: undefined is not a function
```



Discussion:
Can't reproduce, neither on develop or on 3.0.10
Could you provide more information about the setup? Do you use any custom admin skin?

I do use a custom admin skin, namely djangocms-admin-style v0.2.5
But it doesn't make a difference if I deactivate this app.

Here are some other of my package-versions, I'm using:

```
django = 1.5.12
django_cms = 3.0.10
django_hvad = 1.0.0
django_mptt = 0.6.1
django-pipeline = 1.3.9
django-polymorphic = 0.6.1
```

Do you need any further information?

Thanks, I've been able to reproduce this in django 1.5 (likely due to outdated jquery version)


Resolving patch:
diff --git a/cms/forms/widgets.py b/cms/forms/widgets.py
--- a/cms/forms/widgets.py
+++ b/cms/forms/widgets.py
@@ -100,10 +100,10 @@ def render(self, name, value, attrs=None):
     };
     var handlePageChange = function(page_id) {
         if (page_id) {
-            $("#id_%(name)s_2 option").prop('selected', false);
-            $("#id_%(name)s_2 option[value=" + page_id + "]").prop('selected', true);
+            $("#id_%(name)s_2 option").attr('selected', false);
+            $("#id_%(name)s_2 option[value=" + page_id + "]").attr('selected', true);
         } else {
-            $("#id_%(name)s_2 option[value=]").prop('selected', true);
+            $("#id_%(name)s_2 option[value=]").attr('selected', true);
         };
     };
     $("#id_%(name)s_0").change(function(){


Test patch: