<commit_before>import json

from django.contrib import auth
from django.contrib.auth.decorators import login_required
from django.core.paginator import Paginator
from django.core.urlresolvers import reverse
from django.http import HttpResponse, HttpResponseRedirect, Http404
from django.shortcuts import get_object_or_404

from activity.models import Activity
from users.models import Profile, Link
from users.forms import ProfileForm, ProfileLinksForm

import jingo

ACTIVITY_PAGE_SIZE = 20


def dashboard(request, page=0):
    """Display first page of activities for a users dashboard."""
    start = int(page) * ACTIVITY_PAGE_SIZE
    end = start + ACTIVITY_PAGE_SIZE
    profile = request.user.get_profile()
    all_activities = Activity.objects.filter(
        entry__link__project__in=profile.projects_following.all()
    ).select_related('entry', 'entry__link', 'entry__link__project').order_by(
        '-published_on'
    )
    activities = all_activities[start:end]
    if request.is_ajax():
        if not all_activities:
            raise Http404
        return jingo.render(request, 'activity/activity.html', {
            'activities': activities,
            'show_meta': True
        })
    return jingo.render(request, 'users/dashboard.html', {
        'profile': profile,
        'activities': activities,
        'has_more': len(all_activities) > end,
        'next_page': int(page) + 1,
        'total': len(all_activities)
    })


def signout(request):
    """Sign the user out, destroying their session."""
    auth.logout(request)
    return HttpResponseRedirect(reverse('innovate_splash'))


def profile(request, username):
    """Display profile page for user specified by ``username``."""
    user = get_object_or_404(auth.models.User, username=username)
    profile = get_object_or_404(Profile, user=user)
    if profile.link_set.count() != 0:
        social_links = profile.link_set.all()
    else:
        social_links = False
    if profile.project_set.count() != 0:
        projects = profile.project_set.all()
    else:
        projects = False
    return jingo.render(request, 'users/profile.html', {
        'profile': profile,
        'social_links': social_links,
        'projects': projects
    })


@login_required
def links(request):
    if not request.is_ajax():
        raise Http404
    profile = request.user.get_profile()
    links = Link.objects.filter(profile=profile).order_by('id')
    return jingo.render(request, 'users/links.html', {
        'links': links
    })


@login_required
def delete_link(request, id):<commit_msg>2 lines > 10 lines<commit_after>import json

from django.contrib import auth
from django.contrib.auth.decorators import login_required
from django.core.paginator import Paginator
from django.core.urlresolvers import reverse
from django.http import HttpResponse, HttpResponseRedirect, Http404
from django.shortcuts import get_object_or_404

from activity.models import Activity
from users.models import Profile, Link
from users.forms import ProfileForm, ProfileLinksForm

import jingo

ACTIVITY_PAGE_SIZE = 20


def dashboard(request, page=0):
    """Display first page of activities for a users dashboard."""
    start = int(page) * ACTIVITY_PAGE_SIZE
    end = start + ACTIVITY_PAGE_SIZE
    profile = request.user.get_profile()
    all_activities = Activity.objects.filter(
        entry__link__project__in=profile.projects_following.all()
    ).select_related('entry', 'entry__link', 'entry__link__project').order_by(
        '-published_on'
    )
    activities = all_activities[start:end]
    if request.is_ajax():
        if not all_activities:
            raise Http404
        return jingo.render(request, 'activity/activity.html', {
            'activities': activities,
            'show_meta': True
        })
    return jingo.render(request, 'users/dashboard.html', {
        'profile': profile,
        'activities': activities,
        'has_more': len(all_activities) > end,
        'next_page': int(page) + 1,
        'total': len(all_activities)
    })


def signout(request):
    """Sign the user out, destroying their session."""
    auth.logout(request)
    return HttpResponseRedirect(reverse('innovate_splash'))


def profile(request, username):
    """Display profile page for user specified by ``username``."""
    user = get_object_or_404(auth.models.User, username=username)
    profile = get_object_or_404(Profile, user=user)
    return jingo.render(request, 'users/profile.html', {
        'profile': profile,
        'social_links': profile.link_set.all() or False,
        'projects': profile.project_set.all() or False
    })


@login_required
def links(request):
    if not request.is_ajax():
        raise Http404
    profile = request.user.get_profile()
    links = Link.objects.filter(profile=profile).order_by('id')
    return jingo.render(request, 'users/links.html', {
        'links': links
    })


@login_required
def delete_link(request, id):
{'fraction_non_alphanumeric': 0.10745967741935483, 'fraction_numerical': 0.009879032258064515, 'mean_word_length': 3.5639374425023, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '4397018', 'n_tokens_mistral': 1483, 'n_tokens_neox': 1432, 'n_words': 348}