Beispiel #1
0
def list(request):

    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")

    items = OrdersQuerySet("/orders/")
    page = request.GET.get("page")
    paginator = Paginator(items, 10)
    orders_page = paginator.get_page(page)

    context = {
        "orders_page": orders_page,
        "orders": orders_page.object_list,
    }

    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.html", context)
Beispiel #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)
Beispiel #3
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)
Beispiel #4
0
def list(request):

    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")

    items = OrdersQuerySet("/orders/")
    page = request.GET.get("page")
    paginator = Paginator(items, 10)
    orders_page = paginator.get_page(page)

    context = {
        "orders_page": orders_page,
        "orders": orders_page.object_list,
    }

    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.html", context)
Beispiel #5
0
def list(request):

    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")

    orders = sorted(
        [OrderData(order) for order in as_items_or_none(*get_orders_list())],
        key=lambda item: item["statuses"][0]["on"],
        reverse=True,
    )
    context = {"orders": orders or None}

    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.html", context)
Beispiel #6
0
def dashboard(request):

    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")

    context = {
        "channels": as_items_or_none(*get_channels_list()) or None,
        "warehouses": as_items_or_none(*get_warehouses_list()) or None,
        "users": as_items_or_none(*get_users_list()) or None,
        "workers": as_items_or_none(*get_workers_list()) or None,
        "images": as_items_or_none(*get_autoimages_list()) or None,
        "api_url": settings.CARDSHOP_API_URL_EXTERNAL,
    }

    forms_map = {
        "channel_form": ChannelForm,
        "user_form": UserForm,
        "warehouse_form": WarehouseForm,
        "image_form": ImageForm,
    }
    for key, value in forms_map.items():
        context[key] = value(prefix=key, client=request.user.profile)

    if request.method == "POST" and request.POST.get("form") in forms_map.keys():

        # which form is being saved?
        form_key = request.POST.get("form")
        context[form_key] = forms_map.get(form_key)(
            request.POST, prefix=form_key, client=request.user.profile
        )

        if context[form_key].is_valid():
            try:
                res = context[form_key].save()
            except Exception as exp:
                logger.error(exp)
                messages.error(request, _("Error while saving… %(err)s") % {"err": exp})
            else:
                messages.success(request, context[form_key].success_message(res))
                return redirect("scheduler")

    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, "scheduler.html", context)
Beispiel #7
0
def dashboard(request):

    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")

    context = {
        "channels": as_items_or_none(*get_channels_list()) or None,
        "warehouses": as_items_or_none(*get_warehouses_list()) or None,
        "users": as_items_or_none(*get_users_list()) or None,
        "workers": as_items_or_none(*get_workers_list()) or None,
    }

    forms_map = {
        "channel_form": ChannelForm,
        "user_form": UserForm,
        "warehouse_form": WarehouseForm,
    }
    for key, value in forms_map.items():
        context[key] = value(prefix=key)

    if request.method == "POST" and request.POST.get("form") in forms_map.keys():

        # which form is being saved?
        form_key = request.POST.get("form")
        context[form_key] = forms_map.get(form_key)(request.POST, prefix=form_key)

        if context[form_key].is_valid():
            try:
                res = context[form_key].save()
            except Exception as exp:
                logger.error(exp)
                messages.error(request, "Error while saving… {exp}".format(exp=exp))
            else:
                messages.success(request, context[form_key].success_message(res))
                return redirect("scheduler")

    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, "scheduler.html", context)