Exemplo n.º 1
0
                Street.objects.filter(name__icontains=term,
                                      district__name=district).values('name')
                [:10])
        ]

    def find_build(self, term, street, user):
        return [
            b['number'] for b in list(
                House.objects.filter(number__icontains=term,
                                     street__name=street).values('number')
                [:10])
        ]

    def find_street1(self, district, user):
        try:
            streets = Street.objects.filter(district__name__iexact=district)
            for s in streets:
                print s.name
        except Street.DoesNotExist:
            return Error('user `%s` not found' % district)
        else:
            return {
                'success': True,
                'pk': s.pk,
                'login': s.name,
            }


rpc_router = RpcRouter({
    'MainApi': MainApiClass(),
})
Exemplo n.º 2
0
from djangorpc import RpcRouter, Error, Msg
from djangorpc.exceptions import RpcExceptionEvent


class GameApiClass(object):

    def move(self, x, y, battle_id, user):
        print 'Move in battle #%s' % battle_id
        return {}

    def _extra_kwargs(self, request, *args, **kwargs):
        """
        We can to here something like::

            try:
                battle = Battle.objects.get(pk=kwargs['battle_id'])
            except Battle.DoesNotExist:
                raise RpcExceptionEvent('Invalid battle id!')
        """
        return {
            'battle_id': kwargs['battle_id']
        }


router = RpcRouter(
    {
        'GameApi': GameApiClass(),
    },
    url_namespace='game:rpc')
Exemplo n.º 3
0
    def func1(self, val, d='default', *args, **kwargs):
        print('val =', val)
        print('d =', d)
        print('args =', args)
        print('kwargs =', kwargs)
        return Msg('func1')

    @form_handler
    def submit(self, rdata, user):
        form = FeedbackForm(rdata)
        if form.is_valid():
            form.send()
            return Msg('Thank you for feedback.')
        else:
            return Error(form.get_errors())

    @form_handler
    def submit_file(self, rdata, files, user):
        form = FileForm(rdata, files)
        if form.is_valid():
            form.send()
            return Msg(form.cleaned_data['file'].size)
        else:
            return Error(form.get_errors())


router = RpcRouter({
    'MainApi': MainApiClass(),
}, url_namespace='main:rpc')
Exemplo n.º 4
0
from djangorpc import RpcRouter, Msg


class RpcApiClass(object):
    def log_something(self, msg, user):
        print(msg)
        return Msg('OK')


router = RpcRouter({'RpcApi': RpcApiClass()})
Exemplo n.º 5
0
            raise RpcExceptionEvent('Login please!')

    @login_required
    def func7(self, user):
        pass

    def set_cookie(self, user):
        response = RpcHttpResponse({'msg': 'Hello!'})
        response.set_cookie('rpccookie', '123456')
        return response


class CustomRouter(RpcRouter):
    def extra_kwargs(self, request, *args, **kwargs):
        return {'request': request, 'user': request.user}


custom_router = CustomRouter(
    {
        'TricksApi': TricksApiClass(),
        'TricksOneApi': TricksOneApiClass()
    },
    url_namespace='tricks:custom_rpc')

custom_router_one = RpcRouter(
    {
        'TricksTwoApi': TricksTwoApiClass(),
        'TricksThreeApi': TricksThreeApiClass()
    },
    url_namespace='tricks:custom_rpc_one')