@register.tag
def all_products_for_category(parser, token):
    """
    Usage:
     1. {% all_products_for_category as varname %}
     2. {% all_products_for_category for slug_var as varname %}
     3. {% all_products_for_category for "slug" as varname %}

    Sets the variable *varname* in the context to a list of all products that
    are active in *category*, and is equivalent to the result of:

      category.active_products(include_children=True)

    where *category* is:
     1. the 'category' variable in the context, for usage 1.
     2. the instance of Category with the slug in the context variable
        *slug_var*, for usage 2.
     3. the instance of Category with the slug *slug*, for usage 3.
    """
    try:
        # Splitting by None == splitting by spaces.
        tag_name, arg = token.contents.split(None, 1)
    except __HOLE__:
        raise TemplateSyntaxError, "%r tag requires arguments" \
              % token.contents.split()[0]

    m = re.search(r'(.*?)as (\w+)$', arg)

    # First, get the varname - the easiest
    if not m:
        raise TemplateSyntaxError, "Variable name was not specified for %r tag" \
              % tag_name

    arg, var  = m.groups()

    # Now, try and determine usage case the user wants
    if not arg:
        # We're of the first case.
        return AllProductsNode(var)

    m = re.search(r'^for (.+?)$', arg.strip())

    if not m:
        raise TemplateSyntaxError, "Invalid arguments for %r tag" \
              % tag_name

    arg = m.group(1)

    if arg[0] == '"' and arg[-1] == '"':
        # We're of the third case.
        cat_var = arg[1:-1]
        return AllProductsForSlugNode(arg[1:-1], var)
    elif arg:
        # We're of the second case.
        return AllProductsForVariableSlugNode(Variable(arg), var)

    raise TemplateSyntaxError, "Invalid arguments for %r tag" \
          % tag_name
dataset/ETHPy150Open dokterbob/satchmo/satchmo/apps/satchmo_store/shop/templatetags/satchmo_category.py/all_products_for_category