Ejemplo n.º 1
0
def unblock_recipe_(name):
    """
    Разблокирать рецепт
    :param name: название рецепта
    :return: ответ как прошла операция
    """
    try:
        recipe = Recipe.update({
            Recipe.active: True
        }).where(Recipe.name == name)
        success = recipe.execute()
        if success:
            response = {'status': name + ' recipe unblock'}
        else:
            response = {'error': 'probably wrong name'}
    except Exception as e:
        error_message = str(e).split('\n')[0]
        response = {'error': error_message}
    return response
Ejemplo n.º 2
0
def upd_recipe_(name_recipe, data, user):
    """
    изменить свой рецепт
    :param name_recipe: name of recipe to change
    :param user: Пользователь, уто пытается изменть рецепт
    :param data: put параметр 'name'
    :return: ответ как прошла операция
    """
    try:
        recipe = Recipe.get(name=name_recipe)
        if recipe.author.nickname == user.nickname:
            update = {}
            if 'name' in data and data['name']:
                update[Recipe.name] = data['name']
            if 'description' in data and data['description']:
                update[Recipe.description] = data['description']
            if 'hashtags' in data and data['hashtags']:
                update[Recipe.hashtags] = data['hashtags']
            if 'steps' in data and data['steps']:
                update[Recipe.steps] = data['steps']
            if 'dish_type' in data and data['dish_type']:
                update[Recipe.dish_type] = DishType.get(
                    dish_type_name=data['dish_type'])
            if 'image' in data and data['image']:
                update[Recipe.hashtag] = data['image']

            recipe = Recipe.update(update).where(Recipe.name == name_recipe)
            success = recipe.execute()
            if success:
                response = {'status': 'recipe changed'}
            else:
                response = {'error': 'recipe no changed'}
        else:
            response = {'error': 'u not owner of this recipe'}
    except Exception as e:
        error_message = str(e).split('\n')[0]
        response = {'error': error_message}
    return json.dumps(response, ensure_ascii=False)