from soaplib.serializers.primitive import Boolean, String, AnyAsDict, Float, Integer
from soaplib.serializers.clazz import Array
from soaplib.service import DefinitionBase, rpc
from soaplib.wsgi import Application
from soaplib.serializers.clazz import ClassSerializer

from django.http import HttpResponse from mosketeros.guias_app.guias.models import Brand, ModelCar from mosketeros.settings import MEDIA_URL # the class with actual web methods

class ReturnVal(ClassSerializer): # class types: brand = String vehicle = String category = String year = Integer file = String

class GuiasService2(DefinitionBase): @rpc(String, String, _returns=Boolean) def Test(self, f1, f2): return True @rpc( _returns=Array(ReturnVal)) def MostrarTodo(self): temp = [] for m in ModelCar.objects.all(): for g in m.guide_cars.filter(deleted=False): r = ReturnVal() r.brand = r.vehicle = r.year = g.year r.category= r.file = g.get_file_url() temp.append® return temp

# the class which acts as a wrapper between soaplib WSGI functionality and Django class DjangoSoapApp(Application): def call(self, request): # wrap the soaplib response into a Django response object django_response = HttpResponse() def start_response(status, headers): status, reason = status.split(' ', 1) django_response.status_code = int(status) for header, value in headers: django_response[header] = value response = super(DjangoSoapApp, self).call(request.META, start_response) django_response.content = '\n'.join(response) return django_response

soap_service = DjangoSoapApp([GuiasService2], name)

# test #python -c "import suds; print suds.client.Client('', cache=None).service.MostrarTodo()"