本文整理汇总了Python中models.Item.to_json方法的典型用法代码示例。如果您正苦于以下问题:Python Item.to_json方法的具体用法?Python Item.to_json怎么用?Python Item.to_json使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Item
的用法示例。
在下文中一共展示了Item.to_json方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_message
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import to_json [as 别名]
def on_message(self, message):
data = json.loads(message)
if "update_type" in data and data["update_type"] == "draw":
board_id = data["board_id"]
broadcastData = data
self.broadcast(board_id, broadcastData, write_to_self=False)
return
message_type = data.get('message_type')
board_id = data["board_id"]
if message_type and message_type == 'user_update':
self._update_user(board_id, data['username'])
self._broadcast_user_display(board_id)
elif message_type and message_type == 'board_name_update':
name = self._update_board_name(board_id, data['name'])
self._broadcast_board_name_update(board_id, name)
else:
board = Board.get(board_id)
item = Item(**data["item"])
board.updateItem(item)
board.save()
broadcastData = {
"update_type": "pos_change",
"item": json.loads(item.to_json())
}
self.broadcast(board_id, broadcastData, write_to_self=False)
示例2: test_format_item_to_json
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import to_json [as 别名]
def test_format_item_to_json(self):
item = Item(1, "test name", "Medium", "This is a test description")
item.save()
results = item.to_json()
expected_results = dict(id=1, user_id=1, name="test name", priority="Medium",
description="This is a test description")
self.assertEqual(expected_results, results)
示例3: post
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import to_json [as 别名]
def post(self):
data = json.loads(request.data)
if 'name' not in data:
return make_response('The list item name is required', 400)
else:
name = data.get('name')
user_id = data.get('user_id')
description = data.get('description') if 'description' in data else None
priority = data.get('priority') if 'priority' in data else None
item = Item(user_id, name, priority, description)
item.save()
return make_response(jsonify(item.to_json()), 200)
示例4: test_to_json
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import to_json [as 别名]
def test_to_json(self):
item = Item(
sentinel.name, sentinel.room, sentinel.weight,
sentinel.description, sentinel.is_fragile
)
self.assertEquals(
item.to_json(),
{
"name": sentinel.name,
"description": sentinel.description,
"weight": sentinel.weight,
"is_fragile": sentinel.is_fragile
}
)
示例5: put
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import to_json [as 别名]
def put(self, id=None, *args, **kwargs):
board_id = self.get_argument('board_id')
url = self.get_argument('url')
image_url = self.get_argument('image_url')
#tags = self.get_arguments('tags[]', [])
tags = self.request.arguments.get('tags[]');
#tags = self.get_argument('tags[]', [])
pos_x = self.get_argument('pos_x')
pos_y = self.get_argument('pos_y')
scale = self.get_argument('scale')
locked = self.get_argument('locked')
item = Item(id=uuid.uuid4(), url=url, image_url=image_url, tags=tags,
pos_x=pos_x, pos_y=pos_y, scale=scale, locked=locked)
b = Board.get(board_id)
b.items.append(item)
b.save()
data = {'update_type': 'add_item', 'item': json.loads(item.to_json())}
for socket in sockets[board_id]:
EchoWebSocket.safe_write_to_socket(socket, json.dumps(data))