Exemple #1
0
def news_item(request, news_item_id=None):
    """
    View for a news item.

    Only responds to GET requests.
    """
    top_news_item = get_object_or_404(NewsItem, pk=news_item_id)
    child_comments = get_child_comments(top_news_item.child_set, 0)

    header = 'News Item'

    # these are only set if there is an error or something
    comment_posting_error = get_from_session(request, 'comment_posting_error')
    comment_text = get_from_session(request, 'comment_text')
    comment_text_for_id = get_from_session(request, 'comment_text_for_id')

    # comment_text_for_id needs to be a string
    if str(comment_text_for_id) != news_item_id:
        comment_text = ''
        comment_posting_error = ''

    next = reverse('news.views.news_items.news_item', 
                   args=(top_news_item.id,))

    top_news_item.update_ranking()

    return render_to_response('news/news_item.html',
            {'top_news_item': top_news_item,
             'child_comments': child_comments,
             'header': header,
             'comment_posting_error':comment_posting_error,
             'comment_text': comment_text,
             'next': next},
            context_instance=RequestContext(request))
Exemple #2
0
 def has_children(self):
     """
     This returns wheter or not a news item (or comment) has children.
     """
     if hasattr(self, 'child_set'):
         from news.helpers import get_child_comments
         return len(get_child_comments(self.child_set)) > 0
     else:
         return False
Exemple #3
0
 def num_child_comments(self):
     """
     This returns the number of comments a news item (or a comment) has
     """
     if hasattr(self, 'child_set'):
         from news.helpers import get_child_comments
         return len(get_child_comments(self.child_set, return_dead=False))
     else:
         return 0
Exemple #4
0
 def has_nondead_children(self):
     """
     This returns wheter or not a news item (or comment) has children and
     at least one of them is not dead.
     """
     if hasattr(self, 'child_set'):
         from news.helpers import get_child_comments
         return len(get_child_comments(self.child_set, return_dead=False)) > 0
     else:
         return False
Exemple #5
0
def comment(request, comment_id):
    """
    View for a comment.

    Only responds to GETS.
    """
    top_comment = get_object_or_404(Comment, pk=comment_id)
    child_comments = get_child_comments(top_comment.child_set, 0)

    header = 'Comment'


    # these are set if there is an error or something when trying to post
    # the comment
    comment_posting_error = get_from_session(request, 'comment_posting_error')
    comment_text = get_from_session(request, 'comment_text')
    comment_text_for_id = get_from_session(request, 'comment_text_for_id')

    # comment_text_for_id needs to be a string
    if str(comment_text_for_id) != comment_id:
        comment_posting_error = ''
        comment_text = ''

    next = reverse('news.views.comments.comment', 
                   args=(top_comment.id,))

    top_comment.update_ranking()

    return render_to_response('news/comment.html',
            {'top_comment': top_comment,
             'child_comments': child_comments,
             'header': header,
             'comment_posting_error': comment_posting_error,
             'comment_text': comment_text,
             'next': next},
            context_instance=RequestContext(request))
Exemple #6
0
 def testGetChildComments(self):
     """ Test get_child_comments(). """
     newsitem = NewsItem.objects.get(id=1)
     child_comments = get_child_comments(newsitem.child_set)
     for com_data in child_comments:
         self.assert_(com_data['comment'] in Comment.objects.all())