Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/walkah/django-salmon
Django app that implements the Salmon protocol
https://github.com/walkah/django-salmon
Last synced: about 1 month ago
JSON representation
Django app that implements the Salmon protocol
- Host: GitHub
- URL: https://github.com/walkah/django-salmon
- Owner: walkah
- Created: 2011-03-25T14:11:16.000Z (almost 14 years ago)
- Default Branch: master
- Last Pushed: 2011-03-25T05:00:25.000Z (almost 14 years ago)
- Last Synced: 2024-10-15T11:38:51.887Z (3 months ago)
- Language: Python
- Homepage:
- Size: 433 KB
- Stars: 1
- Watchers: 3
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
Awesome Lists containing this project
README
=============
django-salmon
=============This is ``django-salmon``, a drop-in `Django`_ application that adds support for the `Salmon Protocol`_.
.. _Django: http://www.djangoproject.com/
.. _Salmon Protocol: http://www.salmon-protocol.org/salmon-protocol-summaryIt doesn't work yet. Stay tuned though!
Instructions
------------To use ``django-salmon``, add it to your ``INSTALLED_APPS`` in ``settings.py``: ::
INSTALLED_APPS = (
...
'salmon',
...
)You will need models to represent feeds and comments. Set up signals for your feed model: ::
import salmon
...
def salmon_subscriber(sender, **kwargs):
feed = kwargs.get('instance', None)
if not feed:
return
salmon.subscribe(feed, feed.url)
post_save.connect(salmon_subscriber, sender=Feed)def salmon_unsubscriber(sender, **kwargs):
feed = kwargs.get('instance', None)
if not feed:
return
salmon.unsubscribe(feed)
post_delete.connect(salmon_unsubscriber, sender=Feed)Set up the following signal for your comment model: ::
def comment_handler(sender, **kwargs):
comment = kwargs.get('instance', None)
if not comment:
return
url = 'https://%s%s' % (
Site.objects.get_current(),
comment.get_absolute_url())
feed = SalmonAtom1EntryFeed(
comment.comment,
url,
comment.comment,
author_name=comment.user_name,
author_link='acct:' + comment.user_email,
pubdate=comment.submit_date,
)
parent = comment.content_object
salmon.slap(feed, parent.feed)
post_save.connect(comment_handler, sender=Comment)Because this is an incomplete package, in order to test the current functionality, you will need to add a private key to ``settings.py`` or equivalent: ::
SALMON_USER_KEYPAIR = 'RSA...'
To generate a sample key using `PyCrypto`_: ::
import base64
from Crypto import Random
from Crypto.PublicKey import RSA
from Crypto.Util import numberrng = Random.new().read
RSAkey = RSA.generate(1024, rng)encode = lambda a: base64.urlsafe_b64encode(number.long_to_bytes(a))
exp = encode(RSAkey.n)
private_exp = encode(RSAkey.d)
mod = encode(RSAkey.e)
print "RSA.%s.%s.%s" % (mod, exp, private_exp).. _PyCrypto: http://pycrypto.org/
** NOTE: ** This is a work in progress and at the moment is not functional.