Exemple #1
0
def get_comment_list(parser, token):
    """
    Gets comments for the given params and populates the template context with
    a special comment_package variable, whose name is defined by the ``as`` clause.

    Syntax::

        {% get_comment_list for APP_LABEL.MODEL_NAME with FIELD VALUE as VARNAME [orderby path|submit_date|...] [limit n]%}
        {% get_comment_list for OBJECT as VARNAME [orderby path|submit_date|...] [limit n]%}

    Example usage::

        {% get_comment_list for testapp.apple with id 1 as comment_list orderby path %}
        {% get_comment_list for object as comment_list %}
        {% get_comment_list for object as comment_list limit 5%}

    To get a list of comments in reverse order -- that is, most recent first --
    pass ``minus`` as a prefix to the last param::

        {% get_comment_list for testapp.apple with id 1 as comment_list orderby -submit_date %}
    """
    tokens = token.split_contents()
    limit = None
    if tokens[-2] == u'limit':
        limit = tokens[-1]
        tokens = tokens[0:-2]
    if tokens[-2] == u'orderby':
        orderby = tokens[-1]
        tagname, object_definition_tokens, varname = parse_getforas_triplet(tokens[:-2])
    else:
        orderby = '-submit_date'
        tagname, object_definition_tokens, varname = parse_getforas_triplet(tokens)
    object = parse_object_definition(tagname, object_definition_tokens)

    return CommentListNode(object, orderby, varname, limit)
Exemple #2
0
def get_comment_form(parser, token):
    """
    Gets a comment form for the given params.

    Syntax::

        {% get_comment_form for APP_LABEL.MODEL_NAME with FIELD VALUE [with OPTIONS_STRING] as VARNAME %}
        {% get_comment_form for OBJECT [with OPTIONS_STRING] as VARNAME %}

    Example usage::

        {% get_comment_form for testapp.apple with id 1 with 'LO' as comment_form %}
        {% get_comment_form for object with 'LO' as comment_form %}
        {% get_comment_form for object as comment_form %}
    """
    tokens = token.split_contents()
    tagname, object_definition_tokens, varname = parse_getforas_triplet(tokens)
    if len(object_definition_tokens) > 1 and object_definition_tokens[-2] == u'with':
        form_options = object_definition_tokens[-1]
        object = parse_object_definition(tagname, object_definition_tokens[:-2])
    else:
        form_options = ''
        object = parse_object_definition(tagname, object_definition_tokens)

    return CommentFormNode(object, form_options, varname)
Exemple #3
0
def get_comment_form(parser, token):
    """
    Gets a comment form for the given params.

    Syntax::

        {% get_comment_form for APP_LABEL.MODEL_NAME with FIELD VALUE [with OPTIONS_STRING] as VARNAME %}
        {% get_comment_form for OBJECT [with OPTIONS_STRING] as VARNAME %}

    Example usage::

        {% get_comment_form for testapp.apple with id 1 with 'LO' as comment_form %}
        {% get_comment_form for object with 'LO' as comment_form %}
        {% get_comment_form for object as comment_form %}
    """
    tokens = token.split_contents()
    tagname, object_definition_tokens, varname = parse_getforas_triplet(tokens)
    if len(object_definition_tokens
           ) > 1 and object_definition_tokens[-2] == u'with':
        form_options = object_definition_tokens[-1]
        object = parse_object_definition(tagname,
                                         object_definition_tokens[:-2])
    else:
        form_options = ''
        object = parse_object_definition(tagname, object_definition_tokens)

    return CommentFormNode(object, form_options, varname)
Exemple #4
0
def do_tag_process(token, cls):
    """ common processing of discussions get_* template tags """
    tokens = token.split_contents()
    if len(tokens) >= 5:
        tagname, object_definition_tokens, varname = parse_getforas_triplet(tokens)
        return cls(object_definition_tokens, varname)
    elif len(tokens) == 3: # {% template_tag as variable %}
        varname = parse_getas_tuple(tokens)
        return cls(None, varname)
    return cls()
Exemple #5
0
def get_comment_list(parser, token):
    """
    Gets comments for the given params and populates the template context with
    a special comment_package variable, whose name is defined by the ``as`` clause.

    Syntax::

        {% get_comment_list for APP_LABEL.MODEL_NAME with FIELD VALUE as VARNAME [orderby path|submit_date|...] [limit n]%}
        {% get_comment_list for OBJECT as VARNAME [orderby path|submit_date|...] [limit n]%}

    Example usage::

        {% get_comment_list for testapp.apple with id 1 as comment_list orderby path %}
        {% get_comment_list for object as comment_list %}
        {% get_comment_list for object as comment_list limit 5%}

    To get a list of comments in reverse order -- that is, most recent first --
    pass ``minus`` as a prefix to the last param::

        {% get_comment_list for testapp.apple with id 1 as comment_list orderby -submit_date %}
    """
    tokens = token.split_contents()
    limit = None
    if tokens[-2] == u'limit':
        limit = tokens[-1]
        tokens = tokens[0:-2]
    if tokens[-2] == u'orderby':
        orderby = tokens[-1]
        tagname, object_definition_tokens, varname = parse_getforas_triplet(
            tokens[:-2])
    else:
        orderby = '-submit_date'
        tagname, object_definition_tokens, varname = parse_getforas_triplet(
            tokens)
    object = parse_object_definition(tagname, object_definition_tokens)

    return CommentListNode(object, orderby, varname, limit)
Exemple #6
0
def get_comment_count(parser, token):
    """
    Gets comment count for the given params and populates the template context
    with a variable containing that value, whose name is defined by the 'as' clause.

    Syntax::

        {% get_comment_count for APP_LABEL.MODEL_NAME with FIELD VALUE as VARNAME %}
        {% get_comment_count for OBJECT as VARNAME %}

    Example usage::

        {% get_comment_count for testapp.apple with id 1 as comment_count %}
        {% get_comment_count for object as comment_count %}
    """
    tokens = token.split_contents()
    tagname, object_definition_tokens, varname = parse_getforas_triplet(tokens)
    object = parse_object_definition(tagname, object_definition_tokens)

    return CommentCountNode(object, varname)
Exemple #7
0
def get_comment_count(parser, token):
    """
    Gets comment count for the given params and populates the template context
    with a variable containing that value, whose name is defined by the 'as' clause.

    Syntax::

        {% get_comment_count for APP_LABEL.MODEL_NAME with FIELD VALUE as VARNAME %}
        {% get_comment_count for OBJECT as VARNAME %}

    Example usage::

        {% get_comment_count for testapp.apple with id 1 as comment_count %}
        {% get_comment_count for object as comment_count %}
    """
    tokens = token.split_contents()
    tagname, object_definition_tokens, varname = parse_getforas_triplet(tokens)
    object = parse_object_definition(tagname, object_definition_tokens)

    return CommentCountNode(object, varname)