view README.md @ 24:f3bc8c661309
Installation process described with more details.
committer: Alexander Artemenko <svetlyak.40wt@gmail.com>
| author |
Alexander Artemenko <svetlyak.40wt@gmail.com> |
| date |
Tue Nov 25 05:20:24 2008 +0300 |
| parents |
7664af4d7943 |
| children |
802962eb45bb |
line source
4 This two applications provide 3 connected services:
5 pingback server, pingback client and directory ping client.
6 It depends on the [django-xmlrpc][].
11 First, install the [django-xmlrpc][] app. You download it
12 from [my bzr repository][django-xmlrpc] (it based on the
13 https://launchpad.net/django-xmlrpc with minor changes
14 for setuptools packaging), or just use setuptools:
16 easy_install -f http://pypi.aartemenko.com django-xmlrpc
18 Next, download and install `django-pingback`:
20 * download sources from [my branch at github][github-pingback]
21 (this version is based on [Alexander Solovyov's][piranha-version] code).
22 * or use `easy_install -f http://pypi.aartemenko.com django-pingback`
23 * add `pingback` to your `INSTALLED_APPS`
24 * run `./manage.py syncdb`
25 * setup client and server callbacks.
31 Pingback server receives pings from other sites, so, we must
32 create function which binds our URLs an objects.
34 But first of all, add this urlpattern to your urls configuration:
36 ((r'^xmlrpc/$', 'django_xmlrpc.views.handle_xmlrpc', {}, 'xmlrpc'))
38 It is a handler for all xmlrpc requests.
40 Usually, blog has a detailed view for each post. Suppose that
41 out view has name `post_detail` and accepts one keyword arguments
44 Here is simple example, how to make Post objects pingable:
46 from datetime import time, date, datetime
47 from time import strptime
48 from blog.models import Post
49 from pingback import create_ping_func
50 from django_xmlrpc import xmlrpcdispatcher
52 # create simple function which returns
53 # Post object and accepts exactly same
54 # arguments as 'details' view.
55 def pingback_blog_handler(slug, **kwargs):
56 return Post.objects.get(slug=slug)
58 # define association between view name and our handler
59 ping_details = {'post_detail': pingback_blog_handler}
61 # create xml rpc method, which will process all
63 ping_func = create_ping_func(**ping_details)
65 # register this method in the dispatcher
66 xmlrpcdispatcher.register_function(ping_func, 'pingback.ping')
68 Now, go at you http://mysweetsite.com/xmlrpc/ and you should
69 see `pingback.ping` method among few other system methods. If it
70 is not there, then you made mistake in you server setup.
72 Also, you need to tell other sites, that your blog accepts
73 pingbacks. You can do it by adding a link in the head of your site:
75 <link rel="pingback" href="{% url 'xmlrpc' %}" />
77 Or by adding X-Pingback HTTP header. Do do this, just add such line
80 MIDDLEWARE_CLASSES = [
82 'pingback.middleware.XPingMiddleware',
85 Connecting client signals
86 -------------------------
88 Let's suppose, that you have a blog and want to ping external sites
89 (like Technorati) on post save, and to receive pingbacks from other
90 sites. Next two sections contain simple 'how-to' enable these features.
92 At first, setup configuration in the settings, here is an example:
95 'http://ping.blogs.yandex.ru/RPC2',
96 'http://rpc.technorati.com/rpc/ping',
100 Next, you must connect some signals to ping workers,
101 which created using `ping_external_links` and `ping_directories`
104 from django.db.models import signals
105 from pingback.client import ping_external_links, ping_directories
106 from blog.models import Post
107 signals.post_save.connect(
108 ping_external_links(content_attr = 'html',
109 url_attr = 'get_absolute_url'),
110 sender = Post, weak = False)
112 signals.post_save.connect(
113 ping_directories(content_attr = 'html',
114 url_attr = 'get_absolute_url'),
115 sender = Post, weak = False)
117 Please, note, that in the content_attr you must give either attr's or
118 method's name, which returns HTML content of the object.
120 If you don't have such attr or method, for example if you apply
121 markdown filter in the template, then `content_func` attr can be used
122 instead of the `content_attr`.
124 `content_func` also must return HTML, but it accepts an instance as it's
127 Pay attention to the `weak = False` attribute. If you forget about it,
128 django's event dispatcher remove you signal handler.
133 To show pingbacks on your page, you can use code like this:
135 {% load pingback_tags %}
136 {% get_pingback_list for object as pingbacks %}
139 {% for pingback in pingbacks %}
140 <div class="b-pingback">
142 <a name="pingback-{{ pingback.id }}" href="{{ object.get_absolute_url }}#pingback-{{ pingback.id }}" class="b-permlink">permalink</a>
143 {{ pingback.date }}, pingback from {{ pingback.url|urlizetrunc:40 }}:
146 <p>{{ pingback.content }}</p>
151 Also, for can use `{% get_pingback_count for object as cnt %}`, to save
152 pingbacks' count in the context variable.
154 [django-xmlrpc]: https://code.launchpad.net/~aartemenko/django-xmlrpc/svetlyak40wt
155 [github-pingback]: http://github.com/svetlyak40wt/django-pingback/tree/svetlyak40wt
156 [piranha-version]: http://hg.piranha.org.ua/django-pingback/