Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def chat_init(message):
payload = get_request_object(message)
sender_group = get_group_id_for_user(message.user)
view_user = get_object_or_404(User, username=payload['view_user'])
msg_list = get_msg_data(payload['after'], message.user, view_user)
resp = {'action': 'chat.init', 'msg_list': msg_list}
Group(sender_group).send({'text': json.dumps(resp)})
def ws_message(message):
print "Message recieved from client side and the content is ", message.content['text']
# prefix, label = message['path'].strip('/').split('/')
socketid = message.content['text']
Group(socketid).add(message.reply_channel)
log_to_terminal(socketid, {"info": "User added to the Channel Group"})
def process_stream(message):
message_parts = message.content['text'].split(',')
dorm_name, machine_name, X, Y, Z = (
message_parts[0], message_parts[1], float(message_parts[2]), float(message_parts[3]), float(message_parts[4]))
dorm = Building.objects.get(name=dorm_name)
try:
machine = LaundryMachine.objects.get(building=dorm, name = machine_name)
machine_cache = machine_table[machine.building.name+'_'+machine.name]
magnitude = math.sqrt((abs(X)**2 + abs(Y)**2 + abs(Z)**2)/3.0)
add_entry(machine_cache, magnitude, CACHE_SIZE)
status, variance = classify_status(machine_cache)
Group('machine-%d' % machine.pk).send({'text': str(variance)+','+str(status)})
if machine.status != status:
StatusChange(machine=machine, new_status=status).save()
machine.status = status
machine.save()
except Exception as e:
raise
# Typical error text; pass it along
raise exceptions.ParseError(detail=survey['text'])
else:
# Something odd; hopefully it can be coerced into a string
raise exceptions.ParseError(detail=survey)
# Let the superclass handle updates to the other fields
noti = existing_xform.logs.create(source=request.user, type=7, title="Kobo form Updated",
organization=request.organization,
description="new kobo form {0} Updated by {1}".
format(existing_xform.title, request.user.username))
result = {}
result['description'] = noti.description
result['url'] = noti.get_absolute_url()
ChannelGroup("notify-0").send({"text":json.dumps(result)})
if noti.organization:
ChannelGroup("notify-{}".format(noti.organization.id)).send({"text":json.dumps(result)})
return super(XFormViewSet, self).update(request, pk, *args, **kwargs)
ChannelGroup("project-{}".format(fxf.site.project.id)).send({"text": json.dumps(result)})
else:
fxf.save()
noti = fxf.logs.create(source=self.request.user, type=18, title="Schedule",
organization=fxf.project.organization,
project = fxf.project, content_object=fxf, extra_object=fxf.project, extra_message='{0} form {1}'.format(fxf.form_type(), fxf.xf.title),
description='{0} assigned new Schedule form {1} to {2} '.format(
self.request.user.get_full_name(),
fxf.xf.title,
fxf.project.name
))
result = {}
result['description'] = noti.description
result['url'] = noti.get_absolute_url()
# ChannelGroup("site-{}".format(fxf.site.id)).send({"text": json.dumps(result)})
ChannelGroup("project-{}".format(fxf.project.id)).send({"text": json.dumps(result)})
def new_topic_forum(forum, json_data_topic):
"""
Send new topic to timeline forum
Args:
forum: Forum to send.
json_data_topic (list): Data for create a new topic.
"""
Group("forum-%s" % forum).send({
'text': json.dumps(json_data_topic)
})
def receive(self, text=None):
data = json.loads(text)
if (data['type'] == 'handshake'):
self._handshake(data)
elif (data['type'] == 'message'):
replies = self._message(data)
Group(str(data['recipient'])).send({
'text': json.dumps(replies[0])
})
self.send(json.dumps(replies[1]))
elif (data['type'] == 'messages_read'):
self._messages_read(data)
def users_ws_connect(message):
# Work out room name from path (ignore slashes)
print(message.content)
room = message.content['query_string'].strip("room=").strip("/")
print(room)
# Save room in session and add us to the group
message.channel_session['room'] = room
Group("chat-%s" % room).add(message.reply_channel)
if not message.user.is_anonymous():
Group('users').add(message.reply_channel)
Group('users').send({
'text': json.dumps({
'username': message.user.username,
'full_name': message.user.get_full_name(),
'is_logged_in': True
})
def disconnect(self,message,**kwargs):
Group("chats").discard(message.reply_channel)
def send_message(group_name, type, message):
group_name = utils.websocket_group_name(group_name)
Group(group_name).send({'text': dumps({"type": type, "message": message})})