Beispiel #1
0
def get_comment_list(comments=None, rankby="hot"):
    """Recursively build a list of comments."""
    yield 'in'

    # Loop through all the comments I've passed
    for comment in comments:
        # Add comment to the list
        yield comment
        # get comment's children
        children = comment.children.all()
        if rankby == "hot":
            ranked_children = rank_hot(children, top=32)
        elif rankby == "top":
            ranked_children = rank_top(children, timespan = "all-time")
        elif rankby == "new":
            ranked_children = children.order_by('-pub_date')
        else:
            ranked_children = []
        
        # If there's any children
        if len(ranked_children):
            comment.leaf=False
            # loop through children, and apply this function
            for x in get_comment_list(ranked_children, rankby=rankby):
                yield x
        else:
            comment.leaf=True
    yield 'out'
Beispiel #2
0
def get_comment_list(comments=None, rankby="hot"):
    """Recursively build a list of comments."""
    yield 'in'

    # Loop through all the comments I've passed
    for comment in comments:
        # Add comment to the list
        yield comment
        # get comment's children
        children = comment.children.all()
        ranked_children = children.order_by('-pub_date')
        if rankby == "hot":
            ranked_children = rank_hot(children, top=32)
        elif rankby == "top":
            ranked_children = rank_top(children, timespan="all-time")
        elif rankby == "new":
            ranked_children = children.order_by('-pub_date')
        else:
            ranked_children = []

        # If there's any children
        if len(ranked_children):
            comment.leaf = False
            # loop through children, and apply this function
            for x in get_comment_list(ranked_children, rankby=rankby):
                yield x
        else:
            comment.leaf = True
    yield 'out'
Beispiel #3
0
def home(request):
    rational = False
    if request.META['HTTP_HOST'] == "rationalfiction.io" or \
       request.META['HTTP_HOST'] == "localhost:8000":
        rational = True

    # fictionhub includes rational        
    if rational:
        posts = Post.objects.filter(published=True, rational=rational, post_type="story")
    else:
        posts = Post.objects.filter(published=True, post_type="story")

    # Approved only
    posts = posts.filter(author__approved=True)
        
    # fictionhub doesn't include rational
    # posts = Post.objects.filter(published=True, rational=rational, post_type="story")    
    timespan="all-time"
    hot_posts = rank_hot(posts, top=32)[:10]
    top_posts = rank_top(posts, timespan = timespan)[:10]
    new_posts = posts.order_by('-pub_date')[:10]
    # hubs = Hub.objects.all().annotate(number_of_posts=Count('posts')).order_by('-number_of_posts')
    hubs = Hub.objects.all()


    # Add attribute:
    # for hub in hubs:
    #     stories = hub.posts.filter(published = True, rational = rational)
    #     hub.storycount = stories.count()
    # hubs_storycount = []
    # for hub in hubs:
    #     stories = hub.posts.filter(published = True, rational = rational)
    #     hub.storycount = stories.count()
    #     hubs_storycount.append(hub)

    # hubs = 
    # hubs = hubs_storycount.order_by('storycount')
    
 
    return render(request, 'home.html', {
        'hot_posts': top_posts, # hot_posts,
        'new_posts':new_posts,
        'hubs':hubs
    })
Beispiel #4
0
def home(request):
    rational = False

    if not request.user.is_authenticated():
        return render(request, 'home.html', {})

    if not request.user.is_authenticated() and  (request.META['HTTP_HOST'] == "rationalfiction.io" or \
       request.META['HTTP_HOST'] == "localhost:8000"):
        return render(request, 'home-rationalfiction.html', {})

    if check_if_daily(request):
        if request.user.is_authenticated():
            return HttpResponseRedirect('/write/')
        return render(request, 'home-daily.html', {})

    if request.user.is_authenticated():
        return HttpResponseRedirect('/browse/')

    # fictionhub includes rational
    if rational:
        posts = Post.objects.filter(published=True,
                                    rational=rational,
                                    post_type="story")
    else:
        posts = Post.objects.filter(published=True, post_type="story")

    # Approved only
    posts = posts.filter(author__approved=True)

    # Count words
    r = re.compile(r'[{}]'.format(punctuation))
    for post in posts:
        wordcount = 0
        text = r.sub(' ', post.body)
        wordcount += len(text.split())
        if post.children:
            for child in post.children.all():
                text = r.sub(' ', child.body)
                wordcount += len(text.split())
        if wordcount > 1000:
            wordcount = str(int(wordcount / 1000)) + "K"
        post.wordcount = wordcount

    # fictionhub doesn't include rational
    # posts = Post.objects.filter(published=True, rational=rational, post_type="story")
    timespan = "all-time"
    hot_posts = rank_hot(posts, top=32)[:10]
    top_posts = rank_top(posts, timespan=timespan)[:10]
    new_posts = posts.order_by('-pub_date')[:10]
    # hubs = Hub.objects.all().annotate(number_of_posts=Count('posts')).order_by('-number_of_posts')
    hubs = Hub.objects.all()

    # Add attribute:
    # for hub in hubs:
    #     stories = hub.posts.filter(published = True, rational = rational)
    #     hub.storycount = stories.count()
    # hubs_storycount = []
    # for hub in hubs:
    #     stories = hub.posts.filter(published = True, rational = rational)
    #     hub.storycount = stories.count()
    #     hubs_storycount.append(hub)

    # hubs =
    # hubs = hubs_storycount.order_by('storycount')

    return render(
        request,
        'home.html',
        {
            'hot_posts': top_posts,  # hot_posts,
            'new_posts': new_posts,
            'hubs': hubs
        })