<commit_before>from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator
from django.views.generic.base import TemplateView
from django.views.generic import View
from django.http import JsonResponse, QueryDict
from django.core.exceptions import ValidationError
from django.template.loader import render_to_string
from django.shortcuts import get_object_or_404
from django.conf import settings
from django.core.urlresolvers import reverse

import datetime
import dateutil.parser

import markdown
import bleach

from itertools import chain

from Hindlebook.models import Post, Comment
from Hindlebook.forms import PostForm, CommentForm
from api import json_derulo
from api.serializers import CommentSerializer


class StreamView(TemplateView):

    template_name = "stream.html"

    @method_decorator(login_required)
    def dispatch(self, *args, **kwargs):
        return super(StreamView, self).dispatch(*args, **kwargs)

    def get_context_data(self, **kwargs):
        context = super(StreamView, self).get_context_data(**kwargs)
        context['posts'] = None
        context['post_form'] = PostForm()
        context['comment_form'] = CommentForm()
        context['github_id'] = self.request.user.author.github_id
        return context

    def post(self, *args, **kwargs):
        posts = []
        comments = []
        time = None
        if self.request.POST['last_time'] != '':
            time = dateutil.parser.parse(self.request.POST['last_time'])
            time = time + datetime.timedelta(0, 3)
            json_derulo.getForeignStreamPosts(self.request.user.author, time)
        local_posts = Post.objects_ext.get_all_visibile_posts(active_author=self.request.user.author, reversed=False, min_time=time)

        for post in local_posts:
            response_data = {}
            if (post.content_type == "text/x-markdown"):
                display_content = markdown.markdown(post.content)
            elif (post.content_type == "text/html"):
                display_content = post.content
            else:
                display_content = post.content
            bleach.clean(display_content)
            response_data["post"] = render_to_string("post/post.html", {"post": post, "display_content": display_content, "MEDIA_URL": settings.MEDIA_URL})
            response_data["post"] += render_to_string("post/post_footer.html", {"post": post})
            response_data["created_guid"] = post.guid
            posts.append(response_data)
<commit_msg>Made it sanitize with bleach but have to figure out how to make it display again..<commit_after>from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator
from django.views.generic.base import TemplateView
from django.views.generic import View
from django.http import JsonResponse, QueryDict
from django.core.exceptions import ValidationError
from django.template.loader import render_to_string
from django.shortcuts import get_object_or_404
from django.conf import settings
from django.core.urlresolvers import reverse

import datetime
import dateutil.parser

import markdown
import bleach

from itertools import chain

from Hindlebook.models import Post, Comment
from Hindlebook.forms import PostForm, CommentForm
from api import json_derulo
from api.serializers import CommentSerializer


class StreamView(TemplateView):

    template_name = "stream.html"

    @method_decorator(login_required)
    def dispatch(self, *args, **kwargs):
        return super(StreamView, self).dispatch(*args, **kwargs)

    def get_context_data(self, **kwargs):
        context = super(StreamView, self).get_context_data(**kwargs)
        context['posts'] = None
        context['post_form'] = PostForm()
        context['comment_form'] = CommentForm()
        context['github_id'] = self.request.user.author.github_id
        return context

    def post(self, *args, **kwargs):
        posts = []
        comments = []
        time = None
        if self.request.POST['last_time'] != '':
            time = dateutil.parser.parse(self.request.POST['last_time'])
            time = time + datetime.timedelta(0, 3)
            json_derulo.getForeignStreamPosts(self.request.user.author, time)
        local_posts = Post.objects_ext.get_all_visibile_posts(active_author=self.request.user.author, reversed=False, min_time=time)

        for post in local_posts:
            response_data = {}
            if (post.content_type == "text/x-markdown"):
                display_content = markdown.markdown(post.content)
            elif (post.content_type == "text/html"):
                display_content = post.content
            else:
                display_content = post.content
            display_content = bleach.clean(display_content)
            response_data["post"] = render_to_string("post/post.html", {"post": post, "display_content": display_content, "MEDIA_URL": settings.MEDIA_URL})
            response_data["post"] += render_to_string("post/post_footer.html", {"post": post})
            response_data["created_guid"] = post.guid
            posts.append(response_data)

{'fraction_non_alphanumeric': 0.09838928779351834, 'fraction_numerical': 0.0019406171162429653, 'mean_word_length': 3.420240137221269, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, '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': '4624929', 'n_tokens_mistral': 1432, 'n_tokens_neox': 1398, 'n_words': 328}