view README.md @ 32:6ca8eadcd22d
fix relative urls and some additional logging
| author |
Alexander Artemenko <svetlyak.40wt@gmail.com> |
| date |
Sun Dec 14 18:10:11 2008 +0200 (6 months ago) |
| parents |
f3bc8c661309 |
| children |
f06451c79457 |
line source
4 This two applications provide 3 connected services: 5 pingback server, pingback client and directory ping client. 7 Depends on the [django-xmlrpc][]. 12 First, install the [django-xmlrpc][] application. You can download it either 13 from [repo][django-xmlrpc] or just use setuptools: 15 easy_install -f http://pypi.aartemenko.com django-xmlrpc 17 Next, download and install `django-pingback`: 19 * download sources from main [repository][django-pingback] 20 * or use `easy_install django-pingback` 21 * add `pingback` to your `INSTALLED_APPS` 22 * run `./manage.py syncdb` 23 * setup client and server callbacks. 29 Pingback server receives pings from other sites, so, we must 30 create function which binds our URLs an objects. 32 But first of all, add this urlpattern to your urls configuration: 34 ((r'^xmlrpc/$', 'django_xmlrpc.views.handle_xmlrpc', {}, 'xmlrpc')) 36 It is a handler for all xmlrpc requests. 38 Usually, blog has a detailed view for each post. Suppose that 39 our view has name `post_detail` and accepts one keyword arguments 42 Here is simple example, how to make Post objects pingable: 44 from datetime import time, date, datetime 45 from time import strptime 47 from blog.models import Post 48 from pingback import create_ping_func 49 from django_xmlrpc import xmlrpcdispatcher 51 # create simple function which returns Post object and accepts 52 # exactly same arguments as 'details' view. 53 def pingback_blog_handler(slug, **kwargs): 54 return Post.objects.get(slug=slug) 56 # define association between view name and our handler 57 ping_details = {'post_detail': pingback_blog_handler} 59 # create xml rpc method, which will process all 61 ping_func = create_ping_func(**ping_details) 63 # register this method in the dispatcher 64 xmlrpcdispatcher.register_function(ping_func, 'pingback.ping') 66 Now, go at you http://mysweetsite.com/xmlrpc/ and you should 67 see `pingback.ping` method among few other system methods. If it 68 is not there, then you made mistake in you server setup. 70 Also, you need to tell other sites, that your blog accepts 71 pingbacks. You can do it by adding a link in the head of your site: 73 <link rel="pingback" href="{% url 'xmlrpc' %}" /> 75 Or by adding X-Pingback HTTP header. Do do this, just add such line 78 MIDDLEWARE_CLASSES = [ 80 'pingback.middleware.XPingMiddleware', 83 Connecting client signals 84 ------------------------- 86 Let's suppose, that you have a blog and want to ping external sites 87 (like Technorati) on post save, and to receive pingbacks from other 88 sites. Next two sections contain simple 'how-to' enable these features. 90 At first, setup configuration in the settings, here is an example: 93 'http://ping.blogs.yandex.ru/RPC2', 94 'http://rpc.technorati.com/rpc/ping', 98 Next, you must connect some signals to ping workers, 99 which created using `ping_external_links` and `ping_directories` 102 from django.db.models import signals 103 from pingback.client import ping_external_links, ping_directories 104 from blog.models import Post 106 signals.post_save.connect( 107 ping_external_links(content_attr = 'html', 108 url_attr = 'get_absolute_url'), 109 sender = Post, weak = False) 111 signals.post_save.connect( 112 ping_directories(content_attr = 'html', 113 url_attr = 'get_absolute_url'), 114 sender = Post, weak = False) 116 Please note, that in the `content_attr` you must give either attribute or method 117 name, which returns HTML content of the object. 119 If you don't have such attribute or method, for example if you apply markdown 120 filter in the template, then `content_func` argument can be used instead of the 123 `content_func` must return HTML, and must accepts an instance as a single 126 Pay attention to the `weak = False` argument. If case of omitting django's event 127 dispatcher will remove your signal. 132 To show pingbacks on your page, you can use code like this: 134 {% load pingback_tags %} 135 {% get_pingback_list for object as pingbacks %} 138 {% for pingback in pingbacks %} 139 <div class="b-pingback"> 141 <a name="pingback-{{ pingback.id }}" href="{{ object.get_absolute_url }}#pingback-{{ pingback.id }}" class="b-permlink">permalink</a> 142 {{ pingback.date }}, pingback from {{ pingback.url|urlizetrunc:40 }}: 145 <p>{{ pingback.content }}</p> 150 Also you can use `{% get_pingback_count for object as cnt %}`, to save 151 pingbacks' count in the context variable. 153 [django-xmlrpc]: https://code.launchpad.net/~aartemenko/django-xmlrpc/svetlyak40wt 154 [django-pingback]: http://hg.piranha.org.ua/django-pingback/