Ejemplo n.º 1
0
 def get_today_orders(cls, restaurant=None):
     """ get today orders
     """
     today_timestamp = get_today_start_timestamp()
     if not restaurant:
         orders = Order.objects.filter(add_timestamp__gt=today_timestamp)
     else:
         orders = Order.objects.filter(add_timestamp__gt=today_timestamp, restaurant=restaurant)
     return orders
Ejemplo n.º 2
0
def set_today_id(sender, instance, created, raw, using, **kwargs):
    """ if today id is zero, to set it
    """
    order = instance
    if order.today_id <= 0 and created is True:
        today_timestamp = get_today_start_timestamp()
        order_ahead_number = Order.objects.filter(
            add_timestamp__gte=today_timestamp, add_timestamp__lte=order.add_timestamp, restaurant=order.restaurant
        ).count()
        order.today_id = order_ahead_number
        order.save()
Ejemplo n.º 3
0
        return {"ok": False, "reason": u"订餐不存在了"}
    _notify_order(order)
    return {"ok": True, "notify_number": order.notify_number}

@render_json
def notify_restaurant(request, restaurant_id = 0):
    """ notify all orders of restaurant
    """
    if request.user.is_superuser is False:
        return {"ok": False, "reason": u"只有管理员有权限通知"}
    try:
       restaurant = Restaurant.objects.get(id = restaurant_id)
    except Exception, e:
        logging.debug("some exception: %s" % e)
        return {"ok": False, "reason": u"餐厅不存在"}
    today_timestamp = get_today_start_timestamp()
    orders = Order.objects.filter(restaurant = restaurant, add_timestamp__gt = today_timestamp)
    if not orders:
        return {"ok": False, "reason": u"订餐不存在了"}
    for order in orders:
        _notify_order(order)
    return {"ok": True}


@render_csv
def export_today_orders(request):
    """ export orders of today
    """
    today = datetime.datetime(1, 1, 1).today().strftime("%Y%m%d")
    orders = Order.get_today_orders()
    retv = []