当前位置: 首页>>代码示例>>Python>>正文


Python Order.make方法代码示例

本文整理汇总了Python中orders.models.Order.make方法的典型用法代码示例。如果您正苦于以下问题:Python Order.make方法的具体用法?Python Order.make怎么用?Python Order.make使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在orders.models.Order的用法示例。


在下文中一共展示了Order.make方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_order_make

# 需要导入模块: from orders.models import Order [as 别名]
# 或者: from orders.models.Order import make [as 别名]
 def test_order_make(self):
     order_test = Order(client_phone=8432424,
                        type=Order.TYPE_DINNER_WAGON,
                        state=Order.STATE_DONE,
                        order_date=date(2014, 12, 12),
                        execute_date=datetime(2014, 12, 12).date())
     order_test.make()
     self.assertEqual(order_test.state.__str__(), '4', 'State of order is not equal')
     self.assertEqual(order_test.type, Order.TYPE_DINNER_WAGON)
开发者ID:KirillAKostin,项目名称:TRPOProject,代码行数:11,代码来源:tests.py

示例2: get_order_form

# 需要导入模块: from orders.models import Order [as 别名]
# 或者: from orders.models.Order import make [as 别名]
def get_order_form(request, establishment_id, order_type):
    """Возвращает на страницу соответствующую форму, тип зависит от order_type:
    0 - заказ столика
    1 - заказ самовывоза
    2 - заказ доставки"""
    # проверям, нужно ли вообще пользователю показывать форму (вдруг он ничего не заказал?)
    # проверяем, есть ли в сессии ключи, соответствующие блюдам выбранного заведения
    establishment_dishes = Dish.objects.filter(establishmentdish__establishment__id=establishment_id)
    is_valid_request = False
    for key in request.session.keys():
        if key != 'cart_price':
            if establishment_dishes.filter(id=key).first() is not None:
                is_valid_request = True
                break

    if is_valid_request:
        order_types = Order.ORDER_TYPE
        if order_type == '1':
            if request.method == 'POST':
                form = PickUpForm(establishment_id, request.POST)
                if form.is_valid():
                    order_client_phone = form.cleaned_data['phone']
                    order_order_type = order_type
                    order_execute_date = form.cleaned_data['date']
                    order_execute_time = form.cleaned_data['time']
                    order_contact_account = Employee.objects.filter(
                        establishment__id=establishment_id
                    ).first()
                    order_branch_id = int(request.POST.get('address'))
                    order_establishment_branch = EstablishmentBranch.objects.filter(
                        id=order_branch_id
                    ).first()
                    new_order = Order(
                        client_phone=order_client_phone,
                        type=order_order_type,
                        execute_date=order_execute_date,
                        execute_time=order_execute_time,
                        contact_account=order_contact_account,
                        establishment_branch=order_establishment_branch
                    )
                    new_order.save()
                    for key in request.session.keys():
                        if key != 'cart_price':
                            row = OrdersCartRow(
                                establishment_dish=EstablishmentDish.objects.get(dish__id=key),
                                dishes_count=request.session[key],
                                order=new_order,
                            )
                            row.save()
                    new_order.make(type='pickup')
                    new_order.save(update_fields=['type', 'state'])

                    # удаление из сессии оформленных в заказе блюд и корзины, при необходимости
                    keys_for_delete = []
                    for key in request.session.keys():
                        if key != 'cart_price':
                            if establishment_dishes.get(id=key) is not None:
                                keys_for_delete.append(key)
                    for key in keys_for_delete:
                        del request.session[key]
                    is_cart_empty = True
                    for key in request.session.keys():
                        if key != 'cart_price':
                            is_cart_empty = False
                    if is_cart_empty:
                        del request.session['cart_price']

                    establishment = Establishment.objects.get(id=establishment_id)
                    return render(
                        request,
                        'orders/order_created.html',
                        {
                            'order_type': order_type,
                            'establishment_id': establishment_id,
                            'establishment_name': establishment.name,
                            'establishment_email': establishment.email,
                            'establishment_branch_order_phone': order_establishment_branch.order_phone_number,
                            'establishment_branch_help_phone': order_establishment_branch.help_phone_number
                        }
                    )
                else:
                    if request.POST.get('address_changed') == '1':
                        show_errors = 0
                    else:
                        show_errors = 1
            else:
                form = PickUpForm(establishment_id)
                show_errors = 0
            return render(
                request,
                'orders/make_order_form.html',
                {
                    # show_form определяет, нужно ли показывать форму пользователю
                    'show_form': 1,
                    'show_errors': show_errors,
                    'establishment_id': establishment_id,
                    'form': form,
                    'order_types_list': order_types,
                    'current_order_type': order_type
                }
#.........这里部分代码省略.........
开发者ID:KirillAKostin,项目名称:TRPOProject,代码行数:103,代码来源:views.py


注:本文中的orders.models.Order.make方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。