<commit_before>from django.contrib import messages
from django.contrib.auth.decorators import permission_required
from django.http import HttpRequest, HttpResponse
from django.shortcuts import redirect
from django.template.response import TemplateResponse
from django.utils.translation import pgettext_lazy

from ...payment.gateways.braintree.plugin import BraintreeGatewayPlugin
from ...payment.gateways.dummy.plugin import DummyGatewayPlugin
from ...payment.gateways.razorpay.plugin import RazorpayGatewayPlugin
from ...payment.gateways.stripe.plugin import StripeGatewayPlugin
from ..views import staff_member_required
from .forms import GatewayConfigurationForm

PAYMENT_PLUGINS = [
    BraintreeGatewayPlugin,
    DummyGatewayPlugin,
    RazorpayGatewayPlugin,
    StripeGatewayPlugin,
]

PAYMENT_GATEWAYS = {plugin.PLUGIN_NAME: plugin for plugin in PAYMENT_PLUGINS}


@staff_member_required
@permission_required("extensions.manage_plugins")
def index(request: "HttpRequest") -> TemplateResponse:
    ctx = {"payment_gateways": PAYMENT_GATEWAYS.keys()}
    return TemplateResponse(request, "dashboard/payments/index.html", ctx)


@staff_member_required
@permission_required("extension.manage_plugins")
def configure_payment_gateway(request: HttpRequest, plugin_name: str) -> HttpResponse:
    plugin = PAYMENT_GATEWAYS.get(plugin_name, None)
    if plugin is None:
        msg = pgettext_lazy("Dashboard message", "Selected plugin does not exists.")
        messages.error(request, msg)
        return redirect("dashboard:payments-index")

    form = GatewayConfigurationForm(plugin, request.POST or None)
    if form.is_valid():
        form.save()
        msg = pgettext_lazy("Dashboard message", "Payment config succesfully updated")
        messages.success(request, msg)
        return redirect("dashboard:payments-index")

    ctx = {"plugin_name": plugin_name, "config_form": form}
    return TemplateResponse(request, "dashboard/payments/configuration_form.html", ctx)<commit_msg>Fix typo<commit_after>from django.contrib import messages
from django.contrib.auth.decorators import permission_required
from django.http import HttpRequest, HttpResponse
from django.shortcuts import redirect
from django.template.response import TemplateResponse
from django.utils.translation import pgettext_lazy

from ...payment.gateways.braintree.plugin import BraintreeGatewayPlugin
from ...payment.gateways.dummy.plugin import DummyGatewayPlugin
from ...payment.gateways.razorpay.plugin import RazorpayGatewayPlugin
from ...payment.gateways.stripe.plugin import StripeGatewayPlugin
from ..views import staff_member_required
from .forms import GatewayConfigurationForm

PAYMENT_PLUGINS = [
    BraintreeGatewayPlugin,
    DummyGatewayPlugin,
    RazorpayGatewayPlugin,
    StripeGatewayPlugin,
]

PAYMENT_GATEWAYS = {plugin.PLUGIN_NAME: plugin for plugin in PAYMENT_PLUGINS}


@staff_member_required
@permission_required("extensions.manage_plugins")
def index(request: "HttpRequest") -> TemplateResponse:
    ctx = {"payment_gateways": PAYMENT_GATEWAYS.keys()}
    return TemplateResponse(request, "dashboard/payments/index.html", ctx)


@staff_member_required
@permission_required("extension.manage_plugins")
def configure_payment_gateway(request: HttpRequest, plugin_name: str) -> HttpResponse:
    plugin = PAYMENT_GATEWAYS.get(plugin_name, None)
    if plugin is None:
        msg = pgettext_lazy("Dashboard message", "Selected plugin does not exist.")
        messages.error(request, msg)
        return redirect("dashboard:payments-index")

    form = GatewayConfigurationForm(plugin, request.POST or None)
    if form.is_valid():
        form.save()
        msg = pgettext_lazy("Dashboard message", "Payment config succesfully updated")
        messages.success(request, msg)
        return redirect("dashboard:payments-index")

    ctx = {"plugin_name": plugin_name, "config_form": form}
    return TemplateResponse(request, "dashboard/payments/configuration_form.html", ctx)
{'fraction_non_alphanumeric': 0.08793969849246232, 'fraction_numerical': 0.0, 'mean_word_length': 5.3798076923076925, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 7, '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': '1059548', 'n_tokens_mistral': 1115, 'n_tokens_neox': 1119, 'n_words': 258}