Exemplo n.º 1
0
def update_topseller(request):
    """Saves or removes passed topsellers passed id (within request body).
    """
    if request.POST.get("action") == "remove":
        for temp_id in request.POST.keys():

            if temp_id.startswith("product") == False:
                continue

            temp_id = temp_id.split("-")[1]
            try:
                topseller = Topseller.objects.get(pk=temp_id)
                topseller.delete()
            except (Topseller.DoesNotExist, ValueError):
                pass

            _update_positions()
            topseller_changed.send(topseller)

        html = [[
            "#topseller-inline",
            manage_topseller_inline(request, as_string=True)
        ]]
        result = simplejson.dumps(
            {
                "html": html,
                "message": _(u"Topseller have been removed.")
            },
            cls=LazyEncoder)

    else:
        for temp_id in request.POST.keys():

            if temp_id.startswith("position") == False:
                continue

            temp_id = temp_id.split("-")[1]
            topseller = Topseller.objects.get(pk=temp_id)

            # Update position
            position = request.POST.get("position-%s" % temp_id)
            topseller.position = position
            topseller.save()

        _update_positions()
        html = [[
            "#topseller-inline",
            manage_topseller_inline(request, as_string=True)
        ]]
        result = simplejson.dumps(
            {
                "html": html,
                "message": _(u"Topseller have been updated.")
            },
            cls=LazyEncoder)

    return HttpResponse(result)
Exemplo n.º 2
0
def update_topseller(request):
    """Saves or removes passed topsellers passed id (within request body).
    """
    if request.POST.get("action") == "remove":
        for temp_id in request.POST.keys():

            if temp_id.startswith("product") == False:
                continue

            temp_id = temp_id.split("-")[1]
            try:
                topseller = Topseller.objects.get(pk=temp_id)
                topseller.delete()
            except (Topseller.DoesNotExist, ValueError):
                pass

            _update_positions()
            topseller_changed.send(topseller)

        html = [["#topseller-inline", manage_topseller_inline(request, as_string=True)]]
        result = simplejson.dumps({
            "html": html,
            "message": _(u"Topseller have been removed.")
        }, cls=LazyEncoder)

    else:
        for temp_id in request.POST.keys():

            if temp_id.startswith("position") == False:
                continue

            temp_id = temp_id.split("-")[1]
            topseller = Topseller.objects.get(pk=temp_id)

            # Update position
            position = request.POST.get("position-%s" % temp_id)
            topseller.position = position
            topseller.save()

        _update_positions()
        html = [["#topseller-inline", manage_topseller_inline(request, as_string=True)]]
        result = simplejson.dumps({
            "html": html,
            "message": _(u"Topseller have been updated.")
        }, cls=LazyEncoder)

    return HttpResponse(result, mimetype='application/json')