<commit_before>from __future__ import absolute_import, unicode_literals

from django import template
from django.template.defaulttags import token_kwargs
from django.utils.encoding import force_text
from django.utils.safestring import mark_safe

from wagtail import __version__
from wagtail.wagtailcore.models import Page
from wagtail.wagtailcore.rich_text import RichText, expand_db_html
from wagtail.wagtailcore.utils import accepts_kwarg

register = template.Library()


@register.simple_tag(takes_context=True)
def pageurl(context, page):
    """
    Outputs a page's URL as relative (/foo/bar/) if it's within the same site as the
    current page, or absolute (http://example.com/foo/bar/) if not.
    """
    try:
        current_site = context['request'].site
    except (KeyError, AttributeError):
        # request.site not available in the current context; fall back on page.url
        return page.url

    # RemovedInWagtail113Warning - this accepts_kwarg test can be removed when we drop support
    # for relative_url methods which omit the `request` kwarg
    if accepts_kwarg(page.relative_url, 'request'):
        # Pass page.relative_url the request object, which may contain a cached copy of
        # Site.get_site_root_paths()
        # This avoids page.relative_url having to make a database/cache fetch for this list
        # each time it's called.
        return page.relative_url(current_site, request=context.get('request'))
    else:
        return page.relative_url(current_site)


@register.simple_tag(takes_context=True)
def slugurl(context, slug):
    """Returns the URL for the page that has the given slug."""
    page = Page.objects.filter(slug=slug).first()

    if page:
        # call pageurl() instead of page.relative_url() here so we get the ``accepts_kwarg`` logic
        return pageurl(context, page)
    else:
        return None

    try:
        current_site = context['request'].site
    except (KeyError, AttributeError):<commit_msg>Remove check for relative_url without a request kwarg from the pageurl tag<commit_after>from __future__ import absolute_import, unicode_literals

from django import template
from django.template.defaulttags import token_kwargs
from django.utils.encoding import force_text
from django.utils.safestring import mark_safe

from wagtail import __version__
from wagtail.wagtailcore.models import Page
from wagtail.wagtailcore.rich_text import RichText, expand_db_html

register = template.Library()


@register.simple_tag(takes_context=True)
def pageurl(context, page):
    """
    Outputs a page's URL as relative (/foo/bar/) if it's within the same site as the
    current page, or absolute (http://example.com/foo/bar/) if not.
    """
    try:
        current_site = context['request'].site
    except (KeyError, AttributeError):
        # request.site not available in the current context; fall back on page.url
        return page.url

    # Pass page.relative_url the request object, which may contain a cached copy of
    # Site.get_site_root_paths()
    # This avoids page.relative_url having to make a database/cache fetch for this list
    # each time it's called.
    return page.relative_url(current_site, request=context.get('request'))


@register.simple_tag(takes_context=True)
def slugurl(context, slug):
    """Returns the URL for the page that has the given slug."""
    page = Page.objects.filter(slug=slug).first()

    if page:
        # call pageurl() instead of page.relative_url() here so we get the ``accepts_kwarg`` logic
        return pageurl(context, page)
    else:
        return None

    try:
        current_site = context['request'].site
    except (KeyError, AttributeError):
{'fraction_non_alphanumeric': 0.08186500406614258, 'fraction_numerical': 0.000813228517213337, 'mean_word_length': 3.761290322580645, 'pattern_counts': {'":': 0, '<': 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': '5623862', 'n_tokens_mistral': 1061, 'n_tokens_neox': 1033, 'n_words': 351}