Helper function detects a certain clause in tag tokens list.
    Returns its value.

def detect_clause(parser, clause_name, tokens, as_filter_expr=True):
    """Helper function detects a certain clause in tag tokens list.
    Returns its value.

    """
    if clause_name in tokens:
        t_index = tokens.index(clause_name)
        clause_value = tokens[t_index + 1]
        if as_filter_expr:
            clause_value = parser.compile_filter(clause_value)
        del tokens[t_index:t_index + 2]
    else:
        clause_value = None
    return clause_value