# vim: set fileencoding=utf-8 ts=4 shiftwidth=4 softtabstop=4 expandtab: # # Usando el código de # Brendan W. McAdams # http://code.djangoproject.com/wiki/XML-RPC from SimpleXMLRPCServer import SimpleXMLRPCDispatcher from django.http import HttpResponse from blog.models import Articulo dispatcher = SimpleXMLRPCDispatcher(allow_none=False, encoding=None) def rpc_handler(request): """ the actual handler: if you setup your urls.py properly, all calls to the xml-rpc service should be routed through here. If post data is defined, it assumes it's XML-RPC and tries to process as such Empty post assumes you're viewing from a browser and tells you about the service. """ response = HttpResponse() if len(request.POST): response.write(dispatcher._marshaled_dispatch(request.raw_post_data)) else: response.write("

Éste es el servicio XML-RPC.

") response.write("

Deberías invocarlo usando un cliente XML-RPC.

") response.write("

Métodos disponibles:

") response['Content-length'] = str(len(response.content)) return response def articulos_blog(max=10): """ Devuelve los últimos artículos del blog. Admite un argumento, que indica el número de artículos máximo a devolver. """ articulos = Articulo.objects.all() lista = [] for a in articulos: lista.append({ "titulo": a.titulo, "autor": a.autor.username, "created_on": a.created_on.__str__(), "texto": a.texto }) return lista dispatcher.register_function(articulos_blog, 'articulos_blog')