@permission_required("core.manage_shop")
def selected_products(request, manufacturer_id, as_string=False, template_name="manage/manufacturers/selected_products.html"):
    """The selected products part of the products-tab of a manufacturer.

    This is called at start from the products_inline method to assemble the
    whole manage category view and is later called via ajax requests to update
    this part independent of others.
    """
    req = request.POST if request.method == 'POST' else request.GET
    manufacturer = Manufacturer.objects.get(pk=manufacturer_id)

    if req.get("keep-session"):
        page_2 = req.get("manufacturer_page_2", request.session.get("manufacturer_page_2", 2))
        filter_2 = req.get("manufacturer_filter_2", request.session.get("manufacturer_filter_2", ""))
    else:
        page_2 = 1
        filter_2 = ""

    request.session["manufacturer_page_2"] = page_2
    request.session["manufacturer_filter_2"] = filter_2

    try:
        request.session["manufacturer-products-amount"] = int(req.get("manufacturer-products-amount", request.session.get("manufacturer-products-amount")))
    except __HOLE__:
        request.session["manufacturer-products-amount"] = 25

    filters = Q(manufacturer=manufacturer)
    if filter_2:
        filters &= (Q(name__icontains=filter_2) | Q(sku__icontains=filter_2))

    products = Product.objects.filter(filters).exclude(sub_type=VARIANT).distinct()

    paginator_2 = Paginator(products, request.session["manufacturer-products-amount"])
    try:
        page_2 = paginator_2.page(page_2)
    except (EmptyPage, InvalidPage):
        page_2 = paginator_2.page(1)

    result = render_to_string(template_name, RequestContext(request, {
        "manufacturer": manufacturer,
        "products": products,
        "paginator_2": paginator_2,
        "page_2": page_2,
        "filter_2": filter_2,
    }))

    if as_string:
        return result
    else:
        return HttpResponse(json.dumps({
            "html": [["#selected-products", result]],
        }), content_type='application/json')
dataset/ETHPy150Open diefenbach/django-lfs/lfs/manage/manufacturers/products.py/selected_products