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

Issue:
DoesNotExist: Title matching query does not exist. on publish
if page.publisher_public.parent.is_published(language):
                     from cms.models import Title, EmptyTitle
                     public_title = Title.objects.get(page=page.publisher_public, language=language)
                     if isinstance(public_title, EmptyTitle):
                         public_title = None
                     draft_title = Title.objects.get(page=page, language=language)
                     if public_title and not public_title.published:



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
@@ -610,15 +610,16 @@ def publish(self, language):
         # become published.
         publish_set = self.get_descendants().filter(title_set__published=True,
                                                     title_set__language=language).select_related('publisher_public')
+        from cms.models import Title
         for page in publish_set:
-            if page.publisher_public:
+            if page.publisher_public_id:
                 if not page.publisher_public.parent_id:
                     page.publisher_public.parent = page.parent.publisher_public
                     page.publisher_public.save()
                 if page.publisher_public.parent.is_published(language):
-                    from cms.models import Title, EmptyTitle
-                    public_title = Title.objects.get(page=page.publisher_public, language=language)
-                    if isinstance(public_title, EmptyTitle):
+                    try:
+                        public_title = Title.objects.get(page=page.publisher_public, language=language)
+                    except Title.DoesNotExist:
                         public_title = None
                     draft_title = Title.objects.get(page=page, language=language)
                     if public_title and not public_title.published:


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

Issue:
New redirect widget is not nullable
There is no way to empty the new redirect field.
Plus a min-width should be used to have a proper size.



Discussion:
Setting as blocker as this is a user facing issue and a regression

I can look into It asap, shouldnt be too much of a hassle. You fixed the width issue right ?

Yep, size has been fixed in related djangocms-admin-style issue.
Thanks for looking into it


Resolving patch:
diff --git a/cms/forms/widgets.py b/cms/forms/widgets.py
--- a/cms/forms/widgets.py
+++ b/cms/forms/widgets.py
@@ -138,6 +138,7 @@ def render(self, name=None, value=None, attrs=None):
     $(function(){
         $("#%(element_id)s").select2({
             placeholder: "%(placeholder_text)s",
+            allowClear: true,
             minimumInputLength: 3,
             ajax: {
                 url: "%(ajax_url)s",


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

Issue:
Page is not reloaded on template change
Changing template from the toolbar does not reload the page. Template is changed correctly



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
@@ -345,7 +345,8 @@ def add_page_menu(self):
                 active = self.page.template == path
                 if path == TEMPLATE_INHERITANCE_MAGIC:
                     templates_menu.add_break(TEMPLATE_MENU_BREAK)
-                templates_menu.add_ajax_item(name, action=action, data={'template': path}, active=active)
+                templates_menu.add_ajax_item(name, action=action, data={'template': path}, active=active,
+                                             on_success='REFRESH_PAGE')
         current_page_menu.add_break(PAGE_MENU_SECOND_BREAK)
 
         # advanced settings


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

Issue:
if page types is used on more than one site it breaks

if page types is used on more than one site it breaks



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
@@ -96,7 +96,7 @@ def __init__(self, *args, **kwargs):
             self.fields['language'].initial = get_language()
         if 'page_type' in self.fields:
             try:
-                type_root = Page.objects.get(publisher_is_draft=True, reverse_id=PAGE_TYPES_ID)
+                type_root = Page.objects.get(publisher_is_draft=True, reverse_id=PAGE_TYPES_ID, site=site_id)
             except Page.DoesNotExist:
                 type_root = None
             if type_root:


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

Issue:
saving as page type does not check for slug collisions!



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
@@ -295,8 +295,11 @@ def get_form(self, request, obj=None, **kwargs):
             self.inlines = []
             for name in ['slug', 'title']:
                 form.base_fields[name].initial = u''
-            if 'target' in request.GET:
-                target = request.GET['target']
+            if 'target' in request.GET or 'copy_target' in request.GET:
+                if 'target' in request.GET:
+                    target = request.GET['target']
+                if 'copy_target' in request.GET:
+                    target = request.GET['copy_target']
                 if 'position' in request.GET:
                     position = request.GET['position']
                     if position == 'last-child' or position == 'first-child':


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

Issue:
`manage.py cms check` got broke!
/lib/python2.7/site-packages/cms/plugin_pool.py", line 173, in set_plugin_meta
    table_name = 'cmsplugin_%s_items' % splitted[1]
UnboundLocalError: local variable 'splitted' referenced before assignment



Discussion:

Resolving patch:
diff --git a/cms/plugin_pool.py b/cms/plugin_pool.py
--- a/cms/plugin_pool.py
+++ b/cms/plugin_pool.py
@@ -157,7 +157,7 @@ def set_plugin_meta(self):
                         if (table_name not in table_names
                         and splitter in table_name):
                             old_db_name = table_name
-                            table_name.split(splitter, 1)
+                            splitted = table_name.split(splitter, 1)
                             table_name = 'cmsplugin_%s' % splitted[1]
                             if table_name in table_names:
                                 att.rel.through._meta.db_table = table_name
@@ -169,7 +169,7 @@ def set_plugin_meta(self):
                         if (table_name not in table_names
                         and splitter in table_name):
                             old_db_name = table_name
-                            table_name.split(splitter, 1)
+                            splitted = table_name.split(splitter, 1)
                             table_name = 'cmsplugin_%s_items' % splitted[1]
                             if table_name in table_names:
                                 att.through._meta.db_table = table_name


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

Issue:
cms.views.details makes a RequestContext earlier than necessary.
[this line](https://github.com/divio/django-cms/blob/0ff39518f1ea499c9bcebec11144809350a613d5/cms/views.py#L73) doesn't appear to be needed until [here](https://github.com/divio/django-cms/blob/0ff39518f1ea499c9bcebec11144809350a613d5/cms/views.py#L184). Or, if it is, it's relying on some hideous mutability which should be documented (if `# get the right model` is supposed to cover that, it fails)



Discussion:

Resolving patch:
diff --git a/cms/views.py b/cms/views.py
--- a/cms/views.py
+++ b/cms/views.py
@@ -69,8 +69,6 @@ def details(request, slug):
             response._headers = headers
             return response
 
-    # get the right model
-    context = RequestContext(request)
     # Get a Page model object from the request
     page = get_page_from_request(request, use_path=slug)
     if not page:
@@ -180,7 +178,8 @@ def details(request, slug):
         request.toolbar.set_object(page)
 
     template_name = get_template_from_request(request, page, no_current_page=True)
-    # fill the context 
+    # fill the context
+    context = RequestContext(request)
     context['lang'] = current_language
     context['current_page'] = page
     context['has_change_permissions'] = page.has_change_permission(request)
@@ -245,7 +244,7 @@ def _cache_page(response):
         )
         # See note in invalidate_cms_page_cache()
         _set_cache_version(version)
-    
+
 
 def _get_cache_key(request):
     #md5 key of current path


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

Issue:
Bug in plugin_rendering.py
I'm currently facing an extremely weird problem where the publish button and content/structure mode switch is not shown in the toolbar - effectively rendering the whole CMS useless. Unfortunately I don't know when this started, so I'm having a very hard time to pin down if this is my fault or not.

Anyways... while debugging, I found this:

https://github.com/divio/django-cms/blob/develop/cms/plugin_rendering.py#L100

That seems to be a bug to me. Shouldn't it be 

```
if not hasattr(request, 'placeholders'):
```

Note: `placeholders` should be plural, no?



Discussion:
yep


Resolving patch:
diff --git a/cms/plugin_rendering.py b/cms/plugin_rendering.py
--- a/cms/plugin_rendering.py
+++ b/cms/plugin_rendering.py
@@ -97,7 +97,7 @@ def render_placeholder(placeholder, context_to_copy, name_fallback="Placeholder"
     context = context_to_copy
     context.push()
     request = context['request']
-    if not hasattr(request, 'placeholder'):
+    if not hasattr(request, 'placeholders'):
         request.placeholders = []
     request.placeholders.append(placeholder)
     if hasattr(placeholder, 'content_cache'):


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

Issue:
`develop.py authors` doesn't work on Python 3
```
(4env) jonas:~/workspace/django-cms(develop)$ ./develop.py authors
Generating AUTHORS
Collecting author names
Traceback (most recent call last):
  File "./develop.py", line 298, in <module>
    main()
  File "./develop.py", line 209, in main
    return generate_authors()
  File "./develop.py", line 185, in generate_authors
    author = line.decode('utf-8').strip("* \n")
AttributeError: 'str' object has no attribute 'decode'
```



Discussion:

Resolving patch:
diff --git a/develop.py b/develop.py
--- a/develop.py
+++ b/develop.py
@@ -12,6 +12,7 @@
 from docopt import docopt
 from django import VERSION
 from django.utils import autoreload
+from django.utils.encoding import force_text
 
 import cms
 from cms.test_utils.cli import configure
@@ -170,7 +171,8 @@ def makemessages():
 def shell():
     from django.core.management import call_command
     call_command('shell')
-    
+
+
 def generate_authors():
     print("Generating AUTHORS")
 
@@ -182,12 +184,12 @@ def generate_authors():
     with open('AUTHORS', 'r') as f:
         for line in f.readlines():
             if line.startswith("*"):
-                author = line.decode('utf-8').strip("* \n")
+                author = force_text(line).strip("* \n")
                 if author.lower() not in seen_authors:
                     seen_authors.append(author.lower())
                     authors.append(author)
     for author in r.stdout.readlines():
-        author = author.decode('utf-8').strip()
+        author = force_text(author).strip()
         if author.lower() not in seen_authors:
             seen_authors.append(author.lower())
             authors.append(author)


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

Issue:
get_plugins_for_page breaks if page template is inherited.
Django doesn't really like to play with "INHERIT" as a template path ;-)
PR follows



Discussion:

Resolving patch:
diff --git a/cms/utils/plugins.py b/cms/utils/plugins.py
--- a/cms/utils/plugins.py
+++ b/cms/utils/plugins.py
@@ -348,7 +348,7 @@ def get_plugins_for_page(request, page, lang=None):
         return []
     lang = lang or get_language_from_request(request)
     if not hasattr(page, '_%s_plugins_cache' % lang):
-        slots = get_placeholders(page.template)
+        slots = get_placeholders(page.get_template())
         setattr(page, '_%s_plugins_cache' % lang, get_cmsplugin_queryset(request).filter(
             placeholder__page=page, placeholder__slot__in=slots, language=lang, parent__isnull=True
         ).order_by('placeholder', 'position').select_related())


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

Issue:
Bug in PageManager.published
Manager says:

def published(self, site=None):
        return self.get_query_set().published(site)

where Query.published is def published(self, language=None, site=None).
So the if site is set, it goes to language and the query ends up like:

".. publication_end_date" IS NULL) AND "cms_title"."language" = 127.0.0.1:8001  AND "cms_title"."published" = True ..."

Prevents using objects.publised with site argument :(



Discussion:

Resolving patch:
diff --git a/cms/models/managers.py b/cms/models/managers.py
--- a/cms/models/managers.py
+++ b/cms/models/managers.py
@@ -61,7 +61,7 @@ def valid_targets(self, page_id, request, perms, page=None):
         return self.get_query_set().valid_targets(page_id, request, perms, page)
 
     def published(self, site=None):
-        return self.get_query_set().published(site)
+        return self.get_query_set().published(site=site)
 
     def expired(self):
         return self.drafts().expired()


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

Issue:
Fix support for reversion 1.8.1



Discussion:

Resolving patch:
diff --git a/cms/utils/helpers.py b/cms/utils/helpers.py
--- a/cms/utils/helpers.py
+++ b/cms/utils/helpers.py
@@ -46,8 +46,12 @@ def make_revision_with_plugins(obj, user=None, message=None):
     revision_context = reversion.revision_context_manager
     
     cls = obj.__class__
-    
-    if cls in revision_manager._registered_models:
+    if hasattr(revision_manager, '_registration_key_for_model'):
+        model_key = revision_manager._registration_key_for_model(cls)
+    else:
+        model_key = cls
+
+    if model_key in revision_manager._registered_models:
         
         placeholder_relation = find_placeholder_relation(obj)
 
diff --git a/cms/utils/reversion_hacks.py b/cms/utils/reversion_hacks.py
--- a/cms/utils/reversion_hacks.py
+++ b/cms/utils/reversion_hacks.py
@@ -2,6 +2,7 @@
 import reversion
 from reversion.revisions import RegistrationError, VersionAdapter
 
+
 def register_draft_only(model_class, fields, follow, format):
     """
     version of the reversion register function that only registers drafts and
@@ -32,5 +33,9 @@ def register_draft_only(model_class, fields, follow, format):
     registration_info.fields = fields
     registration_info.follow = follow
     registration_info.format = format
-    revision_manager._registered_models[model_class] = registration_info
+    if hasattr(revision_manager, '_registration_key_for_model'):
+        model_key = revision_manager._registration_key_for_model(model_class)
+    else:
+        model_key = model_class
+    revision_manager._registered_models[model_key] = registration_info
     # Do not connect to the post save signal of the model.


Test patch:
diff --git a/test_requirements/django-1.6.txt b/test_requirements/django-1.6.txt
--- a/test_requirements/django-1.6.txt
+++ b/test_requirements/django-1.6.txt
@@ -1,3 +1,3 @@
 -r requirements_base.txt
 django>=1.6
-django-reversion==1.8
+django-reversion>=1.8
Repository: django-cms/django-cms

Issue:
Possibly broken toolbar "is_current_app" parameter
Discovered while preparing a talk for DjangoVillage, will report more detailed info after that



Discussion:

Resolving patch:
diff --git a/cms/toolbar/toolbar.py b/cms/toolbar/toolbar.py
--- a/cms/toolbar/toolbar.py
+++ b/cms/toolbar/toolbar.py
@@ -77,16 +77,16 @@ def __init__(self, request):
             self.clipboard = user_settings.clipboard
         with force_language(self.language):
             try:
-                self.view_name = resolve(self.request.path).func.__module__
+                self.app_name = resolve(self.request.path).app_name
             except Resolver404:
-                self.view_name = ""
+                self.app_name = ""
         toolbars = toolbar_pool.get_toolbars()
 
         self.toolbars = SortedDict()
         app_key = ''
         for key in toolbars:
             app_name = ".".join(key.split(".")[:-2])
-            if app_name in self.view_name and len(key) > len(app_key):
+            if app_name == self.app_name and len(key) > len(app_key):
                 app_key = key
         for key in toolbars:
             toolbar = toolbars[key](self.request, self, key == app_key, app_key)


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

Issue:
api.create_page doesn't allow reverse_id for multi site apps
In 3.0.2 cms/api.py:194 

```
if Page.objects.drafts().filter(reverse_id=reverse_id).count():
```

should include site otherwise pages with a reverse ID can not be created in multiple sites



Discussion:

Resolving patch:
diff --git a/cms/api.py b/cms/api.py
--- a/cms/api.py
+++ b/cms/api.py
@@ -191,7 +191,7 @@ def create_page(title, template, language, menu_title=None, slug=None,
         application_urls = None
 
     if reverse_id:
-        if Page.objects.drafts().filter(reverse_id=reverse_id).count():
+        if Page.objects.drafts().filter(reverse_id=reverse_id, site=site).count():
             raise FieldError('A page with the reverse_id="%s" already exist.' % reverse_id)
 
     page = Page(


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

Issue:
render_model plugin doesn't render non-translated fields in a TranslatableModel
I have a simple, HVAD translatable model, which looks something like this:

``` python
from django.dm import models
from hvad.models import TranslatableModel, TranslatedFields
class StaffMember(TranslatableModel):

    name = models.CharFIeld(default='', max_length=32)
    translations = TranslatedFields(
        title = models.CharField(default='', max_length=32)
    )
```

Using `<h3>{% render_model person "name" %}</h3>` yields:

``` html
<div class="cms_plugin cms_plugin-staff-staffmember-name-1 cms_render_model"></div>
```

Notice that the right classes are there, but there's no content.
- Replacing the `{% render_model %}` tag with just `{{ person.name }}` yields the name field's contents just fine.
- Using `{% render_model person "title" %}` works fine.
- Using `{% render_model other_model "name" %}` where other_model isn't a TranslatableModel works fine.

This is in Django 1.6.5, HVAD v0.4.1, django-cms v3.0.3, but also tried latest develop with same outcome.

Another interesting fact is this project was originally build with cms v2.4.x, but was recently converted to 3.0.3. But, I'm not sure if this is relevant here. Running `manage.py cms check` yields nothing out of order.



Discussion:

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
@@ -812,10 +812,12 @@ def _get_content(self, context, instance, attribute, language, filters):
         Renders the requested attribute
         """
         extra_context = copy(context)
+        attr_value = None
         if hasattr(instance, 'lazy_translation_getter'):
-            extra_context['content'] = instance.lazy_translation_getter(attribute, '')
-        else:
-            extra_context['content'] = getattr(instance, attribute, '')
+            attr_value = instance.lazy_translation_getter(attribute, '')
+        if not attr_value:
+            attr_value = getattr(instance, attribute, '')
+        extra_context['content'] = attr_value
         # This allow the requested item to be a method, a property or an
         # attribute
         if callable(extra_context['content']):


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

Issue:
toolbar causes 500 error if there is no current page
Most common case is when trying to render the toolbar on a 404 page or some other url that does not have a "current page".

How to reproduce:
- produce a 404.html template that loads the toolbar
- start a server with `DEBUG=False` and an empty database (no cms pages yet)
- login to the site as a staff user
- open `/` (or any other url)

Alternatively a site with existing pages can be used, just open an url that causes a 404 or that does not have a "current page" for some other reason.

You'll get a:

```
NoReverseMatch: Reverse for 'cms_page_edit_plugin' with arguments '('',)' and keyword arguments '{}' not found.
```

The error seems to originate [here](https://github.com/divio/django-cms/blob/168d276e3384b3e2872757c95ef825ff5af2007d/cms/templates/cms/toolbar/plugin.html#L27) the first time, there are more cases where it would happen though.

The problem seems to be, that `instance` (a cms page) does not exist in this situation.
This bug also triggers a 500 on any other page that should actually be a 404 (e.g browsers automatically trying to fetch `/favicon.ico`).

The toolbar should be made to work, even if there is no current page (e.g if it's a view from an app that uses static placeholders or if static placeholders are used on the 404 page).



Discussion:
The root case for this if you try to make a {% render_model_block %} templatetag with a None object.

thanks @digi604 
I found that we had some statements like `{% render_model_block request.current_page "changelist" %}` around the navigation in our base template. This is in order to make it possible to double-click the navigation to edit the pagetree.

In this case it does make sense that this should would work on 404 pages or non-cms pages. `changelist` does not need an instance, a class would be enough.

I propose two changes:
- clearer error message in `render_model_block` (and similar templatetags) with information about what template that the failure happened.
- ability for `render_model_block` to take a model `class` or a dotted string representation of the model class (e.g `"cms.Page"`) for the `changelist` case (or any other cases, should they exist, that don't need an instance).

docs: http://django-cms.readthedocs.org/en/latest/advanced/templatetags.html#render-model-block


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
@@ -359,7 +359,7 @@ def get_processors(self, context, plugin):
     def get_context(self, context, plugin):
         if not plugin:
             return {'content': ''}
-        
+
         processors=self.get_processors(context, plugin)
 
         return {'content': plugin.render_plugin(context, processors=processors)}


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

Issue:
Groups could not be deleted if custom user model is used
If a custom user model is used one can't delete groups because in the pre_delete signal the user permissions are cleared. The users are accessed by their reversed descriptor but in the case of a custom user model this is not always called user_set, so there is an attribute error raised.

def pre_delete_group(instance, **kwargs):
     for user in instance.user_set.all():
         clear_user_permission_cache(user)



Discussion:

Resolving patch:
diff --git a/cms/signals/permissions.py b/cms/signals/permissions.py
--- a/cms/signals/permissions.py
+++ b/cms/signals/permissions.py
@@ -58,7 +58,8 @@ def pre_save_group(instance, raw, **kwargs):
 
 
 def pre_delete_group(instance, **kwargs):
-    for user in instance.user_set.all():
+    user_set = getattr(instance, user_related_name)
+    for user in user_set.all():
         clear_user_permission_cache(user)
 
 


Test patch: