Example #1
0
def api_presentation_order(request, presentation_id, order_id):
    try:
        if request.method == "GET":
            presentation = Presentation.objects.get(pk=presentation_id)
            order = Order.objects.get(pk=order_id)

            presentation_order = PresentationOrder(presentation=presentation, order=order)
            presentation_order.save()

            return HttpResponse(json.dumps(order.convert_to_dict()), mimetype="application/json")

        if request.method == "POST":
            new_order_dict = order_duplicate(order_id, "PRE-BOOK")

            presentation = Presentation.objects.get(pk=presentation_id)
            order = Order.objects.get(pk=new_order_dict["order_id"])

            presentation_order = PresentationOrder(presentation=presentation, order=order)
            presentation_order.save()

            return HttpResponse(json.dumps(new_order_dict), mimetype="application/json")

        if request.method == "DELETE":
            presentation = Presentation.objects.get(pk=presentation_id)
            order = Order.objects.get(pk=order_id)
            presentation_order = PresentationOrder.objects.get(presentation=presentation, order=order)
            presentation_order.delete()

            return HttpResponse(json.dumps({"status": "deleted"}), mimetype="application/json")

    except Exception, e:
        logger.error("api_presentation_order: {}".format(e))
        return HttpResponseServerError(e)
Example #2
0
def api_presentation_orders_add(request, presentation_id):
    try:
        add_type = request.GET.get("type", "duplicate")
        id_list = request.GET.getlist("ids[]")

        return_object = {"success": True}
        presentation = Presentation.objects.get(pk=presentation_id)

        for id in id_list:
            if add_type == "add":
                order = Order.objects.get(pk=id)
            elif add_type == "duplicate":
                new_order_dict = order_duplicate(id, "PRE-BOOK")
                order = Order.objects.get(pk=new_order_dict["order_id"])
                order.pre_book_option = _create_new_prebook_date(order.pre_book_option)
                order.save()

            presentation_order = PresentationOrder(presentation=presentation, order=order)
            presentation_order.save()

        return HttpResponse(json.dumps(return_object), mimetype="application/json")

    except Exception, e:
        logger.error("api_presentation_orders_add: {}".format(e))
        return HttpResponseServerError(e)