本文整理汇总了Python中swampdragon.route_handler.register函数的典型用法代码示例。如果您正苦于以下问题:Python register函数的具体用法?Python register怎么用?Python register使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了register函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: TestServerRouter
from dataset_manager.enums import ComputingStateType
from testing import tasks
class TestServerRouter(BaseRouter):
route_name = 'test_server'
valid_verbs = BaseRouter.valid_verbs + ['test', 'test_celery']
def test(self):
try:
time.sleep(2)
self.send({"state": ComputingStateType.SUCCESS})
except:
self.send({"state": ComputingStateType.FAILED})
def test_celery(self):
try:
task = tasks.test.delay()
time.sleep(2)
state = task.state
if state == "SUCCESS":
self.send({"state": ComputingStateType.SUCCESS})
else:
self.send({"state": ComputingStateType.FAILED})
except:
self.send({"state": ComputingStateType.FAILED})
route_handler.register(TestServerRouter)
开发者ID:PeterZs,项目名称:ers,代码行数:30,代码来源:routers.py
示例17: get_subscription_contexts
def get_subscription_contexts(self, **kwargs):
return {'room__users__pk': self.connection.user.pk}
class ProfileRouter(ModelRouter):
route_name = 'profiles'
serializer_class = ProfileSerializer
model = Profile
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(MessageRouter)
route_handler.register(ProfileRouter)
# Modified OnlineUsersRouter
class ChatOnlineUsersRouter(OnlineUsersRouter):
def subscribe(self, **kwargs):
if not self.connection.user:
return
#super().subscribe(**kwargs)
if self.connection.user:
user_manager.add_user(self.connection.user.pk)
route_handler.registered_handlers['swampdragon-online'] = ChatOnlineUsersRouter
开发者ID:bufke,项目名称:chat-experiment,代码行数:30,代码来源:routers.py
示例18: NotifyRouter
'''
'''
from django.contrib.auth.models import User
from swampdragon import route_handler
from swampdragon.route_handler import BaseRouter
from swampdragon_notifications.notifier import notify_users
from .models import *
class NotifyRouter(BaseRouter):
valid_verbs = ['subscribe', 'notify_everyone', 'notify_everyone_but_me']
route_name = 'notifier'
def notify_everyone(self, name):
users = User.objects.all()
# foo = Foo.objects.create(name=name)
notify_users(users, subject="Hello", notification_type='foo')
def notify_everyone_but_me(self, name):
users = User.objects.exclude(pk=self.connection.user.pk)
# foo = Foo.objects.create(name=name)
notify_users(users, subject="hello everyone", notification_type='foo')
route_handler.register(NotifyRouter)
开发者ID:PythonScorpions,项目名称:gpsstops,代码行数:27,代码来源:router.py
示例19: get_query_set
return self.model.objects.get(initiator = kwargs['initiator'],problem = kwargs['problem'])
def get_query_set(self, **kwargs):
return self.model.objects.all()
class MultiMoveRouter(ModelRouter):
route_name = 'MultiMove'
serializer_class = MultiMoveSerializer
model = MultiMove
def get_object(self, **kwargs):
return self.model.objects.get(solution= kwargs['solution'], piece_key = kwargs['piece_key'])
def get_query_set(self, **kwargs):
return self.model.objects.filter(solution= kwargs['solution'])
class ChatRouter(ModelRouter):
route_name = 'Chat'
serializer_class = ChatSerializer
model = Chat
def get_object(self, **kwargs):
return self.model.objects.get(solution= kwargs['solution'], username = kwargs['username'], initiator = kwargs['initiator'])
def get_query_set(self, **kwargs):
return self.model.objects.filter(solution__problem__name = kwargs['problem_name'])
route_handler.register(MultiSolRouter)
route_handler.register(MultiMoveRouter)
route_handler.register(ChatRouter)
开发者ID:vshekar,项目名称:ThinkAgain,代码行数:30,代码来源:routers.py
示例20: get_conversation
message = client.compose(kwargs['uuid'], message)
self.send(message)
except Exception, e:
self.send_error({'message': 'Error composing message'})
@login_required
def get_conversation(self, **kwargs):
user = self.connection.user
token = UserProfile.objects.get(user=user).token
if 'uuid' not in kwargs:
self.send_error({'message': 'Missing room uuid'})
return
try:
client = ChatClient(token)
conv = client.get_conversation(kwargs['uuid'])
conv['messages'].reverse()
self.send(conv)
except Exception, e:
self.send_error({'message': 'Error retrieving conversation'})
route_handler.register(SessionRouter)
route_handler.register(ChatRouter)
开发者ID:daedafusion,项目名称:django-argos,代码行数:30,代码来源:routers.py
注:本文中的swampdragon.route_handler.register函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论