def tool_to_json(tool: ToolDescription): checkout = ToolCheckout.find_by_tool(tool) checkout_model = {} if checkout is not None: checkout_model = { "active": True, "started": checkout.started, "account": checkout.account, "username": checkout.account.username, } else: checkout_model = { "active": False, } return { **model_to_json(tool), **{ "name": tool.name, "description": tool.description, "circle": tool.circle.name, "checkout": checkout_model, } }
def badge_to_json(b: AccountBadge): return { **model_to_json(b), **{ "account_id": b.account_id, "account_username": b.account.username, "awarded_by_id": b.awarded_by_id, "awarded_by_username": b.awarded_by.username if b.awarded_by else None, "description_id": b.description_id } }
def badge_description_to_json(bd: BadgeDescription): return { **model_to_json(bd), **{ "title": bd.title, "description": bd.description, "slug": bd.slug, "icon": bd.icon, "color": bd.color, "certification_circle_id": bd.certification_circle_id } }