Exemple #1
0
class ProfileEditForm(forms.ModelForm):
    SEX = (
        ('s', 'SEX'),
        ('m', 'MALE'),
        ('f', 'FEMALE'),
    )
    MARITAL = (
        ('si', 'SINGLE'),
        ('ma', 'MARRIED'),
        ('di', 'DIVORCED'),
        ('se', 'SEPERATED'),
    )
    PROFILE_STATE_CHOICES = list(STATE_CHOICES)
    PROFILE_STATE_CHOICES.insert(0, ('', 'STATES'))
    sex = forms.CharField(widget=forms.Select(choices=SEX))
    marital = forms.CharField(widget=forms.Select(choices=MARITAL))
    DOB = forms.DateField(widget=forms.TextInput(
        attrs={'class': 'datepicker'}))
    zip_code = USZipCodeField()
    state_province = USStateField(widget=forms.Select(
        choices=PROFILE_STATE_CHOICES))
    SSN = USSocialSecurityNumberField()
    phone = PhoneNumberField()
    fax = PhoneNumberField()

    class Meta:
        model = Profile
        fields = ('passport', 'sex', 'marital', 'next_of_kin', 'DOB', 'phone',
                  'fax', 'address', 'zip_code', 'state_province', 'SSN',
                  'country')
Exemple #2
0
class ProfileForm(ModelForm):
    wants_newsletter = forms.BooleanField(required=False, )
    STATE_CHOICES = list(STATE_CHOICES)
    STATE_CHOICES.insert(0, ('', '---------'))
    state = USStateField(widget=forms.Select(choices=STATE_CHOICES,
                                             attrs={'class': 'form-control'}))
    zip_code = USZipCodeField(widget=forms.TextInput(
        attrs={'class': 'form-control'}))

    class Meta:
        model = UserProfile
        fields = (
            'address1',
            'address2',
            'city',
            'state',
            'zip_code',
            'wants_newsletter',
        )
        widgets = {
            'address1': forms.TextInput(attrs={'class': 'form-control'}),
            'address2': forms.TextInput(attrs={'class': 'form-control'}),
            'city': forms.TextInput(attrs={'class': 'form-control'}),
            'zip_code': forms.TextInput(attrs={'class': 'form-control'})
        }

    def __init__(self, *args, **kwargs):
        super(ProfileForm, self).__init__(*args, **kwargs)
        self.fields[
            'wants_newsletter'].label = "Send me the monthly Free Law Project newsletter"
        for key in ['address1', 'city', 'state', 'zip_code']:
            self.fields[key].required = True
Exemple #3
0
    def __init__(self, *args, **kwargs):
        instance = kwargs.pop('instance', None)
        initial = kwargs.pop('initial', None)
        user = kwargs.pop('user', None)

        kwargs['instance'] = instance
        kwargs['initial'] = initial

        super(VolunteerForm, self).__init__(*args, **kwargs)

        organizations = None
        if user.is_superuser:
            organizations = Organization.objects.all()
        elif user.organizations:
            organizations = user.organizations.all()

        if user.is_superuser:
            states = list(STATE_CHOICES)
        else:
            user_states = [org.state for org in user.organizations.all()]
            states = []

            for state in list(STATE_CHOICES):
                if state[0] in user_states:
                    states.append(state)

        if len(states) > 1:
            states.insert(0, ('', 'Select ...'))

        self.fields['last_name'] = forms.CharField(required=True)
        self.fields['organization'] = forms.ModelChoiceField(
            queryset=organizations)
        self.fields['state'] = USStateField(
            required=True, widget=forms.Select(choices=states), label='State')
Exemple #4
0
class ProfileForm(ModelForm):
    wants_newsletter = forms.BooleanField(required=False)
    STATE_CHOICES = list(STATE_CHOICES)
    STATE_CHOICES.insert(0, ("", "---------"))
    state = USStateField(widget=forms.Select(choices=STATE_CHOICES,
                                             attrs={"class": "form-control"}))
    zip_code = USZipCodeField(widget=forms.TextInput(
        attrs={"class": "form-control"}))

    class Meta:
        model = UserProfile
        fields = (
            "address1",
            "address2",
            "city",
            "state",
            "zip_code",
            "wants_newsletter",
        )
        widgets = {
            "address1": forms.TextInput(attrs={"class": "form-control"}),
            "address2": forms.TextInput(attrs={"class": "form-control"}),
            "city": forms.TextInput(attrs={"class": "form-control"}),
            "zip_code": forms.TextInput(attrs={"class": "form-control"}),
        }

    def __init__(self, *args, **kwargs):
        super(ProfileForm, self).__init__(*args, **kwargs)
        self.fields[
            "wants_newsletter"].label = "Send me the monthly Free Law Project newsletter"
        for key in ["address1", "city", "state", "zip_code"]:
            self.fields[key].required = True
class RiderForm(forms.ModelForm):
    """
    This allows you to enter information for an individual Rider. Birth date is necessary for people who are 18 or younger. Form for a rider with name, address, email, birth date, whether it is a member of the VHSA, and its county
    """

    year_range = list(reversed(range(1920, datetime.date.today().year + 1)))

    birth_date = forms.DateField(
        help_text="Only enter if you are 18 or younger",
        widget=forms.SelectDateWidget(years=year_range),
    )

    state = USStateField(widget=USStateSelect(), initial="VA", required=False)

    zip_code = USZipCodeField(required=False)

    class Meta:

        model = Rider
        fields = '__all__'
        exclude = ['horses']

    def clean(self):
        cleaned_data = super().clean()
        if cleaned_data['member_4H'] and not cleaned_data['county']:
            raise ValidationError(
                "You must specify a county if the rider is a member of 4H.")

        return cleaned_data
Exemple #6
0
class SearchForm(forms.Form):
    STATES = list(STATE_CHOICES)
    STATES.insert(0, ('', 'Select ...'))

    date_signed = forms.DateField(required=False, label='Date Signed')
    city = forms.CharField(required=False, label='City')
    state = USStateField(required=False, widget=forms.Select(choices=STATES), label='State')
    zip = USZipCodeField(required=False, label='Zip')
    zip_radius = forms.IntegerField(required=False, label='Radius in Miles',
                                    help_text='Leave blank for exact zip code match')

    def clean(self):
        cleaned_data = super(SearchForm, self).clean()

        # make sure they selected at least one search field
        if not cleaned_data.get('date_signed') and not cleaned_data.get('city') \
                and not cleaned_data.get('state') and not cleaned_data.get('zip') \
                and not cleaned_data.get('zip_radius'):
            self.add_error('date_signed', 'Please select at least one search criteria.')
        elif cleaned_data.get('zip'):
            try:
                ZipCode.objects.get(zip=cleaned_data.get('zip'))
            except ZipCode.DoesNotExist:
                self.add_error('zip', 'Invalid zip code')
        elif cleaned_data.get('zip_radius') and not cleaned_data.get('zip'):
            self.add_error('zip', 'A zip code is required when searching on zip code radius')
Exemple #7
0
class UpdateProfileForm(forms.ModelForm):
    username = forms.CharField(max_length=30,
                               required=True,
                               help_text='Required.'
                               'Letters, digits and @/./+/-/_ only.')
    first_name = forms.CharField(max_length=30,
                                 required=True,
                                 help_text='Required.')
    last_name = forms.CharField(max_length=30,
                                required=True,
                                help_text='Required.')
    email = forms.EmailField(max_length=150,
                             required=True,
                             help_text='Required. Enter valid email address.')
    city = forms.CharField(max_length=50, required=True, help_text='Required.')
    zipcode = USZipCodeField(required=True, help_text='Required.')
    state = USStateField(required=True, help_text='Required.')
    country = forms.CharField(max_length=50,
                              initial="United States",
                              required=True,
                              help_text='Required.')
    bio = forms.CharField(widget=forms.Textarea, required=False)
    birth_date = forms.DateField(required=False)
    organization = forms.CharField(max_length=30,
                                   required=False,
                                   label='Company / School / Organization')
    image = forms.ImageField(required=False,
                             help_text='Upload/update your profile image.')
    tags = TagField(required=False,
                    label='Skills & Interests',
                    help_text='Separate entries with commas.')

    class Meta:
        model = User
        # all this determines is the order that the fields appear in
        fields = (
            'username',
            'first_name',
            'last_name',
            'email',
            'city',
            'zipcode',
            'state',
            'country',
            'bio',
            'birth_date',
            'organization',
            'image',
        )

    def clean_email(self):
        username = self.cleaned_data.get('username')
        email = self.cleaned_data.get('email')

        if email and User.objects.filter(email=email).exclude(
                username=username).count():
            raise forms.ValidationError(
                'This email address is already in use. Please supply a different email address.'
            )
        return email
Exemple #8
0
class SignUpForm(UserCreationForm):
    username = forms.CharField(max_length=30,
                               required=True,
                               help_text='Required. '
                               'Letters, digits and @/./+/-/_ only.')
    first_name = forms.CharField(max_length=30,
                                 required=True,
                                 help_text='Required.')
    last_name = forms.CharField(max_length=30,
                                required=True,
                                help_text='Required.')
    email = forms.EmailField(max_length=150,
                             required=True,
                             help_text='Required. Enter valid email address.')
    city = forms.CharField(max_length=50, required=True, help_text='Required.')
    zipcode = USZipCodeField(required=True, help_text='Required.')
    state = USStateField(required=True, help_text='Required.')
    country = forms.CharField(max_length=50,
                              initial="United States",
                              required=True,
                              help_text='Required.')

    class Meta(UserCreationForm):
        model = User
        fields = UserCreationForm.Meta.fields + (
            'username',
            'first_name',
            'last_name',
            'email',
            'city',
            'zipcode',
            'state',
            'password1',
            'password2',
        )
Exemple #9
0
    def __init__(self, *args, **kwargs):
        instance = kwargs.pop('instance', None)
        initial = kwargs.pop('initial', None)
        user = kwargs.pop('user', None)

        kwargs['instance'] = instance
        kwargs['initial'] = initial

        super(ContactForm, self).__init__(*args, **kwargs)

        if user.is_superuser:
            states = list(STATE_CHOICES)
        else:
            user_states = [org.state for org in user.organizations.all()]
            states = []

            for state in list(STATE_CHOICES):
                if state[0] in user_states:
                    states.append(state)

        if len(states) > 1:
            states.insert(0, ('', 'Select ...'))

        self.fields['state'] = USStateField(
            required=True, widget=forms.Select(choices=states), label='State')
Exemple #10
0
class ChainedForm(forms.Form):
    city = selectable.AutoCompleteSelectField(
        lookup_class=CityLookup,
        label='City',
        required=False,
        widget=selectable.AutoComboboxSelectWidget)
    state = USStateField(widget=USStateSelect, required=False)
class CustomerAddress(models.Model):
    line_1 = models.CharField(max_length=300)
    line_2 = models.CharField(max_length=300)
    line_3 = models.CharField(max_length=300)
    city = models.CharField(max_length=150)
    postalcode = models.CharField(max_length=10)
    state = USStateField()
    country = models.CharField(max_length=150)
class PatientDemographicsForm(forms.ModelForm):
    state = USStateField(widget=USStateSelect)

    class Meta:
        model = Patient
        fields = [
            "first_name", "last_name", "address", "city", "state", "zip_code",
            "email"
        ]
Exemple #13
0
 def __init__(self, *args, **kwargs):
     if 'name' in kwargs:
         self.name = kwargs.pop('name')
     wclass = kwargs.pop('class')
     self.widget = AddressWidget(wclass=wclass)
     fields = (forms.CharField(max_length=100),
               forms.CharField(max_length=50), USStateField(),
               forms.CharField(max_length=5))
     super(AddressField, self).__init__(fields, *args, **kwargs)
Exemple #14
0
class ProfileForm(ModelForm):
    STATE_CHOICES = list(STATE_CHOICES)
    STATE_CHOICES.insert(0, ('', '---------'))
    state = USStateField(
        widget=forms.Select(
            choices=STATE_CHOICES,
            attrs={
                'class': 'form-control',
                'autocomplete': 'address-level1',
            },
        ),
        required=False,
    )
    zip_code = USZipCodeField(
        widget=forms.TextInput(attrs={
            'class': 'form-control',
            'autocomplete': 'postal-code',
        }),
        required=False,
    )

    class Meta:
        model = UserProfile
        fields = (
            'employer',
            'address1',
            'address2',
            'city',
            'state',
            'zip_code',
            'wants_newsletter',
            'barmembership',
            'plaintext_preferred',
        )
        widgets = {
            'employer': forms.TextInput(attrs={
                'class': 'form-control',
                'autocomplete': 'organization',
            }),
            'barmembership': forms.SelectMultiple(
                attrs={'size': '8', 'class': 'form-control'}
            ),
            'address1': forms.TextInput(attrs={
                'class': 'form-control',
                'autocomplete': 'address-line1',
            }),
            'address2': forms.TextInput(attrs={
                'class': 'form-control',
                'autocomplete': 'address-line2',
            }),
            'city': forms.TextInput(attrs={
                'class': 'form-control',
                'autocomplete': 'address-level2',
            }),
    #        'wants_newsletter': forms.TextInput(attrs={'class': 'form-control'}),
    #        'plaintext_preferred': forms.TextInput(attrs={'class': 'form-control'}),
        }
Exemple #15
0
class AddPaymentForm(forms.Form):
    first_name = forms.CharField(required=True)
    last_name = forms.CharField(required=True)
    address1 = forms.CharField(required=True)
    address2 = forms.CharField(required=False)
    city = forms.CharField(required=True)
    state = USStateField(widget=USStateSelect(), required=True)
    country = forms.CharField(required=True)
    zip_code = USZipCodeField(max_length=16, required=True)
Exemple #16
0
class OrganizationForm(forms.ModelForm):
    phone_number = USPhoneNumberField(required=False)
    mailing_address_state = USStateField(widget=USStateSelect,
                                         required=True,
                                         label='State')
    mailing_address_zip = USZipCodeField(required=True, label='Zipcode')

    class Meta:
        model = Organization
        exclude = ['user', 'date_created']

    def __init__(self, *args, **kwargs):
        super(OrganizationForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_id = 'OrganizationForm'
        self.helper.form_class = 'form-horizontal'
        #self.helper.field_class = 'col-lg-4'
        #self.helper.label_class = 'col-lg-2'
        self.helper.form_tag = True

        self.helper.layout = Layout(
            Fieldset('Add Third Party Buyer',
                     HTML("""
						<p>If you are applying on behalf of an organization, family member, client or other third party who will take title, provide their name and contact information.</p>
					"""),
                     Field('name'),
                     Field('email'),
                     Field('phone_number'),
                     css_class='well'),
            Fieldset('Type and Relationship',
                     Field('entity_type'),
                     Field('relationship_to_user'),
                     css_class='well'),
            Fieldset('Mailing Address',
                     Field('mailing_address_line1'),
                     Field('mailing_address_line2'),
                     Field('mailing_address_line3'),
                     Field('mailing_address_city'),
                     Field('mailing_address_state'),
                     Field('mailing_address_zip'),
                     css_class='well'),
            Fieldset(
                'Supporting Documents',
                HTML("""
						<p>Organizations should provide additional identifying and financial documents.</p>
					"""),
                Field('sos_business_entity_report'),
                #Field('irs_determination_letter'),
                #Field('most_recent_financial_statement'),
                #HTML('<div class="form-group"><div class="control-label col-lg-4">Attach a file</div><div id="file-uploader" class="form-control-static col-lg-6">Drop your file here to upload</div>'),
                css_class='well'),
            FormActions(
                #Button('cancel', 'Cancel'),
                Submit('save', 'Save')))
        self.helper.form_method = 'post'
        self.helper.form_action = ''
class Address(models.Model):
    street = models.CharField(max_length=150)
    city = models.CharField(max_length=100)
    state = USStateField()
    zipcode = models.CharField(max_length=5)

    person = models.OneToOneField(Person, on_delete=models.CASCADE, null=True)

    def __unicode__(self):
        return self.street
Exemple #18
0
class USPostalAddressForm(PostalAddressForm):
    line1 = forms.CharField(label=_(u"Street"), max_length=50)
    line2 = forms.CharField(label=_(u"Area"), required=False, max_length=100)
    city = forms.CharField(label=_(u"City"), max_length=50)
    state = USStateField(label=_(u"US State"), widget=USStateSelect)
    code = USZipCodeField(label=_(u"Zip Code"))

    def __init__(self, *args, **kwargs):
        super(USPostalAddressForm, self).__init__(*args, **kwargs)
        self.fields['country'].initial = "US"
Exemple #19
0
class AddressForm(forms.Form):
    address_street1 = forms.CharField(label='Address', max_length=90)
    address_street2 = forms.CharField(label='Address line 2', required=False)
    address_city = forms.CharField(label='City', max_length=90)

    address_state = USStateField(
        label="State",
        initial="MN",
        widget=USStateSelect(attrs={'class': 'custom-select'}))

    address_zip = USZipCodeField(label='Zip Code')
Exemple #20
0
class SignUpForm(UserCreationForm):

    first_name = forms.CharField(max_length=40,
                                 required=True,
                                 help_text='Required')
    last_name = forms.CharField(max_length=40,
                                required=True,
                                help_text='Required')
    email = forms.EmailField(max_length=254,
                             required=True,
                             help_text='Required')
    address = forms.CharField(max_length=254,
                              required=True,
                              help_text='Required')
    state = USStateField(required=True,
                         widget=USStateSelect(),
                         help_text='Required')
    city = forms.CharField(max_length=85, required=True, help_text='Required')
    zip_code = USZipCodeField(required=True, help_text='Required')

    class Meta:
        model = User
        fields = ('username', 'password1', 'password2', 'first_name',
                  'last_name', 'email')

    def clean_email(self):
        email = self.cleaned_data['email']
        if User.objects.filter(email=email).count() > 0:
            raise forms.ValidationError(
                "A user with that email already exists.")
        return email

    def clean_first_name(self):
        first_name = self.cleaned_data['first_name']
        has_name_chars(first_name)
        return first_name

    def clean_last_name(self):
        last_name = self.cleaned_data['last_name']
        has_name_chars(last_name)
        return last_name

    def clean_city(self):
        city = self.cleaned_data['city']
        has_name_chars(city)
        return city

    def clean_address(self):
        address = self.cleaned_data['address']
        for char in address:
            if char in "!@$%^&*()~,./?;:":
                raise forms.ValidationError(
                    'You included an in Invalid Symbol in the address field')
        return address
Exemple #21
0
class PractProfileForm(forms.ModelForm):
    class Meta:
        model = Practitioner
        exclude = ('account', 'available', 'verified', 'created', 'updated_at')

    phone = forms.IntegerField(required=False)
    accreditation = forms.CharField(required=False)
    license = forms.CharField(required=False)
    state = USStateField(required=False)
    zipcode = USZipCodeField(required=False)
    school = forms.CharField(required=False)
    about = forms.CharField(required=False, widget=forms.Textarea)
Exemple #22
0
    def __init__(self, *args, **kwargs):
        """Constructor for AltLocationField.

        Setting up and providing fields list to parent`s init.

        """
        list_fields = [
            forms.CharField(max_length=255),
            forms.CharField(max_length=255),
            USStateField(),
            USZipCodeField()
        ]
        super().__init__(list_fields, *args, **kwargs)
class PreapprovedAddressGenerateForm(ModelForm):
    state = USStateField(
        widget=Select(attrs={'class': 'form-control'}, choices=US_STATES))

    class Meta:
        model = PreapprovedAddress
        fields = ['addr1', 'city', 'state', 'zip_code', 'note']
        widgets = {
            'addr1': TextInput(attrs={'class': 'form-control'}),
            'city': TextInput(attrs={'class': 'form-control'}),
            'zip_code': TextInput(attrs={'class': 'form-control'}),
            'note': TextInput(attrs={'class': 'form-control'}),
        }
Exemple #24
0
class ArtistInfoForm(forms.ModelForm):
    state = USStateField(widget=floppyforms.Select(choices=STATE_CHOICES_WITH_EMPTY), required=False)
    country = floppyforms.ChoiceField(choices=COUNTRIES_WITH_EMPTY)
    payout_method = forms.ChoiceField(
        choices=User.PAYOUT_CHOICES,
        widget=forms.RadioSelect()
    )
    paypal_email_again = floppyforms.EmailField(required=False)

    class Meta:
        fields = ('first_name', 'last_name', 'address_1', 'address_2', 'city', 'zip', 'state', 'country',
                  'payout_method', 'paypal_email', 'paypal_email_again', 'taxpayer_id')
        model = User

    def __init__(self, *args, **kwargs):
        super(ArtistInfoForm, self).__init__(*args, **kwargs)
        for field in self.Meta.fields:
            self.fields[field].widget.attrs['class'] = 'form-control'
        self.fields['state'].widget.attrs['class'] = 'form-control selectpicker'
        self.fields['country'].widget.attrs['class'] = 'form-control selectpicker'
        # default to US if nothing is set, initial not working as the form is bound
        if not self.initial['country']:
            self.initial['country'] = 'US'

    def clean(self):
        cleaned_data = super(ArtistInfoForm, self).clean()
        if cleaned_data.get('payout_method') == User.PAYOUT_CHOICES.PayPal:
            msg = u"This field is required."
            if not cleaned_data.get('paypal_email'):
                self.add_error('paypal_email', msg)
            if not cleaned_data.get('paypal_email_again'):
                self.add_error('paypal_email_again', msg)
            if cleaned_data.get('paypal_email') != cleaned_data.get('paypal_email_again'):
                raise forms.ValidationError(u'The two email addresses must match.')

        if cleaned_data.get('country') == 'US':
            state = cleaned_data.get('state')
            if not state:
                self.add_error('state', 'You must select a valid US state or territory.')
            taxpayer_id = cleaned_data.get('taxpayer_id')
            if not taxpayer_id:
                self.add_error('taxpayer_id', 'You must enter a valid taxpayer ID as a US citizen.')
            self.fields['state'].clean(state)
            self.fields['taxpayer_id'].clean(state)
        else:
            cleaned_data['state'] = ''
            cleaned_data['taxpayer_id'] = ''
        return cleaned_data
Exemple #25
0
class CheckoutForm(forms.Form):
    first_name = forms.CharField()
    last_name = forms.CharField()
    street_address_1 = forms.CharField(widget=forms.TextInput(
        attrs={
            'class': "form-control",
            'placeholder': "1234 Main St."
        }))
    apartment = forms.CharField(
        required=False,
        widget=forms.TextInput(attrs={
            'class': "form-control",
            'placeholder': "Apartment or suite"
        }))
    country = forms.ChoiceField(choices=COUNTRY_CHOICES,
                                widget=forms.Select(
                                    attrs={
                                        'onChange': 'countrySelect(this)',
                                        'class': 'custom-select d-block w-100',
                                    }))
    province = CAProvinceField(widget=CAProvinceSelect(
        attrs={
            'type': 'hidden',
            'class': 'custom-select d-block w-100',
        }))
    ca_postal_code = CAPostalCodeField(
        required=False,
        widget=forms.TextInput(attrs={
            'class': 'custom-select d-block w-100',
        }))
    us_state = USStateField(
        widget=USStateSelect(attrs={
            'class': 'custom-select d-block w-100',
        }),
        required=False)
    us_zip_code = USZipCodeField(
        required=False,
        widget=forms.TextInput(attrs={
            'class': 'custom-select d-block w-100',
        }))
    same_billing_address = forms.BooleanField(widget=forms.CheckboxInput(),
                                              required=False)
    save_info = forms.BooleanField(widget=forms.CheckboxInput(),
                                   required=False)
    payment_option = forms.ChoiceField(choices=PAYMENT_CHOICE,
                                       widget=forms.RadioSelect())
Exemple #26
0
class ContactForm(forms.Form):
    address_street1 = forms.CharField(label='Address', max_length=90)
    address_street2 = forms.CharField(label='Address line 2', required=False)
    address_city = forms.CharField(label='City', max_length=90)
    address_state = USStateField(
        label="State",
        initial="MN",
        widget=USStateSelect(attrs={'class': 'custom-select'}))
    address_zip = USZipCodeField(label='Zip Code')

    phone_number = PhoneNumberField(label="Phone", region='US')
    phone_can_receive_sms = forms.BooleanField(
        label='This phone can receive SMS messages.', required=False)

    emergency_contact_name = forms.CharField(label='Emergency Contact',
                                             max_length=90)
    emergency_contact_phone = PhoneNumberField(region='US')
class AddressForm(ApplicationForm):
    class Meta:
        model = Application
        fields = ['addr1', 'addr2', 'city', 'state', 'zip_code']
        widgets = {
            'addr1': forms.TextInput(attrs={'class': 'form-control'}),
            'addr2': forms.TextInput(attrs={'class': 'form-control'}),
            'city': forms.TextInput(attrs={'class': 'form-control'}),
            'zip_code': forms.TextInput(attrs={'class': 'form-control'}),
        }

    # Hack to deal with issue that UsStateSelect does not contain
    # a default value (https://stackoverflow.com/questions/1830894).
    state_choices = get_states_in('en')
    state_choices.insert(0, ('', _('select_one')))
    state = USStateField(widget=forms.Select(attrs={'class': 'form-control'},
                                             choices=state_choices))
Exemple #28
0
class CheckoutForm(forms.Form):
    name = forms.CharField(required=True)
    email = forms.EmailField(required=True)
    street_1 = forms.CharField(required=False, label="Street")
    city = forms.CharField(required=False)
    state = USStateField(widget=USStateSelect)
    zip = forms.IntegerField(required=False)

    def clean(self):
        data = self.cleaned_data
        if data["street_1"] == "":
            self.add_error("street_1", "Please complete for delivery")
        elif data["city"] == "":
            self.add_error("city", "Please complete for delivery")
        elif data["zip"] == "":
            self.add_error("zip", "Please complete for delivery")

        return data
Exemple #29
0
    def __init__(self, *args, **kwargs):
        user = kwargs.pop('user')

        super(SearchForm, self).__init__(*args, **kwargs)

        if user.is_superuser:
            states = list(STATE_CHOICES)
        else:
            user_states = [org.state for org in user.organizations.all()]
            states = []

            for state in list(STATE_CHOICES):
                if state[0] in user_states:
                    states.append(state)

        states.insert(0, ('', 'Select ...'))

        self.fields['state'] = USStateField(
            required=False, widget=forms.Select(choices=states), label='State')
Exemple #30
0
    def __init__(self, *args, **kwargs):
        instance = kwargs.pop('instance', None)
        initial = kwargs.pop('initial', {})
        self.user = kwargs.pop('user')

        kwargs['instance'] = instance
        kwargs['initial'] = initial

        super(StaffForm, self).__init__(*args, **kwargs)

        account_types = None
        if self.user.is_superuser:
            account_types = AccountType.objects.all()
        else:
            account_types = AccountType.objects.filter(
                permission_hierarchy__gt=self.user.account_type.
                permission_hierarchy)

        organizations = None
        if self.user.is_superuser:
            organizations = Organization.objects.all()
        else:
            organizations = self.user.organizations.all()

        if self.user.is_superuser:
            states = list(STATE_CHOICES)
        else:
            user_states = [org.state for org in self.user.organizations.all()]
            states = []

            for state in list(STATE_CHOICES):
                if state[0] in user_states:
                    states.append(state)

        if len(states) > 1:
            states.insert(0, ('', 'Select ...'))

        self.fields['state'] = USStateField(
            required=True, widget=forms.Select(choices=states), label='State')
        self.fields['account_type'] = forms.ModelChoiceField(
            queryset=account_types)
        self.fields['organizations'] = forms.ModelMultipleChoiceField(
            queryset=organizations)