From 6100773c2476e333f739674910caf48da001abef Mon Sep 17 00:00:00 2001 From: Rachid Belaid Date: Sun, 2 Sep 2012 19:20:42 +0100 Subject: [PATCH] Add a new signal content_object_init It's sent when a new content object is created: Page, Article --- docs/plugins.rst | 33 +++++++++++++++++++++++++++------ pelican/contents.py | 4 +++- pelican/signals.py | 1 + 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/docs/plugins.rst b/docs/plugins.rst index 53858668..c65fc79e 100644 --- a/docs/plugins.rst +++ b/docs/plugins.rst @@ -48,24 +48,45 @@ which you map the signals to your plugin logic. Let's take a simple example:: signals.initialized.connect(test) + List of signals =============== Here is the list of currently implemented signals: -========================= ============================ ========================================= -Signal Arguments Description -========================= ============================ ========================================= +========================= ======================================= ========================================= +Signal Arguments Description +========================= ======================================= ========================================= initialized pelican object article_generate_context article_generator, metadata -article_generator_init article_generator invoked in the ArticlesGenerator.__init__ +article_generator_init article_generator invoked in the ArticlesGenerator.__init__ pages_generate_context pages_generator, metadata -pages_generator_init pages_generator invoked in the PagesGenerator.__init__ -========================= ============================ ========================================= +pages_generator_init pages_generator invoked in the PagesGenerator.__init__ +content_object_init Content class (Page, Article), instance +========================= ======================================= ========================================= The list is currently small, don't hesitate to add signals and make a pull request if you need them! +.. note:: + + The signal ``content_object_init`` can send different type of object as + argument. If you want to register only one type of object then you will + need to specify the sender when you are connecting to the signal. + + :: + + from pelican import signals + from pelican import contents + + def test(sender, instance): + print "%s : %s content initialized !!" % (sender, instance) + + def register(): + signals.content_object_init.connect(test, sender=contents.Article) + + + List of plugins =============== diff --git a/pelican/contents.py b/pelican/contents.py index 851607a5..b5701732 100644 --- a/pelican/contents.py +++ b/pelican/contents.py @@ -11,7 +11,7 @@ from sys import platform, stdin from pelican.settings import _DEFAULT_CONFIG from pelican.utils import slugify, truncate_html_words - +from pelican import signals logger = logging.getLogger(__name__) @@ -106,6 +106,8 @@ class Page(object): if 'summary' in metadata: self._summary = metadata['summary'] + signals.content_object_init.send(self.__class__, instance=self) + def check_properties(self): """test that each mandatory property is set.""" for prop in self.mandatory_properties: diff --git a/pelican/signals.py b/pelican/signals.py index 4d9ab512..17b4b7e6 100644 --- a/pelican/signals.py +++ b/pelican/signals.py @@ -5,3 +5,4 @@ article_generate_context = signal('article_generate_context') article_generator_init = signal('article_generator_init') pages_generate_context = signal('pages_generate_context') pages_generator_init = signal('pages_generator_init') +content_object_init = signal('content_object_init')