问题
I am using show_placeholder
to display "global" content along my site. For example, a Widget that I use in the sidebar. I did something similar to the suggestions given in this other question. I created a template extra_placeholders.html
and a page (with return id "extra-placeholders") in the admin that use extra_placeholders.html
to store the placeholders. It is never displayed in the front end but I can access the placeholder of it with {% show_placeholder "my_placeholder" "extra-placeholders" %}
It works fine with one caveat that I need to solve. Let's say I use the front-end "Edition Mode" of Django-CMS to edit the placeholder. It works in the sense that I can modify the content and save it.
However, it does not get published automatically.
I understand the reason. The placeholder actually belongs to another page ("extra-placeholders"). So when I click "Publish" in the front end I save the page that I am seeing but not the one associated through the my_placeholder
.
So, I would like to use a signal to save the "extra-placeholders" page each time any other page is saved. I found that there is this signal but how do I use it to publish my extra-placeholders page?
回答1:
You actually want to connect a signal to CMSPlugin
, not Page
.
Something like this (untested!) might work:
def signal_handler(instance, **kwargs):
if not isinstance(instance, CMSPlugin):
return
page = Page.objects.get(reverse_id='extra-placeholders', publisher_is_draft = True)
if page.placeholders.filter(pk=instance.placeholder_id).exists():
page.publish()
post_save.connect(signal_handler)
来源:https://stackoverflow.com/questions/22575747/how-to-use-post-publish-signal-to-publish-a-related-page-referenced-by-show-plac