Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug where empty placeholder would render as 'None' #5734

Merged

Conversation

cworth-gh
Copy link
Contributor

This bug would appear when "placeholder" template tag appeared in a
template being rendered by a non-CMS view.

The render_page_placeholder function had a bare "return" instead of
returning an explicit empty string.

See also the code that would be executed for the same case in
django-cms 3.3.x (in cms_tags.py:render_tag in that release):

    page = request.current_page
    if not page or page == 'dummy':
        if nodelist:
            return nodelist.render(context)
        return ''

Note: I'd like to contribute a test case for this as well. The existing test at cms.tests.test_rendering.RenderingTestCase.test_placeholder looks like
the closest thing for this. I'm just not sure what it would take to modify that
test case so that it would hit the conditional return modified by this code.
(Just changing self.test_page to None did not do the trick.) When I've
exercised this bug manually, I've done it by creating a non-CMS view that
renders with a template that contains a placeholder template tag.

Perhaps that would be an easy test to write for someone with more
experience writing Django tests. Any guidance you might be able to give
me on how to write that test would be appreciated.

This bug would appear when "placeholder" template tag appeared in a
template being rendered by a non-CMS view.

The render_page_placeholder function had a bare "return" instead of
returning an explicit empty string.

See also the code that would be executed for the same case in
django-cms 3.3.x (in cms_tags.py:render_tag in that release):

        page = request.current_page
        if not page or page == 'dummy':
            if nodelist:
                return nodelist.render(context)
            return ''
@czpython
Copy link
Contributor

Hello @cworth-gh,
Thanks for this fix.

Having a {% placeholder %} tag outside of a django CMS view is not supported, has been like this for some time now. The recommended approach is to use a {% static_placeholder %} tag instead.

We decided to "fail silently" when this change was introduced back in 3.0.0 because it would have caused a lot of failures for many people, now I'm not so sure we should continue to fail silently.

Anyways, for the reasons above I'm ok to merge this ('' is more consistent with the other return values) without a test.

@yakky thoughts?

@czpython czpython self-assigned this Oct 20, 2016
@cworth-gh
Copy link
Contributor Author

Hi @czpython,

Thanks for the quick reply. In our use case, I don't think {% static placeholder %} will do what we want.

What we have is a shared, base template that is used by both CMS and non-CMS views. We just expect the {% placeholder %} tags to render as empty for the non-CMS views. So, as of 3.3.x the fact that these are rendered empty, (and silently, even though not technically supported), is quite helpful for us.

If there's something different we "should" be doing for a case like this, let me know.

-Carl

@coveralls
Copy link

coveralls commented Oct 20, 2016

Coverage Status

Coverage remained the same at 82.519% when pulling ce20d36 on nimbis:fix-placeholder-from-non-CMS-view into 2949e3f on divio:release/3.4.x.

@czpython
Copy link
Contributor

This is a valid case, forcing users to override their base template blocks to remove the {% placeholder %} tags would not be good. That said, I think for the future (thinking 3.5.0) we will no longer render a placeholder outside of the cms in edit mode. So when users switch to an app template that inherits from base template with placeholder tags, these placeholders won't show up in structure mode.

@yakky
Copy link
Member

yakky commented Oct 26, 2016

@czpython I'm ok with the proposed change and ok for not needing a dedicated test

@czpython czpython merged commit bd64c85 into django-cms:release/3.4.x Oct 26, 2016
@czpython
Copy link
Contributor

Thanks @cworth-gh

othane pushed a commit to othane/django-cms that referenced this pull request Dec 15, 2016
…5734)

This bug would appear when "placeholder" template tag appeared in a
template being rendered by a non-CMS view.

The render_page_placeholder function had a bare "return" instead of
returning an explicit empty string.

See also the code that would be executed for the same case in
django-cms 3.3.x (in cms_tags.py:render_tag in that release):

        page = request.current_page
        if not page or page == 'dummy':
            if nodelist:
                return nodelist.render(context)
            return ''
@electroniceagle electroniceagle deleted the fix-placeholder-from-non-CMS-view branch December 19, 2017 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants