Skip to content

Commit

Permalink
Brevity: use reciperadar.db in preference to sqlalchemy module imports (
Browse files Browse the repository at this point in the history
  • Loading branch information
jayaddison committed May 28, 2020
1 parent 3d5b2a3 commit 58247a4
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 107 deletions.
15 changes: 5 additions & 10 deletions reciperadar/models/recipes/appliance.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
from sqlalchemy import (
Column,
ForeignKey,
String,
)

from reciperadar import db
from reciperadar.models.base import Storable


class DirectionAppliance(Storable):
__tablename__ = 'direction_appliances'

fk = ForeignKey('recipe_directions.id', ondelete='cascade')
direction_id = Column(String, fk, index=True)
fk = db.ForeignKey('recipe_directions.id', ondelete='cascade')
direction_id = db.Column(db.String, fk, index=True)

id = Column(String, primary_key=True)
appliance = Column(String)
id = db.Column(db.String, primary_key=True)
appliance = db.Column(db.String)

@staticmethod
def from_doc(doc):
Expand Down
27 changes: 10 additions & 17 deletions reciperadar/models/recipes/direction.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
from sqlalchemy import (
Column,
ForeignKey,
Integer,
String,
)
from sqlalchemy.orm import relationship

from reciperadar import db
from reciperadar.models.base import Storable
from reciperadar.models.recipes.appliance import DirectionAppliance
from reciperadar.models.recipes.utensil import DirectionUtensil
Expand All @@ -15,24 +8,24 @@
class RecipeDirection(Storable):
__tablename__ = 'recipe_directions'

fk = ForeignKey('recipes.id', ondelete='cascade')
recipe_id = Column(String, fk, index=True)
fk = db.ForeignKey('recipes.id', ondelete='cascade')
recipe_id = db.Column(db.String, fk, index=True)

id = Column(String, primary_key=True)
index = Column(Integer)
description = Column(String)
markup = Column(String)
appliances = relationship(
id = db.Column(db.String, primary_key=True)
index = db.Column(db.Integer)
description = db.Column(db.String)
markup = db.Column(db.String)
appliances = db.relationship(
'DirectionAppliance',
backref='recipe_directions',
passive_deletes='all'
)
utensils = relationship(
utensils = db.relationship(
'DirectionUtensil',
backref='recipe_directions',
passive_deletes='all'
)
vessels = relationship(
vessels = db.relationship(
'DirectionVessel',
backref='recipe_directions',
passive_deletes='all'
Expand Down
34 changes: 13 additions & 21 deletions reciperadar/models/recipes/ingredient.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,30 @@
from sqlalchemy import (
Column,
Float,
ForeignKey,
Integer,
String,
)
from sqlalchemy.orm import relationship

from reciperadar import db
from reciperadar.models.base import Searchable, Storable
from reciperadar.models.recipes.product import IngredientProduct


class RecipeIngredient(Storable, Searchable):
__tablename__ = 'recipe_ingredients'

fk = ForeignKey('recipes.id', ondelete='cascade')
recipe_id = Column(String, fk, index=True)
fk = db.ForeignKey('recipes.id', ondelete='cascade')
recipe_id = db.Column(db.String, fk, index=True)

id = Column(String, primary_key=True)
index = Column(Integer)
description = Column(String)
markup = Column(String)
product = relationship(
id = db.Column(db.String, primary_key=True)
index = db.Column(db.Integer)
description = db.Column(db.String)
markup = db.Column(db.String)
product = db.relationship(
'IngredientProduct',
backref='recipe_ingredient',
uselist=False,
passive_deletes='all'
)

quantity = Column(Float)
quantity_parser = Column(String)
units = Column(String)
units_parser = Column(String)
verb = Column(String)
quantity = db.Column(db.Float)
quantity_parser = db.Column(db.String)
units = db.Column(db.String)
units_parser = db.Column(db.String)
verb = db.Column(db.String)

@staticmethod
def from_doc(doc):
Expand Down
31 changes: 13 additions & 18 deletions reciperadar/models/recipes/product.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
from sqlalchemy import (
Boolean,
Column,
ForeignKey,
String,
)
from sqlalchemy.dialects import postgresql

from reciperadar import db
from reciperadar.models.base import Storable


class IngredientProduct(Storable):
__tablename__ = 'ingredient_products'

fk = ForeignKey('recipe_ingredients.id', ondelete='cascade')
ingredient_id = Column(String, fk, index=True)

id = Column(String, primary_key=True)
product_id = Column(String)
product = Column(String)
product_parser = Column(String)
is_plural = Column(Boolean)
singular = Column(String)
plural = Column(String)
category = Column(String)
contents = Column(postgresql.ARRAY(String))
fk = db.ForeignKey('recipe_ingredients.id', ondelete='cascade')
ingredient_id = db.Column(db.String, fk, index=True)

id = db.Column(db.String, primary_key=True)
product_id = db.Column(db.String)
product = db.Column(db.String)
product_parser = db.Column(db.String)
is_plural = db.Column(db.Boolean)
singular = db.Column(db.String)
plural = db.Column(db.String)
category = db.Column(db.String)
contents = db.Column(postgresql.ARRAY(db.String))

STATE_AVAILABLE = 'available'
STATE_REQUIRED = 'required'
Expand Down
34 changes: 13 additions & 21 deletions reciperadar/models/recipes/recipe.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
from sqlalchemy import (
Column,
DateTime,
Float,
Integer,
String,
)
from sqlalchemy.orm import relationship

from reciperadar import db
from reciperadar.models.base import Searchable, Storable
from reciperadar.models.recipes.direction import RecipeDirection
from reciperadar.models.recipes.ingredient import RecipeIngredient
Expand All @@ -15,27 +7,27 @@
class Recipe(Storable, Searchable):
__tablename__ = 'recipes'

id = Column(String, primary_key=True)
title = Column(String)
src = Column(String)
dst = Column(String)
domain = Column(String)
image_src = Column(String)
time = Column(Integer)
servings = Column(Integer)
rating = Column(Float)
ingredients = relationship(
id = db.Column(db.String, primary_key=True)
title = db.Column(db.String)
src = db.Column(db.String)
dst = db.Column(db.String)
domain = db.Column(db.String)
image_src = db.Column(db.String)
time = db.Column(db.Integer)
servings = db.Column(db.Integer)
rating = db.Column(db.Float)
ingredients = db.relationship(
'RecipeIngredient',
backref='recipe',
passive_deletes='all'
)
directions = relationship(
directions = db.relationship(
'RecipeDirection',
backref='recipe',
passive_deletes='all'
)

indexed_at = Column(DateTime)
indexed_at = db.Column(db.DateTime)

@property
def noun(self):
Expand Down
15 changes: 5 additions & 10 deletions reciperadar/models/recipes/utensil.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
from sqlalchemy import (
Column,
ForeignKey,
String,
)

from reciperadar import db
from reciperadar.models.base import Storable


class DirectionUtensil(Storable):
__tablename__ = 'direction_utensils'

fk = ForeignKey('recipe_directions.id', ondelete='cascade')
direction_id = Column(String, fk, index=True)
fk = db.ForeignKey('recipe_directions.id', ondelete='cascade')
direction_id = db.Column(db.String, fk, index=True)

id = Column(String, primary_key=True)
utensil = Column(String)
id = db.Column(db.String, primary_key=True)
utensil = db.Column(db.String)

@staticmethod
def from_doc(doc):
Expand Down
15 changes: 5 additions & 10 deletions reciperadar/models/recipes/vessel.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
from sqlalchemy import (
Column,
ForeignKey,
String,
)

from reciperadar import db
from reciperadar.models.base import Storable


class DirectionVessel(Storable):
__tablename__ = 'direction_vessels'

fk = ForeignKey('recipe_directions.id', ondelete='cascade')
direction_id = Column(String, fk, index=True)
fk = db.ForeignKey('recipe_directions.id', ondelete='cascade')
direction_id = db.Column(db.String, fk, index=True)

id = Column(String, primary_key=True)
vessel = Column(String)
id = db.Column(db.String, primary_key=True)
vessel = db.Column(db.String)

@staticmethod
def from_doc(doc):
Expand Down

0 comments on commit 58247a4

Please sign in to comment.