Skip to content

Commit 9074e58

Browse files
authored
Fixes django-cms#6013 -- Show Edit Page button on non-cms pages with placeholders (django-cms#6014)
1 parent 4a9f3ed commit 9074e58

File tree

5 files changed

+36
-4
lines changed

5 files changed

+36
-4
lines changed

CHANGELOG.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Fixed a bug where slug wouldn't be generated in the creation wizard
44
* Fixed a bug where the add page endpoint rendered ``Change page`` as the html title.
55
* Fixed an issue where non-staff users could request the wizard create endpoint.
6+
* Fixed an issue where the ``Edit page`` toolbar button wouldn't show on non-cms pages
7+
with placeholders.
68

79

810
=== 3.4.4 (2017-06-15) ===

cms/cms_toolbars.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def init_from_request(self):
6262

6363
def init_placeholders(self):
6464
content_renderer = self.toolbar.content_renderer
65-
self.placeholders = content_renderer.get_rendered_editable_placeholders()
65+
self.editable_placeholders = content_renderer.get_rendered_editable_placeholders()
6666
self.statics = content_renderer.get_rendered_static_placeholders()
6767

6868
def populate(self):
@@ -79,7 +79,7 @@ def add_structure_mode(self):
7979
if page_permissions.user_can_change_page(self.request.user, page=self.page):
8080
return self.add_structure_mode_item()
8181

82-
elif any(ph for ph in self.placeholders if ph.has_change_permission(self.request.user)):
82+
elif any(ph for ph in self.editable_placeholders if ph.has_change_permission(self.request.user)):
8383
return self.add_structure_mode_item()
8484

8585
for sp in self.statics:
@@ -267,7 +267,7 @@ def init_from_request(self):
267267

268268
def init_placeholders(self):
269269
content_renderer = self.toolbar.content_renderer
270-
self.placeholders = content_renderer.get_rendered_editable_placeholders()
270+
self.placeholders = content_renderer.get_rendered_placeholders()
271271
self.statics = content_renderer.get_rendered_static_placeholders()
272272
self.dirty_statics = [sp for sp in self.statics if sp.dirty]
273273

cms/test_utils/project/placeholderapp/views.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ def detail_view(request, pk, template_name='detail.html', item_name="char_1",
6969
return _base_detail(request, instance, template_name, item_name, template_string)
7070

7171

72+
def latest_view(request):
73+
example = Example1.objects.latest('id')
74+
return detail_view(request, pk=example.pk)
75+
76+
7277
def detail_view_char(request, pk, template_name='detail.html', item_name="char_1",
7378
template_string='',):
7479
instance = CharPksExample.objects.get(pk=pk)

cms/test_utils/project/urls.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from cms.utils.compat.dj import is_installed
1212
from cms.utils.conf import get_cms_setting
1313
from cms.test_utils.project.sampleapp.forms import LoginForm, LoginForm2, LoginForm3
14-
from cms.test_utils.project.placeholderapp.views import example_view
14+
from cms.test_utils.project.placeholderapp.views import example_view, latest_view
1515
from cms.test_utils.project.sampleapp.views import plain_view
1616

1717
admin.autodiscover()
@@ -36,6 +36,7 @@
3636
kwargs={'authentication_form': LoginForm3}),
3737
url(r'^admin/', include(admin.site.urls)),
3838
url(r'^example/$', example_view),
39+
url(r'^example/latest/$', latest_view),
3940
url(r'^plain_view/$', plain_view),
4041
url(r'^', include('cms.urls')),
4142
)

cms/tests/test_toolbar.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,30 @@ def test_markup(self):
224224
self.assertContains(response, '<div id="cms-top"')
225225
self.assertContains(response, 'cms.base.css')
226226

227+
def test_live_draft_markup_on_app_page(self):
228+
"""
229+
Checks that the "edit page" button shows up
230+
on non-cms pages with app placeholders and no static placeholders.
231+
"""
232+
superuser = self.get_superuser()
233+
234+
output = (
235+
'<a class="cms-btn cms-btn-action cms-btn-switch-edit" '
236+
'href="?{}">Edit page</a>'
237+
).format(get_cms_setting('CMS_TOOLBAR_URL__EDIT_ON'))
238+
239+
Example1.objects.create(
240+
char_1="char_1",
241+
char_2="char_2",
242+
char_3="char_3",
243+
char_4="char_4",
244+
)
245+
246+
with self.login_user_context(superuser):
247+
response = self.client.get('/en/example/latest/?%s' % get_cms_setting('CMS_TOOLBAR_URL__EDIT_OFF'))
248+
self.assertEqual(response.status_code, 200)
249+
self.assertContains(response, output, html=True)
250+
227251
def test_markup_generic_module(self):
228252
create_page("toolbar-page", "col_two.html", "en", published=True)
229253
superuser = self.get_superuser()

0 commit comments

Comments
 (0)