From c8ad274fc53bb22abdd400e569b9480194ed85d8 Mon Sep 17 00:00:00 2001 From: "Phyks (Lucas Verney)" Date: Wed, 28 Feb 2018 23:11:22 +0100 Subject: [PATCH] Add missing fields in db --- cuizin/db.py | 22 +++++++++++++++++----- cuizin/js_src/components/Recipe.vue | 7 ++++++- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/cuizin/db.py b/cuizin/db.py index e1bebea..fbd4cc4 100644 --- a/cuizin/db.py +++ b/cuizin/db.py @@ -1,4 +1,5 @@ import base64 +import json import magic import requests @@ -13,18 +14,26 @@ database = SqliteDatabase('recipes.db') database.connect() +class JSONField(TextField): + def db_value(self, value): + return json.dumps(value) + + def python_value(self, value): + if value is not None: + return json.loads(value) + + class Recipe(Model): title = CharField() url = CharField(null=True, unique=True) author = CharField(null=True) picture = BlobField(null=True) short_description = TextField(null=True) - nb_person = None # TODO + nb_person = TextField(null=True) preparation_time = IntegerField(null=True) # In minutes cooking_time = IntegerField(null=True) # In minutes - ingredients = None # TODO + ingredients = JSONField(null=True) instructions = TextField() - comments = None # TODO class Meta: database = database @@ -32,11 +41,14 @@ class Recipe(Model): @staticmethod def from_weboob(obj): recipe = Recipe() - for field in ['title', 'url', 'author', 'picture_url', 'short_description', - 'preparation_time', 'cooking_time', 'instructions']: + for field in ['title', 'url', 'author', 'picture_url', + 'short_description', 'preparation_time', 'cooking_time', + 'ingredients', 'instructions']: value = getattr(obj, field) if value: setattr(recipe, field, value) + + recipe.nb_person = '-'.join(str(num) for num in obj.nb_person) recipe.picture = requests.get(obj.picture_url).content return recipe diff --git a/cuizin/js_src/components/Recipe.vue b/cuizin/js_src/components/Recipe.vue index 04006a7..c81f2d6 100644 --- a/cuizin/js_src/components/Recipe.vue +++ b/cuizin/js_src/components/Recipe.vue @@ -17,8 +17,13 @@

whatshot {{ recipe.cooking_time }} mins

+ +

{{ this.recipe.nb_person }}

{{ this.recipe.short_description }}

-

{{ this.recipe.ingredients }}

{{ this.recipe.instructions }}

Original link