def test_camera(self): camera = models_school.Camera.objects.first() pp.pprint(camera.to_mongo()) foo = GetterDict(camera) pp.pprint(foo.keys()) pp.pprint(foo['id']) out_cam = schemas_school.Camera.from_orm(camera) pp.pprint(out_cam.dict()) pp.pprint(out_cam.to_json())
def test_getdict(): class TestCls: a = 1 b: int def __init__(self): self.c = 3 @property def d(self): return 4 def __getattr__(self, key): if key == 'e': return 5 else: raise AttributeError() t = TestCls() gd = GetterDict(t) assert gd.keys() == ['a', 'c', 'd'] assert gd.get('a', None) == 1 assert gd.get('b', None) is None assert gd.get('b', 1234) == 1234 assert gd.get('c', None) == 3 assert gd.get('d', None) == 4 assert gd.get('e', None) == 5 assert gd.get('f', 'missing') == 'missing' assert list(gd.values()) == [1, 3, 4] assert list(gd.items()) == [('a', 1), ('c', 3), ('d', 4)] assert list(gd) == ['a', 'c', 'd'] assert gd == {'a': 1, 'c': 3, 'd': 4} assert 'a' in gd assert len(gd) == 3 assert str(gd) == "<GetterDict(TestCls) {'a': 1, 'c': 3, 'd': 4}>"
def getter_dict(_cls, name_orm: MealPlan): try: return { **GetterDict(name_orm), "group": name_orm.group.name, "shopping_list": name_orm.shopping_list.id, } except Exception: return { **GetterDict(name_orm), "group": name_orm.group.name, "shopping_list": None, }
def getter_dict(cls, ormModel: User): return { **GetterDict(ormModel), "group": ormModel.group.name, "favorite_recipes": [x.slug for x in ormModel.favorite_recipes], }
def test_getdict(): class TestCls: a = 1 b: int def __init__(self): self.c = 3 @property def d(self): return 4 def __getattr__(self, key): if key == 'e': return 5 else: raise AttributeError() t = TestCls() gd = GetterDict(t) assert gd.keys() == set() assert gd.get('a', None) == 1 assert gd.get('b', None) is None assert gd.get('b', 1234) == 1234 assert gd.get('c', None) == 3 assert gd.get('d', None) == 4 assert gd.get('e', None) == 5 assert gd.get('f', 'missing') == 'missing'
def getter_dict(_cls, name_orm: RecipeModel): return { **GetterDict(name_orm), # "recipe_ingredient": [x.note for x in name_orm.recipe_ingredient], "recipe_category": [x.name for x in name_orm.recipe_category], "tags": [x.name for x in name_orm.tags], "tools": [x.tool for x in name_orm.tools], "extras": {x.key_name: x.value for x in name_orm.extras}, }
def getter_dict(_cls, orm_model: Group): return { **GetterDict(orm_model), "webhook_urls": [x.url for x in orm_model.webhook_urls if x], }
def getter_dict(cls, ormModel: User): return { **GetterDict(ormModel), "group": ormModel.group.name, }
def getter_dict(_cls, name_orm: User): return { **GetterDict(name_orm), "group": name_orm.group.name, }
def getter_dict(_cls, name_orm): return { **GetterDict(name_orm), "total_recipes": len(name_orm.recipes), }
def getter_dict(_cls, name_orm: RecipeModel): return { **GetterDict(name_orm), "recipeCategory": [x.name for x in name_orm.recipeCategory], "tags": [x.name for x in name_orm.tags], }
def getter_dict(_cls, name_orm): return { **GetterDict(name_orm), "recipe_slug": name_orm.recipe.slug, }
def getter_dict(cls, ormModel: ShoppingList): return { **GetterDict(ormModel), "group": ormModel.group.name, }