@permission_required("core.manage_shop")
def manage_categories(request, product_id, template_name="manage/product/categories.html"):
    """Displays the manage category view.
    """
    product = lfs_get_object_or_404(Product, pk=product_id)
    product_category_ids = [p.id for p in product.get_categories()]

    categories = []
    for category in Category.objects.filter(parent=None):

        children = children_categories(request, category, product_category_ids)

        categories.append({
            "id": category.id,
            "slug": category.slug,
            "name": category.name,
            "url": category.get_absolute_url(),
            "checked": category.id in product_category_ids,
            "children": children,
        })

    result = render_to_string(template_name, RequestContext(request, {
        "product": product,
        "categories": categories
    }))

    return HttpResponse(result)
dataset/ETHPy150Open diefenbach/django-lfs/lfs/manage/product/categories.py/manage_categories/original