def handle_chat_message(sender, request, event, **kwargs): socket = sender session = socket.session message = event.args[0] if not session.user_name: event.ack(failure()) else: socket.broadcast_emit('chat_message', session.user_name, message, include_self = True) event.ack(success())
def handle_set_name(sender, request, event, **kwargs): socket = sender user_name = event.args[0] session = socket.session if session.user_name: socket.broadcast_emit('system_message', '{0} changed his name to {1}'.format( session.user_name, user_name), include_self = True) else: socket.broadcast_emit('system_message', '{0} has joined'.format(user_name), include_self = True) session.user_name = user_name event.ack(success())
def handle_chat_message(sender, request, event, **kwargs): socket = sender session = socket.session message = event.args[0] namespace = kwargs['namespace'] if 'user_name' not in session: result = failure() else: namespace.broadcast_event('chat_message', session['user_name'], message) result = success() return result
def handle_set_name(sender, request, event, **kwargs): socket = sender user_name = event.args[0] namespace = kwargs['namespace'] session = socket.session if 'user_name' in session: namespace.broadcast_event('system_message', '{0} changed his name to {1}'.format( session['user_name'], user_name)) else: namespace.broadcast_event('system_message', '{0} has joined'.format(user_name)) session['user_name'] = user_name return success()
def handle_set_name(sender, request, event, **kwargs): socket = sender user_name = event.args[0] namespace = kwargs['namespace'] session = socket.session if 'user_name' in session: namespace.broadcast_event( 'system_message', '{0} changed his name to {1}'.format(session['user_name'], user_name)) else: namespace.broadcast_event('system_message', '{0} has joined'.format(user_name)) session['user_name'] = user_name return success()
def handle_create_shortcut(sender, request, event, **kwargs): data = event.args[0] shortcut = data.get('shortcut', '') if shortcut and not Shortcut.is_available(shortcut): event.ack(failure(message = 'Skrót {0!r} jest juz zajety'.format(shortcut))) return url = data.get('url') if not url.startswith('http'): url = 'http://' + url print(url) try: URLValidator()(url) except: event.ack(failure(message = 'Adres {0!r} jest niepoprawnym URL-em'.format(url))) return shortcut = Shortcut(shortcut = shortcut, url = url) shortcut.full_clean() shortcut.save() event.ack(success(shortcut_url = 'http://{0}/{1}'.format(settings.SERVER_ADDRESS, shortcut.shortcut)))
def handle_shortcut_availability(sender, request, event, **kwargs): shortcut = Shortcut.normalize_shortcut(event.args[0]) available = Shortcut.is_available(shortcut) event.ack(success(available = available))