Commits

Anonymous committed eea2b5a

Added a new signal for ping-o-matic and refatoring in signals callbacks.

--HG--
extra : convert_revision : svn%3Aea932676-bf3b-0410-9f11-03e9079df846/trunk%40160

  • Participants
  • Parent commits 96e1f55

Comments (0)

Files changed (4)

-django-diario was originally created in late 2007 by 
+Diário was originally created in late 2007 by 
 
   * Guilherme Mesquita Gondim (semente) <semente at taurinus.org>. 
 
 And here is an inevitably incomplete list of MUCH-APPRECIATED
 CONTRIBUTORS --- people who have submitted patches, reported bugs,
-added translations and generally made django-diario that much better:
+added translations and generally made Diário that much better:
 
   * Henrique Romano <onaiort at gmail.com>
   * Ricardo Fuentes <jirah.01 at gmail.com>
 from django.db.models import permalink
 from django.utils.translation import ugettext_lazy as _
 
-from diario.utils import markuping
 from diario.managers import PublishedManager, CurrentSitePublishedManager
 from diario.settings import DIARIO_DEFAULT_MARKUP_LANG, HAS_TAG_SUPPORT
 
 
 
 from django.db.models import signals
-from diario.signals import entry_pre_save
-signals.pre_save.connect(entry_pre_save, sender=Entry)
+from diario.signals import convert_body_to_html, update_draft_date
+signals.pre_save.connect(convert_body_to_html, sender=Entry)
+signals.pre_save.connect(update_draft_date, sender=Entry)

diario/signals.py

 """
 
 from datetime import datetime
-from diario.models import Entry
-from diario.utils import markuping
+from django.contrib.sites.models import Site
+from django.core.urlresolvers import reverse
+from diario.utils import markuping, pingomatic
 
-def entry_pre_save(sender, instance, signal, *args, **kwargs):
-    # transform plain text markup in body_source to HTML
-    instance.body = unicode(markuping(instance.markup, instance.body_source))
+def convert_body_to_html(instance, **kwargs):
+    """
+    Convert plain text markup in ``body_source`` field to HTML.
 
+    This signal always connected in models module using ``pre_save``
+    method.
+    """
+    instance.body = unicode(markuping(instance.markup,
+                                      instance.body_source))
+
+def update_draft_date(sender, instance, **kwargs):
+    """
+    Update instance's pub_date if entry was draft.
+
+    This signal always connected in models module using ``pre_save``
+    method.
+    """
     try:
-        # update instance's pub_date if entry was draft
-        e = Entry.objects.get(id=instance.id)
+        e = sender.objects.get(id=instance.id)
         if e.is_draft:
             instance.pub_date = datetime.now()
-    except Entry.DoesNotExist:
+    except sender.DoesNotExist:
         pass
+
+def ping_with_pingomatic(instance, created, **kwargs):
+    """
+    Updates multiple services and search engines about updates to
+    weblog content, with `ping-o-matic <http://pingomatic.com/>`_.
+
+    To connect this signal, you need use ``post_save``
+    method. Example::
+
+      signals.post_save.connect(ping_with_pingomatic, sender=Entry)
+
+    """
+    if created:
+        site = Site.objects.get_current()
+        site_url = 'http://%s' % site + reverse('diario-entry-list')
+        try:
+            pingomatic(site.name, site_url)
+        except:
+            pass
 #
 
 from xmlrpclib import ServerProxy
-from django.contrib.sites.models import Site
-from django.core.urlresolvers import reverse
 
 def markuping(markup, value):
     """
     else:
         return value            # raw
 
-def pingomatic():
-    server = ServerProxy('http://rpc.pingomatic.com/')
-    site = Site.objects.get_current()
-
-    try:
-        server.weblogUpdates.ping(site.name, 'http://%s' % site + \
-                                      reverse('diario-entry-list'))
-    except:
-        pass
+def pingomatic(site_name, site_url, server_url='http://rpc.pingomatic.com/'):
+    server = ServerProxy(server_url)
+    return server.weblogUpdates.ping(site_name, site_url)