Add missing fields in db
This commit is contained in:
parent
8d57245ccf
commit
c8ad274fc5
22
cuizin/db.py
22
cuizin/db.py
@ -1,4 +1,5 @@
|
|||||||
import base64
|
import base64
|
||||||
|
import json
|
||||||
|
|
||||||
import magic
|
import magic
|
||||||
import requests
|
import requests
|
||||||
@ -13,18 +14,26 @@ database = SqliteDatabase('recipes.db')
|
|||||||
database.connect()
|
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):
|
class Recipe(Model):
|
||||||
title = CharField()
|
title = CharField()
|
||||||
url = CharField(null=True, unique=True)
|
url = CharField(null=True, unique=True)
|
||||||
author = CharField(null=True)
|
author = CharField(null=True)
|
||||||
picture = BlobField(null=True)
|
picture = BlobField(null=True)
|
||||||
short_description = TextField(null=True)
|
short_description = TextField(null=True)
|
||||||
nb_person = None # TODO
|
nb_person = TextField(null=True)
|
||||||
preparation_time = IntegerField(null=True) # In minutes
|
preparation_time = IntegerField(null=True) # In minutes
|
||||||
cooking_time = IntegerField(null=True) # In minutes
|
cooking_time = IntegerField(null=True) # In minutes
|
||||||
ingredients = None # TODO
|
ingredients = JSONField(null=True)
|
||||||
instructions = TextField()
|
instructions = TextField()
|
||||||
comments = None # TODO
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
database = database
|
database = database
|
||||||
@ -32,11 +41,14 @@ class Recipe(Model):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def from_weboob(obj):
|
def from_weboob(obj):
|
||||||
recipe = Recipe()
|
recipe = Recipe()
|
||||||
for field in ['title', 'url', 'author', 'picture_url', 'short_description',
|
for field in ['title', 'url', 'author', 'picture_url',
|
||||||
'preparation_time', 'cooking_time', 'instructions']:
|
'short_description', 'preparation_time', 'cooking_time',
|
||||||
|
'ingredients', 'instructions']:
|
||||||
value = getattr(obj, field)
|
value = getattr(obj, field)
|
||||||
if value:
|
if value:
|
||||||
setattr(recipe, field, 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
|
recipe.picture = requests.get(obj.picture_url).content
|
||||||
return recipe
|
return recipe
|
||||||
|
|
||||||
|
@ -17,8 +17,13 @@
|
|||||||
<p><v-icon>whatshot</v-icon> {{ recipe.cooking_time }} mins</p>
|
<p><v-icon>whatshot</v-icon> {{ recipe.cooking_time }} mins</p>
|
||||||
</v-flex>
|
</v-flex>
|
||||||
</v-layout>
|
</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.short_description }}</p>
|
||||||
<p>{{ this.recipe.ingredients }}</p>
|
|
||||||
<p>{{ this.recipe.instructions }}</p>
|
<p>{{ this.recipe.instructions }}</p>
|
||||||
<p v-if="this.recipe.url">
|
<p v-if="this.recipe.url">
|
||||||
<a :href="this.recipe.url">Original link</a>
|
<a :href="this.recipe.url">Original link</a>
|
||||||
|
Loading…
Reference in New Issue
Block a user