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

Issue:
ToolbarMiddleware prevents views from adding custom upload handlers.
The ToolbarMiddle accesses request.POST, which causes the request data and/or files to be parsed, and prevents any views in the CMS from being able to modify the upload handlers for the request as the request body has already been parsed, and and request._files has already been populated.

Middleware that accesses request.POST should generally be considered a bug - Eg see Jacob K-M's comment on this ticket: https://code.djangoproject.com/ticket/613

I'm not quite sure of the right way to fix this.  It's probably fine for the middleware to access .POST if either:
1. If we can be sure at the point that it's been accessed that no view behind the middleware is going to need to use custom upload handlers (or custom parsing of the request body).
2. There's a mechanism for allowing the view to override or defer the usual behavior (eg as the csrfmiddleware does)



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
@@ -219,11 +219,12 @@ def _request_hook_get(self):
         
     def _request_hook_post(self):
         # login hook
-        login_form = CMSToolbarLoginForm(self.request.POST)
-        if login_form.is_valid():
-            username = login_form.cleaned_data['cms_username']
-            password = login_form.cleaned_data['cms_password']
-            user = authenticate(username=username, password=password)
-            if user:
-                login(self.request, user)
-                self.init()
+        if 'cms-toolbar-login' in self.request.GET:
+            login_form = CMSToolbarLoginForm(self.request.POST)
+            if login_form.is_valid():
+                username = login_form.cleaned_data['cms_username']
+                password = login_form.cleaned_data['cms_password']
+                user = authenticate(username=username, password=password)
+                if user:
+                    login(self.request, user)
+                    self.init()


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

Issue:
2.2 Trove classifier is incorrect
The current release added Development Status to the PyPI Trove categories, but it remains `'Development Status :: 4 - Beta'`  which it had during the RCs - I suspect that it should now be `'Development Status :: 5 - Production/Stable'`

I don't have a git clone in front of me, so I can't open a pull request for it directly, at the moment.



Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -4,7 +4,7 @@
 
         
 CLASSIFIERS = [
-    'Development Status :: 4 - Beta',
+    'Development Status :: 5 - Production/Stable',
     'Environment :: Web Environment',
     'Framework :: Django',
     'Intended Audience :: Developers',


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

Issue:
two infinite loops
One can argue that it is a case of bad use of the framework, but as it is supposed to be used by regular users (not computer nerds) i think these are still issues.
- when i select the page i am editing in a "Inherit plugins from page" plugin.
- when i redirect a page to itself (in the "redirect" field in advanced settings).

there may be more, those 2 are the only ones my user could "find out".

I think the page shouldn't be in the options in the first case.
The second is maybe a bit trickier, but a form error would be nice.



Discussion:
I think it's a very valid complaint.

I could reproduce the 'redirect' issue but not the 'inherit plugins from page' issue.


Resolving patch:
diff --git a/cms/views.py b/cms/views.py
--- a/cms/views.py
+++ b/cms/views.py
@@ -80,9 +80,16 @@ def details(request, slug):
     if redirect_url:
         if (settings.i18n_installed and redirect_url[0] == "/"
             and not redirect_url.startswith('/%s/' % current_language)):
+            # add language prefix to url
             redirect_url = "/%s/%s" % (current_language, redirect_url.lstrip("/"))
-        # add language prefix to url
-        return HttpResponseRedirect(redirect_url)
+        # prevent redirect to self
+        own_urls = [
+            'http%s://%s%s' % ('s' if request.is_secure() else '', request.get_host(), request.path),
+            '/%s%s' % (current_language, request.path),
+            request.path,
+        ]
+        if redirect_url not in own_urls:
+            return HttpResponseRedirect(redirect_url)
     
     # permission checks
     if page.login_required and not request.user.is_authenticated():


Test patch:
diff --git a/cms/tests/views.py b/cms/tests/views.py
--- a/cms/tests/views.py
+++ b/cms/tests/views.py
@@ -6,7 +6,7 @@
 from cms.views import _handle_no_page, details
 from django.conf import settings
 from django.core.urlresolvers import clear_url_caches
-from django.http import Http404
+from django.http import Http404, HttpResponse
 import sys
 
 
@@ -101,6 +101,22 @@ def test_internal_forced_redirect(self):
         response = details(request, url.strip('/'))
         self.assertEqual(response.status_code, 302)
         self.assertEqual(response['Location'], redirect_three)
+        
+    def test_redirect_to_self(self):
+        one = create_page("one", "nav_playground.html", "en", published=True,
+                          redirect='/')
+        url = one.get_absolute_url()
+        request = self.get_request(url)
+        response = details(request, url.strip('/'))
+        self.assertEqual(response.status_code, HttpResponse.status_code)
+        
+    def test_redirect_to_self_with_host(self):
+        one = create_page("one", "nav_playground.html", "en", published=True,
+                          redirect='http://testserver/')
+        url = one.get_absolute_url()
+        request = self.get_request(url)
+        response = details(request, url.strip('/'))
+        self.assertEqual(response.status_code, HttpResponse.status_code)
     
     def test_login_required(self):
         create_page("page", "nav_playground.html", "en", published=True,
Repository: django-cms/django-cms

Issue:
Placeholders name with spaces break the cache 
In one of our apps we have placeholder names with spaces, as far as I am concern this is a valid use case.

The placeholder template tag is smart enough to understand this case, however it is missing to escape one part of the name. 

In the following line

https://github.com/divio/django-cms/blob/develop/cms/templatetags/cms_tags.py#L334

If the variable "placeholder_name" contains spaces it is not escaped. A simple change to 

```
    cache_key = _get_cache_key('_show_placeholder_for_page', page_lookup, lang, site_id)+'_placeholder:'+_clean_key(placeholder_name)
```

fixed it although a better solution could be found.

The root problem here is that it's creating keys that are not compatible with memcache as it demands no spaces in the key name.



Discussion:
That looks very sensible.

Would you like to open a pull request, so that you get the merits of it and end up in our AUTHORS file?
A short test would be most welcome too. 

If you don't have time or don't want to, please post here and we'll see what we can do.

Thanks for reporting,
- Chris

I can definitely fork and send, although i"ll have to look at the test. Shouldn't be a problem either.

I just wanted to be certain my fix was good.

PS: I'm already in AUTHORS :) 


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
@@ -331,7 +331,8 @@ def _show_placeholder_for_page(context, placeholder_name, page_lookup, lang=None
     content = None
 
     if cache_result:
-        cache_key = _get_cache_key('_show_placeholder_for_page', page_lookup, lang, site_id)+'_placeholder:'+placeholder_name
+        base_key = _get_cache_key('_show_placeholder_for_page', page_lookup, lang, site_id)
+        cache_key = _clean_key('%s_placeholder:%s' % (base_key, placeholder_name))
         content = cache.get(cache_key)
 
     if not content:


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

Issue:
Language chooser cannot switch language for untranslated page
Language chooser uses page_language_url from menus.templatetags. The final except solution for this template tag is to provide no URL if no translation could be found. For untranslated django-cms pages, this blocks a visitor from switching his language. I would rather redirect those users to the translated homepage then to block them from switching.

The bug arises from [here](https://github.com/divio/django-cms/blob/develop/menus/templatetags/menu_tags.py#L375). I created a temporary workaround by changing that line to this:

```
# no localized path/slug. 
url = "/" + lang + "/"
```



Discussion:
ojii solved this issue for me by working around the default templatetag. If django-cms would include his workaround, that is saving the page url to a variable, would allow me to create a custom template. See his [answer](http://stackoverflow.com/questions/8016169/how-to-link-to-languages-homepage-for-untranslated-page-in-django-cms/8124011#8124011) on stackoverflow.

I just stumbled upon this problem after setting CMS_HIDE_UNTRANSLATED to True. According to the docs I would expect, that it redirects to the start page, see here http://docs.django-cms.org/en/latest/advanced/i18n.html#cms-hide-untranslated


Resolving patch:
diff --git a/menus/templatetags/menu_tags.py b/menus/templatetags/menu_tags.py
--- a/menus/templatetags/menu_tags.py
+++ b/menus/templatetags/menu_tags.py
@@ -371,7 +371,13 @@ def get_context(self, context, lang):
                 url = page.get_absolute_url(language=lang, fallback=False)
                 url = "/" + lang + url
             except:
-                # no localized path/slug. 
-                url = ''
+                # no localized path/slug
+                if settings.CMS_HIDE_UNTRANSLATED:
+                    # redirect to root url if CMS_HIDE_UNTRANSLATED
+                    url = '/' + lang + '/'
+                else:
+                    # If untranslated pages are shown, this will not redirect
+                    # at all.
+                    url = ''
         return {'content':url}
 register.tag(PageLanguageUrl)


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

Issue:
Document Moderation deprecation



Discussion:

Resolving patch:
diff --git a/cms/conf/__init__.py b/cms/conf/__init__.py
--- a/cms/conf/__init__.py
+++ b/cms/conf/__init__.py
@@ -18,6 +18,9 @@ def patch_settings():
     if getattr(settings, 'CMS_FLAT_URLS', False):
         warnings.warn("CMS_FLAT_URLS are deprecated and will be removed in django CMS 2.4!", DeprecationWarning)
     
+    if getattr(settings, 'CMS_MODERATOR', False):
+        warnings.warn("CMS_MODERATOR will be removed and replaced in django CMS 2.4!", DeprecationWarning)
+    
     from cms.conf import global_settings
     # patch settings
     


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

Issue:
Extra leading slash in reverse()'d URLs with 'home' page apphook.
If an app is hooked to the 'home' page, then for URL patterns within that app, the URL returned by `django.core.urlresolvers.reverse` will include an extra leading forward slash.

Example:

```
>>> from django.core.urlresolvers import reverse
>>> reverse('rss')
'//.rss'
>>> reverse('rss', urlconf='main.urls')
'/.rss'
```



Discussion:

Resolving patch:
diff --git a/cms/appresolver.py b/cms/appresolver.py
--- a/cms/appresolver.py
+++ b/cms/appresolver.py
@@ -124,7 +124,7 @@ def get_patterns_for_title(path, title):
     app = apphook_pool.get_apphook(title.application_urls)
     patterns = []
     for pattern_list in get_app_urls(app.urls):
-        if not path.endswith('/'):
+        if path and not path.endswith('/'):
             path += '/'
         page_id = title.page.id
         patterns += recurse_patterns(path, pattern_list, page_id)


Test patch:
diff --git a/cms/tests/apphooks.py b/cms/tests/apphooks.py
--- a/cms/tests/apphooks.py
+++ b/cms/tests/apphooks.py
@@ -84,6 +84,19 @@ def test_apphook_on_root(self):
             self.assertTemplateUsed(response, 'nav_playground.html')
 
             apphook_pool.clear()
+
+    def test_apphook_on_root_reverse(self):
+        with SettingsOverride(ROOT_URLCONF='cms.test_utils.project.urls_for_apphook_tests'):
+            apphook_pool.clear()
+            superuser = User.objects.create_superuser('admin', 'admin@admin.com', 'admin')
+            page = create_page("apphooked-page", "nav_playground.html", "en",
+                created_by=superuser, published=True, apphook="SampleApp")
+            create_title("de", "aphooked-page-de", page, apphook="SampleApp")
+            self.assertTrue(page.publish())
+
+            self.assertFalse(reverse('sample-settings').startswith('//'))
+
+            apphook_pool.clear()
     
     def test_get_page_for_apphook(self):
Repository: django-cms/django-cms

Issue:
Labels missing in admin for cms.plugins.text
I'm using a model that is a subclass of  cms.plugins.text.models.AbstractText but in the admin the labels for all fields have disappeared. I think there should be a

```
{{ field.label_tag }}
```

at the appropriate place in /cms/plugins/text/templates/cms/plugins/text_plugin_fieldset.html (also compare with /django/contrib/admin/templates/admin/includes/fieldset.html ). The labels indeed appear when I add that piece of code.



Discussion:
Is there a reason why this duplicate fieldset file is used?

By changing text_plugin_change_form.html to use the original admin/includes/fieldset.html, everything appears to work fine, including the form error messages.

not really on the top of the priority list. if this is important to you, maybe open a pull request so we can discuss this further.

As ugly as the default text plugin appears with the `{{ field.label_tag }}` reapplied, @svisser has a point.
I have a custom template to overcome this when extending text plugin.
The pull request serves only as a discussion basis.
As far as I can see there are three _real_ solutions
1) Let user easily overrides default template in TextPlugin
2) Have an attribute in TextPlugin to switch from one behavior to another
3) Keep the things as they are :) and document this in the Custom Plugin section of the docs


Resolving patch:
diff --git a/cms/utils/admin.py b/cms/utils/admin.py
--- a/cms/utils/admin.py
+++ b/cms/utils/admin.py
@@ -96,4 +96,5 @@ def render_admin_menu_item(request, page, template=None):
     
     filtered = 'filtered' in request.REQUEST
     context.update(get_admin_menu_item_context(request, page, filtered))
-    return render_to_response(template, context)
+    # add mimetype to help out IE
+    return render_to_response(template, context, mimetype="text/html; charset=utf-8")


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

Issue:
endless redirect if browser language is not a cms language
This occurs if the Browser `Accept-Language` is not one of the languages configured for the cms as active language. And djangos [`get_language_from_request`](https://github.com/django/django/blob/1.4.2/django/utils/translation/trans_real.py#L366) was called previously with something like `SettingsOverride` ([here](https://github.com/divio/django-cms/blob/49c8d4c2905243fb33890f526c334bd39bb350f0/cms/views.py#L60)) where `LANGUAGES` is overridden with a language we don't want. Django optimises with [a cache in a global object](https://github.com/django/django/blob/1.4.2/django/utils/translation/trans_real.py#L29) that then will return languages actually not in `LANGUAGES`.

I have a patch. Pull request will follow.



Discussion:

Resolving patch:
diff --git a/cms/views.py b/cms/views.py
--- a/cms/views.py
+++ b/cms/views.py
@@ -60,9 +60,10 @@ def details(request, slug):
                 with SettingsOverride(LANGUAGES=languages, LANGUAGE_CODE=languages[0][0]):
                     #get supported language
                     new_language = translation.get_language_from_request(request)
-                    with force_language(new_language):
-                        pages_root = reverse('pages-root')
-                        return HttpResponseRedirect(pages_root + attrs)
+                    if new_language in get_public_languages():
+                        with force_language(new_language):
+                            pages_root = reverse('pages-root')
+                            return HttpResponseRedirect(pages_root + attrs)
             else:
                 _handle_no_page(request, slug)
         else:


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

Issue:
plugin-list-holder doesn't properly display plugin after editing and canceling
Steps to reproduce:
1. Create a link plugin and give it the name 'foobar'
2. Notice the plugin's name in the plugin-list-holder (html class):   Link [ foobar ]
3. Open the edit dialog
4. Click cancel

Expected:
Plugin's name in the plugin-list-holder continues to be:   Link [ foobar ]

Actual:
Plugin's name in the plugin-list-holder continues to be:   Link [ 6 ]

(where 6 appears to be the plugin's PK)



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
@@ -1295,7 +1295,6 @@ def edit_plugin(self, request, plugin_id):
                 'CMS_MEDIA_URL': get_cms_setting('MEDIA_URL'),
                 'plugin': cms_plugin,
                 'is_popup': True,
-                'name': unicode(cms_plugin),
                 "type": cms_plugin.get_plugin_name(),
                 'plugin_id': plugin_id,
                 'icon': force_escape(escapejs(cms_plugin.get_instance_icon_src())),
@@ -1303,11 +1302,14 @@ def edit_plugin(self, request, plugin_id):
                 'cancel': True,
             }
             instance = cms_plugin.get_plugin_instance()[0]
-            if not instance:
+            if instance:
+                context['name'] = unicode(instance)
+            else:
                 # cancelled before any content was added to plugin
                 cms_plugin.delete()
                 context.update({
-                    "deleted":True,
+                    "deleted": True,
+                    'name': unicode(cms_plugin),
                 })
             return render_to_response('admin/cms/page/plugin_forms_ok.html', context, RequestContext(request))
 


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

Issue:
Unihandecode errors
start new starttestserver.py with fresh db. enter the following url:

http://localhost:8000/en/admin/cms/page/1/?language=en

Unihandecode errors
start new starttestserver.py with fresh db. enter the following url:

http://localhost:8000/en/admin/cms/page/1/?language=en



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
@@ -492,6 +492,8 @@ def change_view(self, request, object_id, extra_context=None):
         """
         The 'change' admin view for the Page model.
         """
+        if extra_context is None:
+            extra_context = {}
         try:
             obj = self.model.objects.get(pk=object_id)
         except self.model.DoesNotExist:


Test patch:
diff --git a/cms/tests/admin.py b/cms/tests/admin.py
--- a/cms/tests/admin.py
+++ b/cms/tests/admin.py
@@ -373,6 +373,12 @@ def test_changelist_tree(self):
         # but not any further down the tree
         self.assertFalse('id="page_%s"' % third_level_page.pk in response.content)
 
+    def test_unihandecode_doesnt_break_404_in_admin(self):
+        admin = self.get_superuser()
+        self.client.login(username='admin', password='admin')
+        response = self.client.get('/en/admin/cms/page/1/?language=en')
+        self.assertEqual(response.status_code, 404)
+
 
 class AdminFieldsetTests(CMSTestCase):
     def validate_attributes(self, a, b, ignore=None):
Repository: django-cms/django-cms

Issue:
"copy_relations" in check command doesn't take inheritance into consideretion
I get this warning if my plugin is inherited from an abstract class that defines copy_relations method:

```
 - goscale.plugins.presentations.models.GooglePresentation has a many-to-many relation to goscale.plugins.presentations.models.GooglePresentation,
but no "copy_relations" method defined. [WARNING]
```

Here's a gist with my models code: https://gist.github.com/littlepea/5418003

So my actual plugin is GooglePresentation which is inherited from an abstract base class GoscaleCMSPlugin and django-cms is warning me that it has a Many-to-Many field posts but doesn't have a copy_relations method.
But the base abstract class does actually have this method...



Discussion:
@piquadrat didn't we have a check for subclasses there?

Thinking of it, just looking into `__dict__` to see if the method is there was probably to simplistic. We'll probably have to walk the inheritance chain and check if the `copy_relations` method we find is not the one defined on `CMSPlugin`.


Resolving patch:
diff --git a/cms/utils/check.py b/cms/utils/check.py
--- a/cms/utils/check.py
+++ b/cms/utils/check.py
@@ -1,5 +1,6 @@
 # -*- coding: utf-8 -*-
 from __future__ import with_statement
+import inspect
 from contextlib import contextmanager
 from cms import constants
 from cms.models.pluginmodel import CMSPlugin
@@ -225,11 +226,18 @@ def check_plugin_instances(output):
 @define_check
 def check_copy_relations(output):
     c_to_s = lambda klass: '%s.%s' % (klass.__module__, klass.__name__)
+
+    def get_class(method_name, model):
+        for cls in inspect.getmro(model):
+            if method_name in cls.__dict__:
+                return cls
+        return None
+
     with output.section('Presence of "copy_relations"') as section:
         plugin_pool.discover_plugins()
         for plugin in plugin_pool.plugins.values():
             plugin_class = plugin.model
-            if 'copy_relations' in plugin_class.__dict__:
+            if get_class('copy_relations', plugin_class) is not CMSPlugin or plugin_class is CMSPlugin:
                 # this class defines a ``copy_relations`` method, nothing more
                 # to do
                 continue


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

Issue:
add template field back to advanced settings

add template field back to advanced settings

add template field back to advanced settings



Discussion:

Resolving patch:
diff --git a/cms/admin/forms.py b/cms/admin/forms.py
--- a/cms/admin/forms.py
+++ b/cms/admin/forms.py
@@ -217,7 +217,7 @@ def clean_overwrite_url(self):
     class Meta:
         model = Page
         fields = [
-            'site', 'reverse_id', 'overwrite_url', 'redirect', 'soft_root', 'navigation_extenders',
+            'site', 'template', 'reverse_id', 'overwrite_url', 'redirect', 'soft_root', 'navigation_extenders',
             'application_urls', 'application_namespace'
         ]
 


Test patch:
diff --git a/cms/tests/admin.py b/cms/tests/admin.py
--- a/cms/tests/admin.py
+++ b/cms/tests/admin.py
@@ -952,6 +952,7 @@ def test_reverse_id_error_location(self):
             'language': 'en',
             'site': site.pk,
             'reverse_id': dupe_id,
+            'template': 'col_two.html',
         }
         form = AdvancedSettingsForm(data=page2_data, files=None)
         self.assertFalse(form.is_valid())
@@ -967,6 +968,7 @@ def test_reverse_id_error_location(self):
         self.assertEqual([u'A page with this reverse URL id exists already.'],
                          form.errors['reverse_id'])
         page2_data['reverse_id'] = ""
+
         form = AdvancedSettingsForm(data=page2_data, files=None)
         self.assertTrue(form.is_valid())
         admin = self._get_guys(admin_only=True)