<commit_before>"""CMS Plugins for the ``cmsplugin_redirect`` app."""
from django.utils.translation import ugettext_lazy as _
from django.http import HttpResponseRedirect

from cms.plugins.link.forms import LinkForm
from cms.plugin_pool import plugin_pool
from cms.plugin_base import CMSPluginBase

from .models import ForceRedirectPluginModel
from .middleware import ForceResponse


class ForceRedirectPlugin(CMSPluginBase):
    model = ForceRedirectPluginModel
    form = LinkForm
    name = _('Redirect action')
    admin_preview = False

    def render(self, context, instance, placeholder):
        current_page = context['request'].current_page
        # if the user defined a page and that isn't the current one, redirect
        # there
        if instance.page_link and instance.page != instance.page_link:
            url = instance.page_link.get_path()
        else:
            # otherwise try to redirect to the first child if present
            try:
                url = '/{}/'.format(
                    current_page.get_children()[0].get_path())
            except IndexError:
                raise Exception('No child page found!')

        raise ForceResponse(HttpResponseRedirect(url))


plugin_pool.register_plugin(ForceRedirectPlugin)
<commit_msg>should be using absolute url instead of path<commit_after>"""CMS Plugins for the ``cmsplugin_redirect`` app."""
from django.utils.translation import ugettext_lazy as _
from django.http import HttpResponseRedirect

from cms.plugins.link.forms import LinkForm
from cms.plugin_pool import plugin_pool
from cms.plugin_base import CMSPluginBase

from .models import ForceRedirectPluginModel
from .middleware import ForceResponse


class ForceRedirectPlugin(CMSPluginBase):
    model = ForceRedirectPluginModel
    form = LinkForm
    name = _('Redirect action')
    admin_preview = False

    def render(self, context, instance, placeholder):
        current_page = context['request'].current_page
        # if the user defined a page and that isn't the current one, redirect
        # there
        if instance.page_link and instance.page != instance.page_link:
            url = instance.page_link.get_absolute_url()
        else:
            # otherwise try to redirect to the first child if present
            try:
                url = '/{}/'.format(
                    current_page.get_children()[0].get_path())
            except IndexError:
                raise Exception('No child page found!')

        raise ForceResponse(HttpResponseRedirect(url))


plugin_pool.register_plugin(ForceRedirectPlugin)

{'fraction_non_alphanumeric': 0.07444746025591314, 'fraction_numerical': 0.0007754943776657619, 'mean_word_length': 3.1082802547770703, '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': '1343822', 'n_tokens_mistral': 660, 'n_tokens_neox': 641, 'n_words': 205}