当前位置: 首页>>代码示例>>Python>>正文


Python route_handler.register函数代码示例

本文整理汇总了Python中swampdragon.route_handler.register函数的典型用法代码示例。如果您正苦于以下问题:Python register函数的具体用法?Python register怎么用?Python register使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了register函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_middleware_processing

 def test_middleware_processing(self):
     route_handler.register(TestRouter)
     data = {'verb': 'say_hello', 'route': TestRouter.get_name()}
     with self.assertRaises(AttributeError):
         self.connection.dummy
     self.connection.on_message(data)
     self.assertTrue(self.connection.dummy)
开发者ID:boris-savic,项目名称:swampdragon,代码行数:7,代码来源:test_subscriber_connection.py

示例2: setUp

 def setUp(self):
     route_handler.register(NotificationRouter)
     backends.backends = [('realtime', RealtimeNotification)]
     user_manager.clear()
     self.user_a = User.objects.create(first_name='Veronica', username='veronica')
     self.user_b = User.objects.create(first_name='Jonas', username='jonas')
     self.user_c = User.objects.create(first_name='Benedicte', username='bennitrix')
     user_manager.add_user(self.user_a.pk)
     user_manager.add_user(self.user_b.pk)
     user_manager.add_user(self.user_c.pk)
开发者ID:johnfraney,项目名称:swampdragon-notifications,代码行数:10,代码来源:test_realtime_notifications.py

示例3: test_validate_field_from_router

 def test_validate_field_from_router(self):
     """
     Ensure that both the text and number error message
     is raised upon validation
     """
     data = {'text': 'foo', 'number': 8}
     route_handler.register(Router)
     self.connection.call_verb(Router.route_name, 'create', **data)
     self.assertEqual(self.connection.last_message['context']['state'], ERROR)
     self.assertIn('text', self.connection.last_message['data'])
     self.assertIn('number', self.connection.last_message['data'])
开发者ID:CptLemming,项目名称:swampdragon,代码行数:11,代码来源:test_serializer_validation.py

示例4: get_object

    model = UserMessage
    route_name = 'admin-message'
    permission_classes = [LoginRequired()]

    def get_object(self, **kwargs):
        return self.model.objects.get(pk=kwargs['pk'])

    def get_query_set(self, **kwargs):
        return self.model.all()

    def create(self, **kwargs):
        initial = self.get_initial('create', **kwargs)
        self.serializer = self.serializer_class(data=kwargs, initial=initial)
        pk = self.serializer.data['user']
        user = get_user_model().objects.get(pk=pk)
        msg = UserMessage.objects.create(
            text=self.serializer.data['text'],
            user=user,
            direction='to'
        )
        publish_data('user-message-%s' % user.pk, {
            'text': msg.text,
            'created_at': str(msg.created_at),
            'direction': 'from'
        })

        self.send('done')

route_handler.register(UserMessageRouter)
route_handler.register(AdminMessageRouter)
开发者ID:Praseetha-KR,项目名称:django-engage,代码行数:30,代码来源:routers.py

示例5: TodoListRouter

from swampdragon.route_handler import ModelRouter
from todo.models import TodoList, TodoItem
from todo.serializers import TodoListSerializer, TodoItemSerializer


class TodoListRouter(ModelRouter):
    route_name = 'todo-list'
    serializer_class = TodoListSerializer
    model = TodoList

    def get_object(self, **kwargs):
        return self.model.objects.get(pk=kwargs['id'])

    def get_query_set(self, **kwargs):
        return self.model.objects.all()


class TodoItemRouter(ModelRouter):
    route_name = 'todo-item'
    serializer_class = TodoItemSerializer
    model = TodoItem

    def get_object(self, **kwargs):
        return self.model.objects.get(pk=kwargs['id'])

    def get_query_set(self, **kwargs):
        return self.model.objects.filter(todo_list__id=kwargs['list_id'])


route_handler.register(TodoListRouter)
route_handler.register(TodoItemRouter)
开发者ID:Ragepanda12,项目名称:swampdragon_test,代码行数:31,代码来源:routers.py

示例6: ChatRouter

class ChatRouter(ModelRouter):
    route_name = 'chat'
    serializer_class = ChatSerializer
    include_related = [ChatMessageSerializer, ChatMessageSerializer]
    model = Chat

    def get_object(self, **kwargs):
        return self.model.objects.get(pk=kwargs['id'])

    def get_query_set(self, **kwargs):
        return self.model.objects.all()

class ChatMessageRouter(ModelRouter):
    route_name = 'chat-message'
    serializer_class = ChatMessageSerializer
    model = ChatMessage

    def get_object(self, **kwargs):
        return self.model.objects.get(pk=kwargs['id'])

    def get_query_set(self, **kwargs):
        return self.model.objects.all()

route_handler.register(MailRouter)
route_handler.register(MailReplyRouter)
route_handler.register(NotificationRouter)
route_handler.register(ChatRouter)
route_handler.register(ChatMessageRouter)

开发者ID:dmic23,项目名称:wease_dev,代码行数:28,代码来源:routers.py

示例7: NotificationRouter

from swampdragon import route_handler
from swampdragon.route_handler import ModelPubRouter

from .models import Notification
from .serializers import NotificationSerializer


class NotificationRouter(ModelPubRouter):
    valid_verbs = ['subscribe']
    route_name = 'notifications'
    model = Notification
    serializer_class = NotificationSerializer


route_handler.register(NotificationRouter)
开发者ID:huyquyet,项目名称:notifications,代码行数:15,代码来源:routers.py

示例8: get_query_set

        return self.model.objects.get(pk = kwargs['id'])

    def get_query_set(self, **kwargs):
        return self.model.objects.all()


class TicTacToeMoveRouter(ModelPubRouter):
    route_name = 'tic-tac-toe-move'
    model = TicTacToeMove
    serializer_class = model.serializer_class

    def get_initial(self, verb, **kwargs):
        if verb == 'create':
            try:
                tic_tac_toe = TicTacToe.objects.get(id = kwargs.get('tic_tac_toe_id'))
                return {'tic_tac_toe': tic_tac_toe}
            except TicTacToe.DoesNotExist:
                pass
        return dict()


    def get_object(self, **kwargs):
        return self.model.objects.get(pk = kwargs['id'])

    def get_query_set(self, **kwargs):
        return self.model.objects.filter(tic_tac_toe = kwargs['tic_tac_toe_id'])


route_handler.register(TicTacToeRouter)
route_handler.register(TicTacToeMoveRouter)
开发者ID:harpb,项目名称:tic-tac-toe,代码行数:30,代码来源:routers.py

示例9: WithFileRouter

    route_name = '_sdfileupload'


class WithFileRouter(BaseModelRouter):
    model = WithFile
    serializer_class = WithFileSerializer
    route_name = 'withfile-route'

    def get_object(self, **kwargs):
        return self.model.objects.get(pk=kwargs['id'])

    def get_query_set(self, **kwargs):
        return self.model.objects.all()


class MultiFileRouter(BaseModelRouter):
    model = MultiFileModel
    serializer_class = MultiFileSerializer
    route_name = 'multifile-route'

    def get_object(self, **kwargs):
        return self.model.objects.get(pk=kwargs['id'])

    def get_query_set(self, **kwargs):
        return self.model.objects.all()


route_handler.register(WithFileRouter)
route_handler.register(MultiFileRouter)
route_handler.register(FileUpload)
开发者ID:jonashagstedt,项目名称:swampdragon-fileupload,代码行数:30,代码来源:routers.py

示例10: ChatRouter

from swampdragon import route_handler
from swampdragon.route_handler import BaseRouter


class ChatRouter(BaseRouter):
    route_name = 'chat-route'
    valid_verbs = ['chat', 'subscribe']

    def get_subscription_channels(self, **kwargs):
        return ['chatroom']

    def chat(self, *args, **kwargs):
        errors = {}
        if 'name' not in kwargs or len(kwargs['name']) is 0:
            errors['name'] = 'Specify a name'

        if 'message' not in kwargs or len(kwargs['message']) is 0:
            errors['message'] = 'Enter a chat message'

        if errors:
            self.send_error(errors)
        else:
            self.send({'status': 'ok'})
            self.publish(self.get_subscription_channels(), kwargs)


route_handler.register(ChatRouter)
开发者ID:CptLemming,项目名称:swampdragon,代码行数:27,代码来源:routers.py

示例11: test_on_message

 def test_on_message(self):
     route_handler.register(TestRouter)
     data = {'verb': 'say_hello', 'route': TestRouter.get_name()}
     self.connection.on_message(data)
     self.assertTrue(self.connection.hello_said)
开发者ID:CptLemming,项目名称:swampdragon,代码行数:5,代码来源:test_subscriber_connection.py

示例12: setUp

 def setUp(self):
     route_handler.register(PersonRouter)
开发者ID:CptLemming,项目名称:swampdragon,代码行数:2,代码来源:test_selfpub_model_m2m_update.py

示例13: PlayerRouter

from swampdragon import route_handler
from swampdragon.route_handler import ModelRouter

from .models import Player
from .serializers import PlayerSerializer


class PlayerRouter(ModelRouter):
    route_name = 'player'
    serializer_class = PlayerSerializer
    model = Player

    def get_object(self, **kwargs):
        return self.model.objects.get(pk=kwargs['id'])

    def get_query_set(self, **kwargs):
        return self.model.objects.all()

route_handler.register(PlayerRouter)
开发者ID:olya-d,项目名称:django-game-backend-tutorial,代码行数:19,代码来源:routers.py

示例14: created

        event = Event.objects.filter(identifier = kwargs['identifier'])
        return self.model.objects.filter(event = event)
        
    def created(self, obj, **kwargs):
        data = self.serializer_class(instance=obj).serialize()
        chatData = dict({'data': data})
        base_channel = self.serializer_class.get_base_channel()
        identifier = kwargs['identifier']
        channel = base_channel + "identifier:" + identifier
        self.publish([channel], chatData)        
        super().created(obj, **kwargs)
            
class MarkerListRouter(BaseRouter):
    route_name = 'marker-list'
    valid_verbs = ['subscribe', 'get_markers']

    def get_markers(self, **kwargs):
        identifier = kwargs['identifier']
        local_channel = kwargs['local_channel']
        lat = kwargs['lat']
        lng = kwargs['lng']
        channel = "marker|identifier:" + identifier
        self.publish([channel], kwargs)
        
    def get_subscription_channels(self, **kwargs):
        identifier = kwargs['identifier']
        return ["marker|identifier:" + identifier]

route_handler.register(ChatListRouter)
route_handler.register(MarkerListRouter)
开发者ID:gm2bv,项目名称:mosi2map,代码行数:30,代码来源:routers.py

示例15: EventsRouter

from swampdragon import route_handler
from swampdragon.route_handler import ModelRouter
from turnover.models import Events
from turnover.serializers import EventsSerializer


class EventsRouter(ModelRouter):
    route_name = "events-list"
    serializer_class = EventsSerializer
    model = Events

    def get_object(self, **kwargs):
        return self.model.objects.get(pk=kwargs["id"])

    def get_query_set(self, **kwargs):
        return self.model.objects.all()


route_handler.register(EventsRouter)
开发者ID:joshfokis,项目名称:turnover,代码行数:19,代码来源:routers.py


注:本文中的swampdragon.route_handler.register函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。