<commit_before>from django import forms
from djforms.core.models import STATE_CHOICES

from models import Contact, Order

from djtools.fields.localflavor import USPhoneNumberField
from djtools.fields import TODAY

from trust_commerce import PaymentProcessor
from localflavor.us.forms import USZipCodeField
from captcha.fields import ReCaptchaField

EXP_MONTH = [(x, x) for x in xrange(1, 13)]
EXP_YEAR = [(x, x) for x in xrange(TODAY.year, TODAY.year + 15)]
REQ = {'class': 'required'}


class ContactForm(forms.ModelForm):
    """
    A generic form to collect contact info
    """
    phone = forms.CharField(
        label="Phone number", max_length=12,
        required=False
    )
    state = forms.CharField(
        widget=forms.Select(choices=STATE_CHOICES), required=False
    )
    postal_code = USZipCodeField(required=False)

    class Meta:
        model = Contact
        exclude = (
            'country','order','second_name','previous_name',
            'salutation','longitude','latitude'
        )


class OrderForm(forms.ModelForm):
    """
    A generic form to collect order info
    """
    avs = forms.CharField(
        required = False,
        widget=forms.HiddenInput()
    )
    auth = forms.CharField(
        required = False,
        widget=forms.HiddenInput()
    )
    cycle = forms.CharField(
        required = False,
        widget=forms.HiddenInput()
    )
    total = forms.CharField(max_length=100)

    class Meta:
        model = Order
        fields = ('total',)


class CreditCardForm(forms.Form):
    """
    A generic form to collect credit card information
    and then charge the credit card.
    """
    def __init__(self, *args, **kwargs):
        # globally override the Django >=1.6 default of ':'
        kwargs.setdefault('label_suffix', '')
        super(CreditCardForm, self).__init__(*args, **kwargs)

    billing_name = forms.CharField(
        max_length=128, label="Name on card", widget=forms.TextInput(attrs=REQ)
    )
    card_number = forms.CharField(
        label="Card number", max_length=16, widget=forms.TextInput(attrs=REQ)
    )
    expiration_month = forms.CharField(
        max_length=2,
        widget=forms.Select(
            choices=EXP_MONTH, attrs={'class': 'required input-mini'}
        )
    )
    expiration_year = forms.CharField(
        max_length=4,
        widget=forms.Select(
            choices=EXP_YEAR, attrs={'class': 'required input-small'}
        )
    )
    security_code = forms.CharField(
        max_length=4,
        help_text="""
            The 3 or 4 digit code on your credit card.
        """,
        widget=forms.TextInput(attrs=REQ)
    )
    captcha = ReCaptchaField()


class TrustCommerceForm(CreditCardForm):
    """<commit_msg>now using google's v3 of recaptcha form field<commit_after>from django import forms
from djforms.core.models import STATE_CHOICES

from models import Contact, Order

from djtools.fields.localflavor import USPhoneNumberField
from djtools.fields import TODAY

from trust_commerce import PaymentProcessor
from localflavor.us.forms import USZipCodeField
from captcha.fields import ReCaptchaField
from captcha.widgets import ReCaptchaV2Checkbox
from captcha.widgets import ReCaptchaV2Invisible
from captcha.widgets import ReCaptchaV3


EXP_MONTH = [(x, x) for x in xrange(1, 13)]
EXP_YEAR = [(x, x) for x in xrange(TODAY.year, TODAY.year + 15)]
REQ = {'class': 'required'}


class ContactForm(forms.ModelForm):
    """
    A generic form to collect contact info
    """
    phone = forms.CharField(
        label="Phone number", max_length=12,
        required=False
    )
    state = forms.CharField(
        widget=forms.Select(choices=STATE_CHOICES), required=False
    )
    postal_code = USZipCodeField(required=False)

    class Meta:
        model = Contact
        exclude = (
            'country','order','second_name','previous_name',
            'salutation','longitude','latitude'
        )


class OrderForm(forms.ModelForm):
    """
    A generic form to collect order info
    """
    avs = forms.CharField(
        required = False,
        widget=forms.HiddenInput()
    )
    auth = forms.CharField(
        required = False,
        widget=forms.HiddenInput()
    )
    cycle = forms.CharField(
        required = False,
        widget=forms.HiddenInput()
    )
    total = forms.CharField(max_length=100)

    class Meta:
        model = Order
        fields = ('total',)


class CreditCardForm(forms.Form):
    """
    A generic form to collect credit card information
    and then charge the credit card.
    """
    def __init__(self, *args, **kwargs):
        # globally override the Django >=1.6 default of ':'
        kwargs.setdefault('label_suffix', '')
        super(CreditCardForm, self).__init__(*args, **kwargs)

    billing_name = forms.CharField(
        max_length=128, label="Name on card", widget=forms.TextInput(attrs=REQ)
    )
    card_number = forms.CharField(
        label="Card number", max_length=16, widget=forms.TextInput(attrs=REQ)
    )
    expiration_month = forms.CharField(
        max_length=2,
        widget=forms.Select(
            choices=EXP_MONTH, attrs={'class': 'required input-mini'}
        )
    )
    expiration_year = forms.CharField(
        max_length=4,
        widget=forms.Select(
            choices=EXP_YEAR, attrs={'class': 'required input-small'}
        )
    )
    security_code = forms.CharField(
        max_length=4,
        help_text="""
            The 3 or 4 digit code on your credit card.
        """,
        widget=forms.TextInput(attrs=REQ)
    )
    captcha = ReCaptchaField(
        label = "",
        widget=ReCaptchaV3()
    )
    '''
    captcha = ReCaptchaField(
        widget=ReCaptchaV2Checkbox(
            attrs={
                'data-theme': 'dark',
                'data-size': 'compact',
            }
        )
    )
    '''


class TrustCommerceForm(CreditCardForm):
    """
{'fraction_non_alphanumeric': 0.10810810810810811, 'fraction_numerical': 0.008445945945945946, 'mean_word_length': 2.6481823783117684, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '7629993', 'n_tokens_mistral': 1827, 'n_tokens_neox': 1753, 'n_words': 413}