Example #1
0
def from_dish(dish: Dish, language: str) -> str:
    dish_content = ""
    if language == 'uz':
        if dish.description_uz:
            dish_content += dish.get_full_name_uz()
            dish_content += '\n\n'
            dish_content += dish.description_uz
            dish_content += '\n\n'
    else:
        if dish.description:
            dish_content += dish.get_full_name()
            dish_content += '\n\n'
            dish_content += dish.description
            dish_content += '\n\n'
    price = dish.price * settings.get_currency_value()
    price_currency = 'sum'
    if dish.show_usd:
        price = dish.price
        price_currency = 'usd'
    if dish.is_sale:
        sale_price = dish.sale_price * settings.get_currency_value()
        if dish.show_usd:
            sale_price = dish.sale_price
        dish_content += "{}: <s>{}</s> {} {}".format(get_string('dish.price', language),
                                       _format_number(price), _format_number(sale_price), get_string(price_currency, language))
    else:
        dish_content += "{}: {} {}".format(get_string('dish.price', language),
                                       _format_number(price), get_string(price_currency, language))
    return dish_content
Example #2
0
def create_dish(name,
                description,
                image,
                price,
                quantity,
                category_id,
                show_usd=False):
    check_quantity = ''
    if quantity != check_quantity:
        check_quantity = quantity
    elif quantity == check_quantity:
        check_quantity = 0

    dish = Dish(name=str.strip(name),
                description=str.strip(description),
                price=price,
                quantity=check_quantity,
                category_id=category_id,
                show_usd=show_usd)
    if type(image) is str and image != '':
        file_path = os.path.join(Config.UPLOAD_DIRECTORY, image)
        dish.image_path = file_path
    elif image and image.filename != '':
        file_path = os.path.join(Config.UPLOAD_DIRECTORY, image.filename)
        files.save_file(image, file_path, recreate=True)
        dish.image_path = file_path
    db.session.add(dish)
    db.session.commit()
    return dish
Example #3
0
def create_dish(name_ru,
                name_uz,
                description_ru,
                description_uz,
                image,
                price,
                category_id,
                show_usd=False):
    dish = Dish(name=name_ru,
                name_uz=name_uz,
                description=description_ru,
                description_uz=description_uz,
                price=price,
                category_id=category_id,
                show_usd=show_usd)
    if type(image) is str:
        file_path = os.path.join(Config.UPLOAD_DIRECTORY, image)
        dish.image_path = file_path
    elif image and image.filename != '':
        file_path = os.path.join(Config.UPLOAD_DIRECTORY, image.filename)
        files.save_file(image, file_path, recreate=True)
        dish.image_path = file_path
    db.session.add(dish)
    db.session.commit()
    return dish
Example #4
0
def from_dish_full_name(dish: Dish, language):
    if language == 'uz':
        return dish.get_full_name_uz()
    else:
        return dish.get_full_name()
Example #5
0
def set_dish_image_id(dish: Dish, image_id: str):
    dish.image_id = image_id
    db.session.commit()