Ejemplo n.º 1
0
def detail(request, order_id):
    success, code, msg = test_connection()
    if not success:
        messages.error(
            request,
            "Unable to connect (HTTP {code}) to API at <code>{url}</code>{msg}"
            .format(
                url=settings.CARDSHOP_API_URL,
                code=code,
                msg=" -- " + msg if msg else "",
            ),
        )
        return redirect("admin")

    retrieved, order = get_order(order_id)
    context = {"orderdata": OrderData(order)}

    if success:
        messages.set_level(request, messages.DEBUG)
        messages.debug(
            request,
            "Connected to Scheduler API at <code>{url}</code>".format(
                url=settings.CARDSHOP_API_URL),
        )
    return render(request, "all_orders-detail.html", context)
Ejemplo n.º 2
0
def detail(request, order_id):
    success, code, msg = test_connection()
    if not success:
        messages.error(
            request,
            _("Unable to connect (HTTP %(code)s) to API at <code>%(url)s</code>%(msg)s")
            % {
                "url": settings.CARDSHOP_API_URL,
                "code": code,
                "msg": " -- " + msg if msg else "",
            },
        )
        return redirect("admin")

    retrieved, order = get_order(order_id)
    context = {"orderdata": OrderData(order)}

    if success:
        messages.set_level(request, messages.DEBUG)
        messages.debug(
            request,
            _("Connected to Scheduler API at <code>%(url)s</code>")
            % {"url": settings.CARDSHOP_API_URL},
        )
    return render(request, "all_orders-detail.html", context)
Ejemplo n.º 3
0
 def fetch_and_get(cls, order_id):
     order = cls.objects.get(id=order_id)
     # fetch current version of scheduler data
     retrieved, scheduler_data = get_order(order.scheduler_id)
     if retrieved:
         order.retrieved = True
         order.scheduler_data = scheduler_data
         order.scheduler_data_on = timezone.now()
         # update status fron scheduler data
         order.status = Order.status_from_statuses(scheduler_data.get("statuses"))
         order.save()
     else:
         order.retrieved = False
     return order
Ejemplo n.º 4
0
def order_log(request, order_id, step, kind, index=None, fmt="txt"):
    if fmt not in ("txt", "html"):
        raise Http404(_("Unhandled format `%(fmt)s`") % {"fmt": fmt})
    else:
        mime = {"txt": "text/plain", "html": "text/html"}.get(fmt)

    if step not in ("create", "download", "write") or kind not in (
        "worker",
        "installer",
        "uploader",
        "downloader",
        "wipe",
        "writer",
    ):
        raise Http404(_("`%(kind)s` log does not exists") % {"kind": kind})

    retrieved, order = get_order(order_id, with_logs=True)
    if not retrieved:
        raise Http404(order)

    try:
        if step == "write":
            index = int(index) - 1
            content = order["tasks"][step][index]["logs"][kind]
        else:
            content = order["tasks"][step]["logs"][kind]
    except Exception as exp:
        logger.exception(exp)
        raise Http404(
            _("Log %(step)s/%(kind)s.txt does not exists for Order #%(id)s")
            % {"step": step, "kind": kind, "id": order_id}
        )

    if content and fmt == "html":
        try:
            content = Ansi2HTMLConverter().convert(content)
        except Exception as exp:
            logger.error("Unable to convert content to HTML")
            logger.exception(exp)

    return HttpResponse(content, content_type=mime)