<commit_before>from django.views.generic.edit import CreateView
from django.shortcuts import render_to_response, render, get_object_or_404,\
    redirect
from django.contrib.auth import authenticate, login as auth_login
from django.contrib.auth.models import User
from django.template.context import RequestContext
from stream_django.enrich import Enrich
from stream_django.feed_manager import feed_manager
from stream_twitter.forms import FollowForm
from stream_twitter.models import Follow
from stream_twitter.models import Tweet, Hashtag
from pytutorial import settings


enricher = Enrich()


class TimelineView(CreateView):
    model = Tweet
    fields = ['text']
    success_url = "/timeline/"

    def form_valid(self, form):
        form.instance.user = self.request.user
        return super(TimelineView, self).form_valid(form)

    def get(self, request):
        feeds = feed_manager.get_news_feeds(request.user.id)
        activities = feeds.get('flat').get()['results']
        activities = enricher.enrich_activities(activities)
        hashtags = Hashtag.objects.order_by('-occurrences')
        context = {
            'activities': activities,
            'form': self.get_form_class(),
            'login_user': request.user,
            'hashtags': hashtags
        }
        return render(request, 'stream_twitter/timeline.html', context)


class HomeView(CreateView):
    greeting = "Welcome to Stream Twitter"

    def get(self, request):
        # import pdb;pdb.set_trace()
        if not request.user.is_authenticated() and not settings.USE_AUTH:
            admin_user = authenticate(
                username=settings.DEMO_USERNAME, password=settings.DEMO_PASSWORD)
            auth_login(request, admin_user)
        context = RequestContext(request)
        context_dict = {
            'greeting': self.greeting,
            'login_user': request.user,
            'users': User.objects.order_by('-date_joined')
        }
        return render_to_response('stream_twitter/home.html', context_dict, context)


def follow(request):
    form = FollowForm(request.POST)
    if form.is_valid():
        follow = form.instance
        follow.user = request.user
        follow.save()
    return redirect("/timeline/")


def unfollow(request, target_id):
    follow = Follow.objects.filter(user=request.user, target_id=target_id).first()
    if follow is not None:
        follow.delete()
    return redirect("/timeline/")


def discover(request):
    users = User.objects.order_by('-date_joined')
    login_user = User.objects.get(username=request.user)
    following = []
    for i in users:<commit_msg>resort users in the discover page<commit_after>from django.views.generic.edit import CreateView
from django.shortcuts import render_to_response, render, get_object_or_404,\
    redirect
from django.contrib.auth import authenticate, login as auth_login
from django.contrib.auth.models import User
from django.template.context import RequestContext
from stream_django.enrich import Enrich
from stream_django.feed_manager import feed_manager
from stream_twitter.forms import FollowForm
from stream_twitter.models import Follow
from stream_twitter.models import Tweet, Hashtag
from pytutorial import settings


enricher = Enrich()


class TimelineView(CreateView):
    model = Tweet
    fields = ['text']
    success_url = "/timeline/"

    def form_valid(self, form):
        form.instance.user = self.request.user
        return super(TimelineView, self).form_valid(form)

    def get(self, request):
        feeds = feed_manager.get_news_feeds(request.user.id)
        activities = feeds.get('flat').get()['results']
        activities = enricher.enrich_activities(activities)
        hashtags = Hashtag.objects.order_by('-occurrences')
        context = {
            'activities': activities,
            'form': self.get_form_class(),
            'login_user': request.user,
            'hashtags': hashtags
        }
        return render(request, 'stream_twitter/timeline.html', context)


class HomeView(CreateView):
    greeting = "Welcome to Stream Twitter"

    def get(self, request):
        if not request.user.is_authenticated() and not settings.USE_AUTH:
            admin_user = authenticate(
                username=settings.DEMO_USERNAME, password=<PASSWORD>.<PASSWORD>)
            auth_login(request, admin_user)
        context = RequestContext(request)
        context_dict = {
            'greeting': self.greeting,
            'login_user': request.user,
            'users': User.objects.order_by('-date_joined')
        }
        return render_to_response('stream_twitter/home.html', context_dict, context)


def follow(request):
    form = FollowForm(request.POST)
    if form.is_valid():
        follow = form.instance
        follow.user = request.user
        follow.save()
    return redirect("/timeline/")


def unfollow(request, target_id):
    follow = Follow.objects.filter(user=request.user, target_id=target_id).first()
    if follow is not None:
        follow.delete()
    return redirect("/timeline/")


def discover(request):
    users = User.objects.order_by('date_joined')
    login_user = User.objects.get(username=request.user)
    following = []
    for i in users:
{'fraction_non_alphanumeric': 0.09925558312655088, 'fraction_numerical': 0.0011452567283832794, 'mean_word_length': 3.1953562850280224, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6779887', 'n_tokens_mistral': 1524, 'n_tokens_neox': 1489, 'n_words': 338}