예제 #1
0
class CustomCheckoutForm(CheckoutForm):
    class Meta:
        fields = [
            'email', 'shipping_same_as_billing', 'personal_information_consent'
        ]
        fields.extend('billing_%s' % f for f in CustomOrder.ADDRESS_FIELDS)
        fields.extend('shipping_%s' % f for f in CustomOrder.ADDRESS_FIELDS)
        model = CustomOrder

    billing_address = forms.CharField(label=_('address'), required=True)
    shipping_address = forms.CharField(label=_('address'), required=False)
    # override it so it will be required
    billing_country = LazyTypedChoiceField(label=_('Country'),
                                           choices=Country.choices(),
                                           required=True)
    shipping_country = LazyTypedChoiceField(label=_('Country'),
                                            choices=Country.choices(),
                                            required=False)
    personal_information_consent = forms.BooleanField(label=_(
        '<a href="/personal-information-protection/" target="_blank">I agree to provide my personal information</a>.'
    ),
                                                      required=True)

    def clean(self):
        data = super(CustomCheckoutForm, self).clean()

        if not data.get('shipping_same_as_billing'):
            for f in self.REQUIRED_ADDRESS_FIELDS:
                field = 'shipping_%s' % f
                if not data.get(field):
                    self._errors[field] = self.error_class(
                        [_('This field is required.')])

        return data
예제 #2
0
class RegisterForm(forms.Form):
    email = forms.EmailField(label=_('Email'),
                             widget=forms.EmailInput(),
                             required=True)
    username = forms.CharField(label=_('Username'),
                               required=True)
    firstname = forms.CharField(label=_('Firstname'),
                                required=True)
    lastname = forms.CharField(label=_('Lastname'),
                               required=True)
    password = forms.CharField(label=_('Password'),
                               widget=forms.PasswordInput(),
                               required=True)
    address = forms.CharField(label=_('Address'),
                              required=True)
    additional_info = forms.CharField(label=_('Additional Info'))
    country = LazyTypedChoiceField(label=_('Country'),
                                   choices=countries)
    citizen = LazyTypedChoiceField(label=_('Citizenship'),
                                   choices=countries)

    def __init__(self, *args, **kwargs):
        super(RegisterForm, self).__init__(*args, **kwargs)
        self.email = None
        self.username = None
        self.password = None
        self.firstname = None
        self.lastname = None
        self.address = None
        self.additional_info = None

    def clean(self):
        return self.cleaned_data
예제 #3
0
class CustomCheckoutForm(CheckoutForm):
    class Meta:
        fields = ['email', 'shipping_same_as_billing']
        fields.extend('billing_%s' % f for f in CustomOrder.ADDRESS_FIELDS)
        fields.extend('shipping_%s' % f for f in CustomOrder.ADDRESS_FIELDS)
        model = CustomOrder

    billing_address = forms.CharField(label=_('address'), required=True)
    shipping_address = forms.CharField(label=_('address'), required=False)
    # override it so it will be required
    billing_country = LazyTypedChoiceField(label=_('Country'),
                                           choices=Country.choices(),
                                           required=True)
    shipping_country = LazyTypedChoiceField(label=_('Country'),
                                            choices=Country.choices(),
                                            required=False)

    def clean(self):
        data = super(CustomCheckoutForm, self).clean()

        if not data.get('shipping_same_as_billing'):
            for f in self.REQUIRED_ADDRESS_FIELDS:
                field = 'shipping_%s' % f
                if not data.get(field):
                    self._errors[field] = self.error_class(
                        [_('This field is required.')])

        return data
예제 #4
0
class RemoteWorkshopForm(forms.Form):
    date = ApproximateDateFormField(
        widget=forms.TextInput(attrs={'class': 'compact-input'}))
    city = forms.CharField(
        required=True,
        max_length=200,
        widget=forms.TextInput(attrs={'class': 'compact-input'}))
    country = LazyTypedChoiceField(
        choices=[(None, _('Choose country'))] + list(countries))
    sponsorship = forms.CharField(
        widget=forms.Textarea(attrs={'class': 'compact-input'}))
    coaches = forms.CharField(
        widget=forms.Textarea(attrs={'class': 'compact-input'}))
    tools = forms.CharField(
        widget=forms.Textarea(attrs={'class': 'compact-input'})
    )
    diversity = forms.CharField(
        widget=forms.Textarea(attrs={'class': 'compact-input'})
    )
    additional = forms.CharField(
        widget=forms.Textarea(attrs={'class': 'compact-input'})
    )

    def clean_date(self):
        date = self.cleaned_data.get('date')
        validate_approximatedate(date)
        # Check if the event is in the future
        validate_future_date(date)
        # Check if date is 3 months away
        validate_event_date(date)
        return date

    def get_data_for_saving(self):
        return self.cleaned_data
예제 #5
0
class UserApplyStep1Form(forms.Form):
    first_name = forms.CharField(max_length=20)
    last_name = forms.CharField(max_length=20)
    email = forms.EmailField(max_length=50)
    citizenship = LazyTypedChoiceField(choices=countries)
    skype_id = forms.CharField(label='Skype ID', max_length=20)
    timezone = forms.ChoiceField(choices=TIMEZONE_CHOICES)
예제 #6
0
class UserProfileForm(forms.ModelForm):
    phone = forms.CharField(max_length=40,
                            required=False,
                            validators=[phone_regex_validator])
    country = LazyTypedChoiceField(choices=countries,
                                   widget=CountrySelectWidget)
    published = forms.BooleanField(required=False)

    def __init__(self, *args, **kwargs):
        super(UserProfileForm, self).__init__(*args, **kwargs)
        # Set the initial values
        self.fields['phone'].initial = kwargs['instance'].profile.phone
        self.fields['country'].initial = kwargs['instance'].profile.country
        self.fields['published'].initial = kwargs['instance'].profile.published

    def save(self, commit=True):
        """
        Save the User instance with its profile info.
        """
        # Save the user
        user = self.instance
        user.save()

        # By this point the User's UserProfile was created. Update it.
        user.profile.phone = self.cleaned_data['phone']
        user.profile.country = self.cleaned_data['country']
        user.profile.published = self.cleaned_data['published']
        user.profile.save()

        return user

    class Meta:
        model = User
        fields = ('first_name', 'last_name', 'email')
예제 #7
0
class PublisherForm(forms.Form):
    name = forms.CharField(label="Publisher's name", max_length=30)
    address = forms.CharField(label="Address", max_length=50)
    country = LazyTypedChoiceField(choices=countries)
    state = forms.CharField(max_length=20)
    city = forms.CharField(max_length=30)
    website = forms.URLField()
예제 #8
0
class CountryForm(forms.Form):
    """Country selection form."""

    country = LazyTypedChoiceField(label=pgettext_lazy(
        "Country form field label", "Country"),
                                   choices=[])

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        available_countries = {(country.code, country.name)
                               for shipping_zone in ShippingZone.objects.all()
                               for country in shipping_zone.countries}
        self.fields["country"].choices = sorted(available_countries,
                                                key=lambda choice: choice[1])

    def get_shipping_price_estimate(self, checkout, discounts):
        """Return a shipping price range for given order for the selected
        country.
        """
        from .utils import get_shipping_price_estimate

        country = self.cleaned_data["country"]
        if isinstance(country, str):
            country = Country(country)
        return get_shipping_price_estimate(checkout, discounts, country)
예제 #9
0
class ComplaintForm(forms.Form):
    title = forms.CharField(max_length=100)
    company = forms.CharField(max_length=100)
    person = forms.CharField(max_length=100)
    city = forms.CharField(max_length=100)
    country = LazyTypedChoiceField(choices=countries)
    experience = forms.CharField(max_length=10000, widget=forms.Textarea)

    def __init__(self, *args, **kwargs):
        super(ComplaintForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_class = 'form-horizontal'
        self.helper.form_show_labels = False

        # self.helper.layout = Layout(
        # 	Field('title', css_class='input-sm', placeholder="Title"),
        # 	Field('company', css_class='input-sm', placeholder="Company"),
        # 	Field('person', css_class='input-sm', placeholder="Relevant Person"),
        # 	Field('city', css_class='input-sm', placeholder="City"),
        # 	Field('country', css_class='input-sm'),
        # 	Field('experience', css_class='input-sm', placeholder="Write your experience here."),
        #     ButtonHolder(
        #         Submit('submit', 'Submit', css_class='btn btn-lg btn-primary')
        #     )
        # )
        self.helper.label_class = 'col-lg-2'
        self.helper.field_class = 'col-lg-8'

        self.helper.layout = Layout(
            'title', 'company', 'person', 'city', 'country', 'experience',
            ButtonHolder(
                Submit('submit', 'Submit',
                       css_class='btn btn-lg btn-primary')))
예제 #10
0
파일: forms.py 프로젝트: guegue/forocacao
class SignupForm(forms.Form):
    current_event = Event.objects.filter(status='frontpage')[0]
    type = forms.ModelChoiceField(queryset=AttendeeType.objects.filter(id__in=current_event.types.all()),label=_('Type'))
    first_name = forms.CharField(max_length=30, label=_('First name'))
    last_name = forms.CharField(max_length=30, label=_('Last name'))
    second_lastname = forms.CharField(max_length=30, label=_('Second last name'),required=False)
    document = forms.CharField(max_length=60, label=_('ID Card'),required=False)
    country = LazyTypedChoiceField(choices=countries, label=_('Country'))
    profession = forms.ModelChoiceField(queryset=Profession.objects.filter(id__in=current_event.professions.all()),label=_('Profession'))
    phone = forms.CharField(max_length=50, label=_('Phone'),required=True)
    sponsored = forms.BooleanField(label=_('Sponsored'),required=False)
    sponsor = forms.ModelChoiceField(queryset=Sponsor.objects.filter(id__in=current_event.sponsors.all()),label=_('Sponsor'), required=False)

    def signup(self, request, user):
        user.first_name = self.cleaned_data['first_name']
        user.last_name = self.cleaned_data['last_name']
        user.second_lastname = self.cleaned_data['second_lastname']
        user.document = self.cleaned_data['document']
        user.phone = self.cleaned_data['phone']
        user.country = self.cleaned_data['country']
        user.profession = self.cleaned_data['profession']
        user.type = self.cleaned_data['type']
        user.sponsored = self.cleaned_data['sponsored']
        user.sponsor = self.cleaned_data['sponsor']
        user.event = self.current_event
        user.save()
예제 #11
0
class CountryForm(forms.Form):

    country = LazyTypedChoiceField(choices=countries)

    def get_shipment_options(self):
        code = self.cleaned_data['country']
        return get_shipment_options(code)
예제 #12
0
class SignupForm(forms.Form):
    name = forms.CharField(
        max_length=30,
        label=_('Name'),
        widget=forms.TextInput(attrs={
            'placeholder': _('John Smith'),
            'autofocus': 'autofocus'
        }))
    GENDER_CHOICES = (
        ('M', _('Male')),
        ('F', _('Female')),
        ('O', _('Other')),
    )
    gender = forms.ChoiceField(label=_('Gender'), choices=GENDER_CHOICES)
    birthday = forms.DateField(
        label=_('Birthday'),
        widget=extras.SelectDateWidget(years=range(1910, 2017)))
    place_of_origin = LazyTypedChoiceField(label=_('Country/Region of Origin'),
                                           choices=countries)

    def signup(self, request, user):
        user.name = self.cleaned_data['name']
        user.gender = self.cleaned_data['gender']
        user.birthday = self.cleaned_data['birthday']
        user.place_of_origin = self.cleaned_data['place_of_origin']
        user.save()
예제 #13
0
파일: forms.py 프로젝트: lttsh/LemonPie
class ActivityForm(EntryForm):
    name = forms.CharField(max_length=50)
    location_city = forms.CharField(max_length=50)
    location_country = LazyTypedChoiceField(choices=countries)
    #TODO: Add a widget for Date selection
    date_begin = forms.DateField()
    date_end = forms.DateField()
    description = forms.CharField(widget=forms.Textarea)
class ProfileForm(forms.Form):
    username = forms.CharField(
        max_length=128,
        label='Username',
        widget=forms.TextInput(attrs={'class': 'form-control'}))
    country = LazyTypedChoiceField(choices=countries,
                                   label='Country',
                                   required=False)
    gender = forms.ChoiceField(choices=gender_choices,
                               label='Gender',
                               required=False)
    age = forms.IntegerField(max_value=150,
                             min_value=0,
                             label='Age',
                             required=False)
    street1 = forms.CharField(max_length=512, label='Street1', required=False)
    street2 = forms.CharField(max_length=512, label='Street2', required=False)
    suburb = forms.CharField(max_length=128, label='Suburb', required=False)
    state = forms.CharField(max_length=128, label='State', required=False)
    postalCode = forms.CharField(max_length=128,
                                 label='Postal Code',
                                 required=False)
    phone = forms.CharField(max_length=24,
                            label='Phone number',
                            required=False)

    painting = forms.BooleanField(
        label='painting',
        required=False,
        widget=forms.CheckboxInput(attrs={'class': 'form-interest'}))
    sculpture = forms.BooleanField(
        label='sculpture',
        required=False,
        widget=forms.CheckboxInput(attrs={'class': 'form-interest'}))
    photography = forms.BooleanField(
        label='photography',
        required=False,
        widget=forms.CheckboxInput(attrs={'class': 'form-interest'}))
    calligraphy = forms.BooleanField(
        label='calligraphy',
        required=False,
        widget=forms.CheckboxInput(attrs={'class': 'form-interest'}))
    printmaking = forms.BooleanField(
        label='printmaking',
        required=False,
        widget=forms.CheckboxInput(attrs={'class': 'form-interest'}))
    art_and_craft = forms.BooleanField(
        label='art_and_craft',
        required=False,
        widget=forms.CheckboxInput(attrs={'class': 'form-interest'}))
    seal_cutting = forms.BooleanField(
        label='seal_cutting',
        required=False,
        widget=forms.CheckboxInput(attrs={'class': 'form-interest'}))
    art_design = forms.BooleanField(
        label='art_design',
        required=False,
        widget=forms.CheckboxInput(attrs={'class': 'form-interest'}))
예제 #15
0
class ModuloLocalizzatoreItalia(forms.Form):
    indirizzo = forms.CharField(label='Indirizzo',
                                required=False,
                                help_text="es. Via Rosmini, 42. (Opzionale)")
    comune = forms.CharField(help_text="es. Cinisello Balsamo.")
    provincia = forms.CharField(required=True,
                                min_length=3,
                                help_text="es. Milano. (per intero)")
    stato = LazyTypedChoiceField(choices=(('IT', 'Italia'), ), initial="IT")
예제 #16
0
class BillForm(forms.Form):
    address = forms.CharField()
    current_city = forms.CharField(required=False)
    country = LazyTypedChoiceField(choices=countries)

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        for myField in self.fields:
            self.fields[myField].widget.attrs['class'] = 'form-control'
예제 #17
0
class MassEditForm(forms.Form):
    gender = EnumField(Gender).formfield(default=Gender.UNDISCLOSED, label=_('Gender'), required=False)
    merchant_notes = forms.CharField(label=_('Merchant Notes'), widget=forms.Textarea, required=False)
    www = forms.URLField(required=False, label=_("Website URL"))
    account_manager = forms.ModelChoiceField(PersonContact.objects.all(), label=_("Account Manager"), required=False)
    tax_number = forms.CharField(label=_("Company: Tax Number"), max_length=32, required=False)
    members = forms.ModelMultipleChoiceField(Contact.objects.all(), label=_("Company: Members"), required=False)
    language = LazyTypedChoiceField(
        choices=[("", _("Select Language"))] + list(countries), label=_('Language'), required=False)
예제 #18
0
class CountryForm(forms.Form):

    country = LazyTypedChoiceField(
        label=pgettext_lazy('Country form field label', 'Country'),
        choices=countries)

    def get_shipment_options(self):
        code = self.cleaned_data['country']
        return get_shipment_options(code)
예제 #19
0
파일: forms.py 프로젝트: sourav47/saleor
class CountryForm(forms.Form):
    """Country selection form."""

    country = LazyTypedChoiceField(label=pgettext_lazy(
        'Country form field label', 'Country'),
                                   choices=countries)

    def get_shipment_options(self):
        """Return a list of shipping methods for the selected country."""
        code = self.cleaned_data['country']
        return get_shipment_options(code)
예제 #20
0
class UserApplyStep1Form(forms.Form):
    first_name = forms.CharField(max_length=20)
    last_name = forms.CharField(max_length=20)
    email = forms.EmailField(max_length=50)
    citizenship = LazyTypedChoiceField(choices=countries)
    skype_id = forms.CharField(label='Skype ID', max_length=20)
    timezone = forms.ChoiceField(choices=TIMEZONE_CHOICES)
    birth_year = forms.IntegerField(min_value=1950, max_value=2000)
    gender = forms.TypedChoiceField(choices=GENDER_CHOICES)
    education = forms.TypedChoiceField(choices=EDUCATION_CHOICES)
    education_major = forms.CharField(max_length=50)
예제 #21
0
파일: forms.py 프로젝트: aldwyn-acn/effigia
class UserProfileForm(forms.ModelForm):
    class Meta:
        model = get_user_model()
        fields = ['username', 'first_name', 'last_name', 'email']
        widgets = {'country': CountrySelectWidget(
            layout=('{widget}<img class="country-select-flag" '
                    'style="margin: 6px 4px; position: absolute;" src="{flag_url}">'))
        }

    avatar = forms.FileField(required=False)
    bio = forms.CharField(widget=forms.Textarea, required=False)
    country = LazyTypedChoiceField(choices=countries)
예제 #22
0
class SoftwareOrderForm(forms.Form):

    billing_company = forms.CharField(required=False, label='Company')
    billing_first_name = forms.CharField(required=True, label='First name')
    billing_last_name = forms.CharField(required=True, label='Last name')
    billing_address_1 = forms.CharField(required=True, label='Address Line 1')
    billing_address_2 = forms.CharField(required=False, label='Address Line 2')
    billing_city = forms.CharField(required=True, label='City')
    billing_postcode = forms.CharField(required=True, label='Post Code')
    billing_country_code = LazyTypedChoiceField(choices=countries,
                                                label='Country')
    billing_country_area = forms.CharField(required=False, label='Area')
    pay_method = forms.CharField(widget=forms.HiddenInput(), required=True)
예제 #23
0
class CandidateRegister(forms.ModelForm):

    name = forms.CharField(max_length=100, required=True)
    phone = forms.CharField(max_length=12, required=True)
    email = forms.EmailField(max_length=100, required=True)
    cv = forms.FileField()
    gender = forms.ChoiceField(choices=(('', ''), ('male', 'Male'),
                                        ('female', 'Female')))
    country = LazyTypedChoiceField(choices=countries)

    class Meta:
        model = candidate
        fields = ('name', 'phone', 'email', 'cv', 'gender', 'country')
class RegisterForm(forms.Form):
    username = forms.CharField(
        max_length=128,
        label='Username',
        widget=forms.TextInput(attrs={'class': 'form-control'}))
    password1 = forms.CharField(
        max_length=256,
        label='Password',
        widget=forms.PasswordInput(attrs={'class': 'form-control'}))
    password2 = forms.CharField(
        max_length=256,
        label='Confirm password',
        widget=forms.PasswordInput(attrs={'class': 'form-control'}))
    email = forms.EmailField(
        label='Email',
        widget=forms.EmailInput(attrs={'class': 'form-control'}))

    realName = forms.CharField(max_length=128,
                               label='Your real name',
                               required=False)

    # referee = forms.CharField(max_length=128, label='Referee\'s name',
    #                           widget=forms.TextInput(attrs={'class': 'form-control'}))

    refEmail = forms.EmailField(
        label='Referee\'s Email',
        required=False,
        widget=forms.EmailInput(attrs={'class': 'form-control'}))
    country = LazyTypedChoiceField(choices=countries,
                                   label='Country',
                                   required=False)
    # artist = forms.ChoiceField(choices=artist_choices, label='artist')
    captcha = CaptchaField(label="Captcha")
    gender = forms.ChoiceField(choices=gender_choices,
                               label='Gender',
                               required=False)
    age = forms.IntegerField(max_value=150,
                             min_value=0,
                             label='Age',
                             required=False)
    street1 = forms.CharField(max_length=512, label='Street1', required=False)
    street2 = forms.CharField(max_length=512, label='Street2', required=False)
    suburb = forms.CharField(max_length=128, label='Suburb', required=False)
    state = forms.CharField(max_length=128, label='State', required=False)
    postalCode = forms.CharField(max_length=128,
                                 label='Postal Code',
                                 required=False)
    phone = forms.CharField(max_length=24,
                            label='Phone number',
                            required=False)
예제 #25
0
파일: event.py 프로젝트: HoiJean/pretix
class TaxRuleLineForm(forms.Form):
    country = LazyTypedChoiceField(choices=CountriesAndEU(), required=False)
    address_type = forms.ChoiceField(choices=[
        ('', _('Any customer')),
        ('individual', _('Individual')),
        ('business', _('Business')),
        ('business_vat_id', _('Business with valid VAT ID')),
    ],
                                     required=False)
    action = forms.ChoiceField(choices=[
        ('vat', _('Charge VAT')),
        ('reverse', _('Reverse charge')),
        ('no', _('No VAT')),
    ], )
예제 #26
0
class CountryForm(forms.Form):
    """Country selection form."""

    country = LazyTypedChoiceField(label=pgettext_lazy(
        'Country form field label', 'Country'),
                                   choices=countries)

    def __init__(self, *args, **kwargs):
        self.taxes = kwargs.pop('taxes', {})
        super().__init__(*args, **kwargs)

    def get_shipment_options(self):
        """Return a list of shipping methods for the selected country."""
        code = self.cleaned_data['country']
        return get_shipment_options(code, self.taxes)
예제 #27
0
class RegistrationForm2(forms.Form):

    first_name = forms.CharField(
        max_length=30,
        label=_('First name'),
        required=False,
        widget=forms.TextInput(attrs={'placeholder': _('first name')}))

    last_name = forms.CharField(
        max_length=30,
        label=_('Last name'),
        required=False,
        widget=forms.TextInput(attrs={'placeholder': _('last name')}))

    country = LazyTypedChoiceField(choices=countries)

    newsletter = forms.BooleanField(label=_("Register to the newsletter"),
                                    required=False)
예제 #28
0
class BillingAddressForm(forms.Form):
    name = forms.CharField(required=True,
                           widget=forms.TextInput(attrs={
                               "id": "billing-name",
                               "class": "address-field"
                           }))
    address_line1 = forms.CharField(required=True,
                                    widget=forms.TextInput(
                                        attrs={
                                            "onFocus": "geolocate()",
                                            "id": "billing-street",
                                            "class": "address-field"
                                        }))
    address_line2 = forms.CharField(
        required=False,
        widget=forms.TextInput(attrs={
            'class': 'input-field col mods',
            'id': 'billing-apt'
        }))
    address_city = forms.CharField(
        required=True,
        widget=forms.TextInput(
            attrs={
                'class': 'input-field col mods field address-field',
                'id': 'billing-city',
                'required': "true"
            }))
    address_state = forms.CharField(
        required=True,
        widget=forms.TextInput(
            attrs={
                'class': 'input-field col mods field address-field',
                'id': 'billing-state',
                'required': "true"
            }))
    address_zip = forms.IntegerField(
        required=True,
        widget=forms.TextInput(
            attrs={
                'class': 'input-field col mods address-field',
                'id': 'billing-zip',
                'required': "true"
            }))
    address_country = LazyTypedChoiceField(choices=countries)
예제 #29
0
class ProfileForm(forms.Form):
    MAX_PHOTO_SIZE = 2 * 1024 * 1024
    PHOTO_MAX_WIDTH = 1024
    PHOTO_MAX_HEIGH = 1024
    first_name = fields.CharField(max_length=30, required=False)
    last_name = fields.CharField(max_length=30, required=False)
    photo = forms.ImageField(required=False,
                             label='Profile image (recommended size: 160x160)',
                             widget=forms.FileInput)
    bio = fields.CharField(widget=forms.Textarea,
                           max_length=PROFILE_BIO_MAX_LEN,
                           required=False,
                           label='Bio (a short description of yourself)',
                           help_text='{} characters max.'.format(PROFILE_BIO_MAX_LEN))
    country = LazyTypedChoiceField(choices=[('', ''), ] + list(countries),
                                   required=False,
                                   label='Where do you live?')

    def clean_photo(self):
        photo = self.cleaned_data.get('photo', False)
        if photo and photo.image and photo.file:
            if photo.image.size[0] > self.PHOTO_MAX_WIDTH:
                raise ValidationError("Image width too large ( max %s px )" %
                                      self.PHOTO_MAX_WIDTH)
            if photo.image.size[1] > self.PHOTO_MAX_HEIGH:
                raise ValidationError("Image height too large ( max %s px )" %
                                      self.PHOTO_MAX_HEIGH)
            file_size = len(photo)
            if file_size > self.MAX_PHOTO_SIZE:
                raise ValidationError("Image size is too large ( max %s  )" %
                                      filesizeformat(self.PHOTO_MAX_HEIGH))
            if file_size < 1:
                raise ValidationError("Image is empty" %
                                      filesizeformat(self.PHOTO_MAX_HEIGH))
            return photo

    def clean_bio(self):
        import html.parser
        html_parser = html.parser.HTMLParser()

        bio = self.cleaned_data.get('bio', '')
        bio = clean(bio, tags=[], strip=True, strip_comments=True)
        return html_parser.unescape(bio)
예제 #30
0
파일: forms.py 프로젝트: MKurugollu/RateMy
class UserProfileForm(forms.ModelForm):
    first_name = forms.CharField(required=True)
    last_name = forms.CharField(required=True)

    picture = forms.ImageField(required = True)

    bio = forms.CharField(required=False)

    age = forms.IntegerField(required=True)

    fb = forms.URLField(required=False)
    instagram = forms.URLField(required=False)
    twitter = forms.URLField(required=False)

    country = LazyTypedChoiceField(choices=countries)

    class Meta:
        model = UserProfile
        exclude = ('user', )