Add missing fields in db

This commit is contained in:
Lucas Verney 2018-02-28 23:11:22 +01:00
parent 8d57245ccf
commit c8ad274fc5
2 changed files with 23 additions and 6 deletions

View File

@ -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

View File

@ -17,8 +17,13 @@
<p><v-icon>whatshot</v-icon> {{ recipe.cooking_time }} mins</p>
</v-flex>
</v-layout>
<ul>
<li v-for="ingredient in this.recipe.ingredients">
{{ ingredient }}
</li>
</ul>
<p>{{ this.recipe.nb_person }}</p>
<p>{{ this.recipe.short_description }}</p>
<p>{{ this.recipe.ingredients }}</p>
<p>{{ this.recipe.instructions }}</p>
<p v-if="this.recipe.url">
<a :href="this.recipe.url">Original link</a>