<commit_before>import CommonMark
from django.views import generic
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from django.core.urlresolvers import reverse_lazy
from . models import Post
from django.contrib.auth.models import User
from dashboard.models import Author
from django.contrib.auth import authenticate, login
from django.contrib.auth.decorators import login_required
from .forms import PostForm
from django.http import HttpResponse, HttpResponseRedirect, Http404
from django.shortcuts import render, get_object_or_404
from django.contrib import messages
from .models import Post, Comment
from .forms import CommentForm
from django.shortcuts import render, get_object_or_404, redirect
from django.db.models import Q


class IndexView(generic.ListView):
    template_name = 'post/index.html'
    context_object_name = 'all_posts'

    def get_queryset(self):
        return Post.objects.all().order_by('-pub_date')


def view_posts(request):
    if request.user.is_authenticated():
        user = request.user
        author = Author.objects.get(user=request.user.id)
        context = dict()
        context1 = dict()
        context2 = dict()

        # NOTE: this does the same thing as the function indexHome in dashboard/view.py
        # Return posts that are NOT by current user (=author) and:

        # case 1: post.visibility=public and following               --> can view
        # case 1': post.visibility=public  and not following          --> can't view
        # case 2': post.visibility=friends and not friends            --> can't view
        context1['visible_posts'] = Post.objects \
            .filter(~Q(author__id=user.profile.id)) \
            .filter(author__id__in=author.followed_authors.all()) \
            .filter(visibility="PUBLIC").order_by('-pub_date')

        # case 2: post.visibility=friends and friends                 --> can view
        context2['visible_posts'] = Post.objects \
            .filter(~Q(author__id=user.profile.id)) \
            .filter(author__id__in=author.friends.all()) \
            .filter(Q(visibility="FRIENDS") | Q(visibility="PUBLIC")).order_by('-pub_date')

        context["visible_posts"] = context1["visible_posts"] | context2["visible_posts"]

        # TODO: need to be able to filter posts by current user's relationship to post author
        # case 3: post.visibility=foaf and friend/foaf                --> can view<commit_msg>My posts can only be seen by on this server.<commit_after>import CommonMark
from django.views import generic
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from django.core.urlresolvers import reverse_lazy
from . models import Post
from django.contrib.auth.models import User
from dashboard.models import Author
from django.contrib.auth import authenticate, login
from django.contrib.auth.decorators import login_required
from .forms import PostForm
from django.http import HttpResponse, HttpResponseRedirect, Http404
from django.shortcuts import render, get_object_or_404
from django.contrib import messages
from .models import Post, Comment
from .forms import CommentForm
from django.shortcuts import render, get_object_or_404, redirect
from django.db.models import Q


class IndexView(generic.ListView):
    template_name = 'post/index.html'
    context_object_name = 'all_posts'

    def get_queryset(self):
        return Post.objects.all().order_by('-pub_date')


def view_posts(request):
    if request.user.is_authenticated():
        user = request.user
        author = Author.objects.get(user=request.user.id)
        context = dict()
        context1 = dict()
        context2 = dict()

        # NOTE: this does the same thing as the function indexHome in dashboard/view.py
        # Return posts that are NOT by current user (=author) and:

        # case 1: post.visibility=public and following               --> can view
        # case 1': post.visibility=public  and not following          --> can't view
        # case 2': post.visibility=friends and not friends            --> can't view
        context1['visible_posts'] = Post.objects \
            .filter(~Q(author__id=user.profile.id)) \
            .filter(author__id__in=author.followed_authors.all()) \
            .filter(visibility="PUBLIC").order_by('-pub_date')

        # case 2: post.visibility=friends and friends and friends on this server --> can view
        context2['visible_posts'] = Post.objects \
            .filter(~Q(author__id=user.profile.id)) \
            .filter(author__id__in=author.friends.all()) \
            .filter(Q(visibility="FRIENDS") | Q(visibility="PUBLIC") | Q(visibility="SERVERONLY")) \
            .order_by('-pub_date')

        context["visible_posts"] = context1["visible_posts"] | context2["visible_posts"]

        # TODO: need to be able to filter posts by current user's relationship to post author
        # case 3: post.visibility=foaf and friend/foaf                --> can view
{'fraction_non_alphanumeric': 0.09766881028938906, 'fraction_numerical': 0.008038585209003215, 'mean_word_length': 3.0828547990155863, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '860804', 'n_tokens_mistral': 1414, 'n_tokens_neox': 1322, 'n_words': 389}