@register.tag
def categories_for_slugs(parser, token):
    """
    Usage: {% categories_for_slugs "slug[,slug...]" as varname %}

    Sets the variable *varname* in the context to a list of categories, given by
    the list of slugs.

    Useful if you want to specify a custom list of categories and override the
    default category listing from satchmo. 
    
    Example usage::

        {% categories_for_slug "hats,boots,accessories" as categories %}
        <ul>
            {% for child in categories.child.active %}
            <li><a href="{{ child.get_absolute_url }}">{{ child.translated_name }}</a></li>
            {% endfor %}
        </ul>
        
    """
    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)

    if not m:
        raise TemplateSyntaxError, "%r tag had invalid arguments" \
              % tag_name

    cat_slugs, var = m.groups()
    cats=[]

    for cat_slug in cat_slugs.split(','):
        try:
            cat = Category.objects.get(slug__iexact=cat_slug)
        except Category.DoesNotExist:
            log.warn("No category found for slug: %s", cat_slug)
            cat = None
        cats.append(cat)

    return SetVariableInContextNode(var, cats)
dataset/ETHPy150Open dokterbob/satchmo/satchmo/apps/satchmo_store/shop/templatetags/satchmo_category.py/categories_for_slugs