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

    This is called at start from the manage_products view to assemble the
    whole manage manufacturer view and is subsequently 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 = req.get("manufacturer_page", request.session.get("manufacturer_page", 1))
        filter_ = req.get("manufacturer_filter", request.session.get("manufacturer_filter", ""))
        category_filter = req.get("manufacturer_category_filter", request.session.get("manufacturer_category_filter", ""))
    else:
        page = 1
        filter_ = ""
        category_filter = ""

    s = request.session
    s["manufacturer_page"] = page
    s["manufacturer_filter"] = filter_
    s["manufacturer_category_filter"] = category_filter

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

    filters = Q()
    if filter_:
        filters &= (Q(name__icontains=filter_) | Q(sku__icontains=filter_))
    if category_filter:
        if category_filter == "None":
            filters &= Q(categories=None)
        elif category_filter == "All":
            pass
        else:
            category_temp = lfs_get_object_or_404(Category, pk=category_filter)
            categories_temp = [category_temp]
            categories_temp.extend(category_temp.get_all_children())

            filters &= Q(categories__in=categories_temp)


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

    paginator = Paginator(selectable_products, s["manufacturer-products-amount"])
    try:
        page = paginator.page(page)
    except (EmptyPage, InvalidPage):
        page = paginator.page(1)

    result = render_to_string(template_name, RequestContext(request, {
        "manufacturer": manufacturer,
        "paginator": paginator,
        "page": page,
        "selected_products": selected_products(request, manufacturer_id, as_string=True),
    }))

    if as_string:
        return result
    else:
        return HttpResponse(json.dumps({
            "html": [["#products-inline", result]],
        }), content_type='application/json')


# Actions
dataset/ETHPy150Open diefenbach/django-lfs/lfs/manage/manufacturers/products.py/products_inline