Esempio n. 1
0
def add_tag():
    json_data = flask.request.json

    # text
    text = json_data.get('text')
    if not text:
        return flask.jsonify({'msg': 'Must provide non-empty text'}), 400

    tag = Tag(text=text)
    if not tag.save():
        return flask.jsonify({'msg': 'Error in saving data'}), 400
    return flask.jsonify({'msg': 'Success'}), 200
Esempio n. 2
0
def edit_tag(tagId: str):
    json_data = flask.request.json
    tag = Tag.get_by_id(tagId)

    # text
    text = json_data.get('text')
    if text:
        tag.text = text

    if not tag.save():
        return flask.jsonify({'msg': 'Error in saving data'}), 400
    return flask.jsonify({'msg': 'Success'}), 200
Esempio n. 3
0
 def tags(self):
     from models.model_tag import Tag
     from models.relation_recipe_tag import RecipeTagRelation
     return Tag.select().join(
         RecipeTagRelation,
         pw.JOIN.LEFT_OUTER).where(RecipeTagRelation.recipe == self)
Esempio n. 4
0
        "_", "") + ("%02d" % random.randint(0, 99))
    users.append(
        User(userId=userId,
             name=user['name'].strip(),
             email=user['email'].strip(),
             pw_hash=generate_password_hash(password),
             imgName="user-%s.png" % userId))

User.bulk_create(users)

# Step 3: Tags
tags_df = pd.read_csv("data/tags.csv", sep=';')
tags = []
tag_names = []
for tag_id, tag in tags_df.iterrows():
    tags.append(Tag(text=tag['text'].strip()))
    tag_names.append(tag['text'].strip().lower().replace(' ', ''))
Tag.bulk_create(tags)

# Step 4: Ingredients
ingredients_df = pd.read_csv("data/ingredients.csv", sep=';')
ingredients = []
ingredient_names = []
for ingredient_id, ingredient in ingredients_df.iterrows():
    ingredients.append(Ingredient(name=ingredient['name'].strip()))
    ingredient_names.append(ingredient['name'].strip().lower().replace(
        ' ', ''))

Ingredient.bulk_create(ingredients)

# Step 5: Recipes
Esempio n. 5
0
def delete_tag(tagId: str):
    tag = Tag.get_by_id(tagId)
    if not tag.delete_instance():
        return flask.jsonify({'msg': 'Error in deleting data'}), 400
    return flask.jsonify({'msg': 'Success'}), 200
Esempio n. 6
0
def get_tag(tagId: str):
    tag = Tag.get_by_id(tagId)
    return flask.jsonify({'msg': 'Success', 'data': tag.as_dict()}), 200
Esempio n. 7
0
def get_tags():
    query = Tag.select()

    tags = [c for c in query]
    tag_dicts = [c.as_dict() for c in tags]
    return flask.jsonify({'msg': 'Success', 'data': tag_dicts}), 200
Esempio n. 8
0
 def wrapper(tagId, *args, **kwargs):
     tag = Tag.get_or_none(Tag.id == tagId)
     if tag:
         return func(tagId, *args, **kwargs)
     else:
         return flask.jsonify({'msg': 'Tag does not exists'}), 400