<commit_before>

from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.shortcuts import get_object_or_404, redirect
from mezzanine.conf import settings
from mezzanine.generic.models import ThreadedComment
from mezzanine.utils.views import render, paginate

from .models import Link
from .forms import LinkForm
from .utils import order_by_score


PAGING = (settings.ITEMS_PER_PAGE, settings.MAX_PAGING_LINKS)


def link_detail(request, slug, template="link_detail.html"):
    links = Link.objects.select_related("user")
    context = {"link": get_object_or_404(links, slug=slug)}
    return render(request, template, context)


@login_required
def link_create(request, template="link_form.html"):
    link_form = LinkForm(request.POST or None)
    if request.method == "POST" and link_form.is_valid():
        link = link_form.save(commit=False)
        link.user = request.user
        link.gen_description = False
        link.save()
        return redirect(link)
    context = {"link_form": link_form}
    return render(request, template, context)


@login_required
def link_edit(request, slug, template="link_form.html"):
    links = Link.objects.published(for_user=request.user)
    link = get_object_or_404(links, slug=slug)
    link_form = LinkForm(request.POST or None, instance=link)
    if request.method == "POST" and link_form.is_valid():
        link = link_form.save()
        return redirect(link)
    context = {"link_form": link_form}
    return render(request, template, context)


def link_list(request, username=None, by_score=True, template="link_list.html"):
    links = Link.objects.select_related("user")
    profile_user = None
    title = ""
    if username:
        user_lookup = {"username__iexact": username, "is_active": True}
        profile_user = get_object_or_404(User, **user_lookup)
        links = links.filter(user=profile_user)
    if by_score:
        links = order_by_score(links, "publish_date")<commit_msg>Remove link editing view since we don't use it.<commit_after>

from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.shortcuts import get_object_or_404, redirect
from mezzanine.conf import settings
from mezzanine.generic.models import ThreadedComment
from mezzanine.utils.views import render, paginate

from .models import Link
from .forms import LinkForm
from .utils import order_by_score


PAGING = (settings.ITEMS_PER_PAGE, settings.MAX_PAGING_LINKS)


def link_detail(request, slug, template="link_detail.html"):
    links = Link.objects.select_related("user")
    context = {"link": get_object_or_404(links, slug=slug)}
    return render(request, template, context)


@login_required
def link_create(request, template="link_form.html"):
    link_form = LinkForm(request.POST or None)
    if request.method == "POST" and link_form.is_valid():
        link = link_form.save(commit=False)
        link.user = request.user
        link.gen_description = False
        link.save()
        return redirect(link)
    context = {"link_form": link_form}
    return render(request, template, context)


def link_list(request, username=None, by_score=True, template="link_list.html"):
    links = Link.objects.select_related("user")
    profile_user = None
    title = ""
    if username:
        user_lookup = {"username__iexact": username, "is_active": True}
        profile_user = get_object_or_404(User, **user_lookup)
        links = links.filter(user=profile_user)
    if by_score:
        links = order_by_score(links, "publish_date")
{'fraction_non_alphanumeric': 0.1013044684984735, 'fraction_numerical': 0.005828476269775187, 'mean_word_length': 4.30780559646539, 'pattern_counts': {'":': 9, '<': 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': '5062811', 'n_tokens_mistral': 1119, 'n_tokens_neox': 1090, 'n_words': 262}