<commit_before>from django.views.generic.edit import FormView

from authorizenet.forms import CustomerPaymentForm
from .models import CustomerProfile, CustomerPaymentProfile


class PaymentProfileCreationView(FormView):
    template_name = 'authorizenet/payment_profile_creation.html'
    form_class = CustomerPaymentForm

    def form_valid(self, form):
        """If the form is valid, save the payment profile"""
        self.create_payment_profile(
            payment_data=form.cleaned_data,
            billing_data=form.cleaned_data,
        )
        return super(PaymentProfileCreationView, self).form_valid(form)

    def create_payment_profile(self, **kwargs):
        """Create and return payment profile"""
        customer_profile = self.get_customer_profile()
        if customer_profile:
            return CustomerPaymentProfile.objects.create(
                customer_profile=customer_profile, **kwargs)
        else:
            customer_profile = CustomerProfile.objects.create(
                user=self.request.user, **kwargs)
            return customer_profile.payment_profiles.get()

    def get_customer_profile(self):
        """Return customer profile or ``None`` if none exists"""
        try:
            return CustomerProfile.objects.get(user=self.request.user)
        except CustomerProfile.DoesNotExist:
            return None

    def get_context_data(self, **kwargs):
        return kwargs<commit_msg>Fixup code style in generic view<commit_after>from django.views.generic.edit import FormView

from authorizenet.forms import CustomerPaymentForm
from .models import CustomerProfile, CustomerPaymentProfile


class PaymentProfileCreationView(FormView):
    template_name = 'authorizenet/payment_profile_creation.html'
    form_class = CustomerPaymentForm

    def form_valid(self, form):
        """If the form is valid, save the payment profile"""
        data = form.cleaned_data
        self.create_payment_profile(payment_data=data, billing_data=data)
        return super(PaymentProfileCreationView, self).form_valid(form)

    def create_payment_profile(self, **kwargs):
        """Create and return payment profile"""
        customer_profile = self.get_customer_profile()
        if customer_profile:
            return CustomerPaymentProfile.objects.create(
                customer_profile=customer_profile, **kwargs)
        else:
            customer_profile = CustomerProfile.objects.create(
                user=self.request.user, **kwargs)
            return customer_profile.payment_profiles.get()

    def get_customer_profile(self):
        """Return customer profile or ``None`` if none exists"""
        try:
            return CustomerProfile.objects.get(user=self.request.user)
        except CustomerProfile.DoesNotExist:
            return None
{'fraction_non_alphanumeric': 0.07875980042765503, 'fraction_numerical': 0.0, 'mean_word_length': 3.1770833333333335, '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': '6622352', 'n_tokens_mistral': 709, 'n_tokens_neox': 693, 'n_words': 164}