示例#1
0
文件: views.py 项目: dhruvAdhia/ella
def add_post(content, thread, user = False, nickname = False, email = '', ip='0.0.0.0', parent = None):
    """
    PARAMS
    content: post content
    thread: TopicThread instance
    ip: IP address
    """
    # invalidate cached thread posts
    delete_cached_object(get_key_comments_on_thread__by_submit_date(None, thread))
    delete_cached_object(get_key_comments_on_thread__spec_filter(None, thread))

    content = filter_banned_strings(content)
    comment_set = get_comments_on_thread(thread).order_by('-parent')
    CT_THREAD = ContentType.objects.get_for_model(TopicThread)

    if comment_set.count() > 0 and not parent:
        parent = comment_set[0]
    elif parent:
        parent = get_cached_object_or_404(Comment, pk = parent)

    if (user):
        cmt = Comment(
            content=content,
            subject='',
            ip_address=ip,
            target_ct=CT_THREAD,
            target_id=thread.id,
            parent=parent,
            user=user,
)

        cmt.save()

        # post is viewed by its autor
        make_objects_viewed(user, (cmt,))

    elif nickname:
        cmt = Comment(
            content=content,
            subject='',
            ip_address=ip,
            target_ct=CT_THREAD,
            target_id=thread.id,
            parent=parent,
            nickname=nickname,
            email=email,
)

        cmt.save()

    else:
        raise Exception("Either user or nickname param required!")
示例#2
0
def add_post(content, thread, user = False, nickname = False, email = '', ip='0.0.0.0', parent = None):
    """
    PARAMS
    content: post content
    thread: TopicThread instance
    ip: IP address
    """
    # invalidate cached thread posts
    delete_cached_object(get_key_comments_on_thread__by_submit_date(None, thread))
    delete_cached_object(get_key_comments_on_thread__spec_filter(None, thread))

    content = filter_banned_strings(content)
    comment_set = get_comments_on_thread(thread).order_by('-parent')
    CT_THREAD = ContentType.objects.get_for_model(TopicThread)

    if comment_set.count() > 0 and not parent:
        parent = comment_set[0]
    elif parent:
        parent = get_cached_object_or_404(Comment, pk = parent)

    if (user):
        cmt = Comment(
            content=content,
            subject='',
            ip_address=ip,
            target_ct=CT_THREAD,
            target_id=thread.id,
            parent=parent,
            user=user,
        )

        cmt.save()

        # post is viewed by its autor
        make_objects_viewed(user, (cmt,))

    elif nickname:
        cmt = Comment(
            content=content,
            subject='',
            ip_address=ip,
            target_ct=CT_THREAD,
            target_id=thread.id,
            parent=parent,
            nickname=nickname,
            email=email,
        )

        cmt.save()

    else:
        raise Exception("Either user or nickname param required!")
示例#3
0
def get_thread_pagination(context, thread):
    """
    Renders thread pagination (useful for threads printout) - direct links to specific
    pages within paginated thread.

    Syntax::
        {% get_thread_pagination_per_topic TOPIC %}

    Example usage::
        {% get_thread_pagination_per_topic object %}
    """
    if not isinstance(thread, TopicThread):
        raise TemplateSyntaxError(
            'get_thread_pagination_per_topic - parameter should be valid TopicThread object! Passed arg. type is %s' \
            % str(type(thread))
)
    qset = get_comments_on_thread(thread)
    p = Paginator(qset, DISCUSSIONS_PAGINATE_BY)
    return {
        'pages': p.pages,
        'has_more_pages': p.pages > 1,
        'page_range': p.page_range,
        'thread_url': thread.get_absolute_url(),
}
示例#4
0
文件: cache.py 项目: whit/ella
def comments_on_thread__spec_filter(thread):
    out = get_comments_on_thread(thread).filter(
        is_public__exact=True).order_by('submit_date')
    return list(out)
示例#5
0
文件: cache.py 项目: whit/ella
def comments_on_thread__by_submit_date(thread):
    out = get_comments_on_thread(thread).order_by('submit_date')
    return list(out)
示例#6
0
文件: cache.py 项目: Almad/ella
def comments_on_thread__spec_filter(thread):
    out = get_comments_on_thread(thread).filter(is_public__exact=True).order_by('submit_date')
    return list(out)
示例#7
0
文件: cache.py 项目: Almad/ella
def comments_on_thread__by_submit_date(thread):
    out = get_comments_on_thread(thread).order_by('submit_date')
    return list(out)