Python django.forms 模块,FloatField() 实例源码

我们从Python开源项目中,提取了以下38个代码示例,用于说明如何使用django.forms.FloatField()

项目:django-rest-search    作者:wemap    | 项目源码 | 文件源码
def get_form_field_schema(field):
    """
    Returns the coreapi schema for the given form field.
    """
    title = force_text(field.label) if field.label else ''
    description = force_text(field.help_text) if field.help_text else ''

    if isinstance(field, forms.BooleanField):
        field_class = coreschema.Boolean
    elif isinstance(field, forms.FloatField):
        field_class = coreschema.Number
    elif isinstance(field, (forms.IntegerField, forms.ModelChoiceField)):
        field_class = coreschema.Integer
    else:
        field_class = coreschema.String

    return field_class(description=description, title=title)
项目:heltour    作者:cyanfish    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        reg = kwargs.pop('registration')
        super(ApproveRegistrationForm, self).__init__(*args, **kwargs)

        workflow = ApproveRegistrationWorkflow(reg)

        self.fields['send_confirm_email'].initial = workflow.default_send_confirm_email
        self.fields['invite_to_slack'].initial = workflow.default_invite_to_slack

        section_list = reg.season.section_list()
        if len(section_list) > 1:
            section_options = [(season.id, season.section.name) for season in section_list]
            self.fields['section'] = forms.ChoiceField(choices=section_options, initial=workflow.default_section.id)

        if workflow.is_late:
            self.fields['retroactive_byes'] = forms.IntegerField(initial=workflow.default_byes)
            self.fields['late_join_points'] = forms.FloatField(initial=workflow.default_ljp)
项目:CodingDojo    作者:ComputerSocietyUNB    | 项目源码 | 文件源码
def get_prep_value(self, value):
        value = super(FloatField, self).get_prep_value(value)
        if value is None:
            return None
        return float(value)
项目:CodingDojo    作者:ComputerSocietyUNB    | 项目源码 | 文件源码
def get_internal_type(self):
        return "FloatField"
项目:CodingDojo    作者:ComputerSocietyUNB    | 项目源码 | 文件源码
def formfield(self, **kwargs):
        defaults = {'form_class': forms.FloatField}
        defaults.update(kwargs)
        return super(FloatField, self).formfield(**defaults)
项目:django-livesettings3    作者:kunaldeo    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
            kwargs['required'] = False
            forms.FloatField.__init__(self, *args, **kwargs)
项目:core    作者:IntelligentTrading    | 项目源码 | 文件源码
def formfield(self, **kwargs):
        from django.forms import FloatField
        defaults = {'form_class': FloatField}
        defaults.update(kwargs)
        return super(MoneyField, self).formfield(**defaults)
项目:django-rest-search    作者:wemap    | 项目源码 | 文件源码
def test_float(self):
        form_field = forms.FloatField()
        core_field = get_form_field_schema(form_field)
        self.assertTrue(isinstance(core_field, coreschema.Number))
        self.assertFalse(core_field.integer_only)
项目:django-danceschool    作者:django-danceschool    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        super(RefundForm, self).__init__(*args, **kwargs)

        this_invoice = kwargs.pop('instance',None)

        for item in this_invoice.invoiceitem_set.all():
            initial = False
            if item.finalEventRegistration:
                initial = item.finalEventRegistration.cancelled
            item_max = item.total + item.taxes if this_invoice.buyerPaysSalesTax else item.total

            self.fields["item_cancelled_%s" % item.id] = forms.BooleanField(
                label=_('Cancelled'),required=False,initial=initial)
            self.fields['item_refundamount_%s' % item.id] = forms.FloatField(
                label=_('Refund Amount'),required=False,initial=(-1) * item.adjustments, min_value=0, max_value=item_max)

        self.fields['comments'] = forms.CharField(
            label=_('Explanation/Comments (optional)'),required=False,
            help_text=_('This information will be added to the comments on the invoice associated with this refund.'),
            widget=forms.Textarea(attrs={'placeholder': _('Enter explanation/comments...'), 'class': 'form-control'}))

        self.fields['id'] = forms.ModelChoiceField(
            required=True,queryset=Invoice.objects.filter(id=this_invoice.id),widget=forms.HiddenInput(),initial=this_invoice.id)

        self.fields['initial_refund_amount'] = forms.FloatField(
            required=True,initial=(-1) * this_invoice.adjustments,min_value=0,max_value=this_invoice.amountPaid + this_invoice.refunds,widget=forms.HiddenInput())

        self.fields['total_refund_amount'] = forms.FloatField(
            required=True,initial=0,min_value=0,max_value=this_invoice.amountPaid + this_invoice.refunds,widget=forms.HiddenInput())
项目:heltour    作者:cyanfish    | 项目源码 | 文件源码
def formfield(self, **kwargs):
        defaults = {'widget': django_forms.TextInput(attrs={'class': 'vIntegerField'}), 'initial': self.default}
        defaults.update(kwargs)
        return django_forms.FloatField(**defaults)

#-------------------------------------------------------------------------------
项目:graphene-django    作者:graphql-python    | 项目源码 | 文件源码
def test_should_float_convert_float():
    assert_conversion(forms.FloatField, graphene.Float)
项目:pretix-passbook    作者:pretix    | 项目源码 | 文件源码
def settings_form_fields(self) -> dict:
        return OrderedDict(
            list(super().settings_form_fields.items()) + [
                ('icon',
                 PNGImageField(
                     label=_('Event icon'),
                     help_text=_('Display size is 29 x 29 pixels. We suggest an upload size of 87 x 87 pixels to '
                                 'support retina displays.'),
                     required=True,
                 )),
                ('logo',
                 PNGImageField(
                     label=_('Event logo'),
                     help_text=_('Display size is 160 x 50 pixels. We suggest an upload size of 480 x 150 pixels to '
                                 'support retina displays.'),
                     required=True,
                 )),
                ('background',
                 PNGImageField(
                     label=_('Pass background image'),
                     help_text=_('Display size is 180 x 220 pixels. We suggest an upload size of 540 x 660 pixels to '
                                 'support retina displays.'),
                     required=False,
                 )),
                ('latitude',
                 forms.FloatField(
                     label=_('Event location (latitude)'),
                     required=False
                 )),
                ('longitude',
                 forms.FloatField(
                     label=_('Event location (longitude)'),
                     required=False
                 )),
            ]
        )
项目:lifesoundtrack    作者:MTG    | 项目源码 | 文件源码
def get_prep_value(self, value):
        value = super(FloatField, self).get_prep_value(value)
        if value is None:
            return None
        return float(value)
项目:lifesoundtrack    作者:MTG    | 项目源码 | 文件源码
def get_internal_type(self):
        return "FloatField"
项目:lifesoundtrack    作者:MTG    | 项目源码 | 文件源码
def formfield(self, **kwargs):
        defaults = {'form_class': forms.FloatField}
        defaults.update(kwargs)
        return super(FloatField, self).formfield(**defaults)
项目:pretix-espass    作者:esPass    | 项目源码 | 文件源码
def settings_form_fields(self) -> dict:
        return OrderedDict(
            list(super().settings_form_fields.items()) + [
                ('icon',
                 PNGImageField(
                     label=_('Event icon'),
                     help_text=_('We suggest an upload size of 96x96 pixels - the display size is 48dp'),
                     required=True,
                 )),
                ('logo',
                 PNGImageField(
                     label=_('Event logo'),
                     help_text=_('Upload a nice big image - size depends on the device - example size 800x600'),
                     required=True,
                 )),
                ('location_name',
                 forms.CharField(
                     label=_('Event location name'),
                     required=False
                 )),
                ('latitude',
                 forms.FloatField(
                     label=_('Event location latitude'),
                     required=False
                 )),
                ('longitude',
                 forms.FloatField(
                     label=_('Event location longitude'),
                     required=False
                 )),
            ]
        )
项目:liberator    作者:libscie    | 项目源码 | 文件源码
def get_prep_value(self, value):
        value = super(FloatField, self).get_prep_value(value)
        if value is None:
            return None
        return float(value)
项目:liberator    作者:libscie    | 项目源码 | 文件源码
def get_internal_type(self):
        return "FloatField"
项目:liberator    作者:libscie    | 项目源码 | 文件源码
def formfield(self, **kwargs):
        defaults = {'form_class': forms.FloatField}
        defaults.update(kwargs)
        return super(FloatField, self).formfield(**defaults)
项目:djanoDoc    作者:JustinChavez    | 项目源码 | 文件源码
def get_prep_value(self, value):
        value = super(FloatField, self).get_prep_value(value)
        if value is None:
            return None
        return float(value)
项目:djanoDoc    作者:JustinChavez    | 项目源码 | 文件源码
def get_internal_type(self):
        return "FloatField"
项目:djanoDoc    作者:JustinChavez    | 项目源码 | 文件源码
def formfield(self, **kwargs):
        defaults = {'form_class': forms.FloatField}
        defaults.update(kwargs)
        return super(FloatField, self).formfield(**defaults)
项目:Deploy_XXNET_Server    作者:jzp820927    | 项目源码 | 文件源码
def get_form_field(self, **kwargs):
    """Return a Django form field appropriate for an integer property.

    This defaults to a FloatField instance when using Django 0.97 or
    later.  For 0.96 this defaults to the CharField class.
    """
    defaults = {}
    if hasattr(forms, 'FloatField'):
      defaults['form_class'] = forms.FloatField
    defaults.update(kwargs)
    return super(FloatProperty, self).get_form_field(**defaults)
项目:internet-of-things    作者:softbutterfly    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        self.widget = GeopositionWidget()
        errors = self.default_error_messages.copy()

        if 'error_messages' in kwargs:
            errors.update(kwargs['error_messages'])

        localize = kwargs.get('localize', False)

        fields = (
            forms.FloatField(
                label=_('latitude'),
                error_messages={'invalid': errors['invalid_latitude']},
                localize=localize,
                validators=[
                    NumberIsInRangeValidator(
                        lower=-90.0,
                        upper=+90.0,
                        error_message=_("latitude must be a value between -90 and +90 degrees").capitalize()
                    )
                ]
            ),
            forms.FloatField(
                label=_('longitude'),
                error_messages={'invalid': errors['invalid_longitude']},
                localize=localize,
                validators=[
                    NumberIsInRangeValidator(
                        lower=-180.0,
                        upper=+180.0,
                        error_message=_("longitude must be a value between -180 and +180 degrees").capitalize()
                    ),
                ]
            ),
            forms.FloatField(
                label=_('elevation'),
                error_messages={'invalid': errors['invalid_elevation']},
                localize=localize
            ),
        )
        super(GeopositionField, self).__init__(fields, **kwargs)
项目:evel-reporting-reference-vnf    作者:att    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        '''Constructor to allocate dynamic choices.

        The constructor is needed to initialize the Alarm name choices so
        it reflects the state of the database at the point of use.
        '''
        super(FaultForm, self).__init__(*args, **kwargs)

        #----------------------------------------------------------------------
        # get the selected alarm_condition from the args. If there are no
        # faults defined in the database, the value will be None, so set the
        # text to read 'No Events defined'
        #----------------------------------------------------------------------
        fault_name = args[0]['fault_name']

        if fault_name is None:
            self.fields['fault_name'] = forms.CharField()
            self.fields['fault_name'].widget.attrs['readonly'] = True
            self.data['fault_name'] = 'No Events defined'
        else:
             self.fields['fault_name'] = forms.ChoiceField(choices=[
                     (o.fault_name, str(o)) for o in Fault.objects.all()])

        self.fields['fault_count'] = forms.IntegerField(
                                                    label='Faults to Raise',
                                                    min_value=1)
        self.fields['fault_rate'] = forms.FloatField(
                                                 label='Fault Rate (per sec)',
                                                 min_value=0.0,
                                                 max_value=10.0)
项目:evel-reporting-reference-vnf    作者:att    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        '''Constructor to allocate dynamic choices.

        The constructor is needed to initialize the Alarm Condition choices so
        it reflects the state of the database at the point of use.
        '''
        super(MeasurementForm, self).__init__(*args, **kwargs)

        #----------------------------------------------------------------------
        # get the selected event from the args. If there are no events defined
        # in the database, the value will be None, so set the text to read
        # 'No Events defined'
        #----------------------------------------------------------------------
        measurement_name = args[0]['measurement']

        if measurement_name is None:
            self.fields['measurement'] = forms.CharField()
            self.fields['measurement'].widget.attrs['readonly'] = True
            self.data['measurement'] = 'No Events defined'
        else:
             self.fields['measurement'] = forms.ChoiceField(choices=[
                     (o.measurement_name, str(o))
                        for o in Measurement.objects.all()])
        self.fields['measurement_count'] = forms.IntegerField(
                                              label='Measurements to Raise',
                                              min_value=1)
        self.fields['measurement_rate'] = forms.FloatField(
                                           label='Measurement Rate (per sec)',
                                           min_value=0.0,
                                           max_value=10.0)
        return
项目:evel-reporting-reference-vnf    作者:att    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        '''Constructor to allocate dynamic choices.

        The constructor is needed to initialise the Metrics choices so
        it reflects the state of the database at the point of use.
        '''
        super(MobileFlowForm, self).__init__(*args, **kwargs)

        #----------------------------------------------------------------------
        # get the selected event from the args. If there are no events defined
        # in the database, the value will be None, so set the text to read
        # 'No Events defined'
        #----------------------------------------------------------------------
        flow_name = args[0]['mobile_flow']

        if flow_name is None:
            self.fields['mobile_flow'] = forms.CharField()
            self.fields['mobile_flow'].widget.attrs['readonly'] = True
            self.data['mobile_flow'] = 'No Events defined'
        else:
            self.fields['mobile_flow'] = forms.ChoiceField(label='Mobile Flow',
                                       choices=[ (o.friendly_name, str(o))
                                           for o in MobileFlow.objects.all()])
        self.fields['mobile_flow_count'] = forms.IntegerField(
                                              label='Mobile Flow to Raise',
                                              min_value=1)
        self.fields['mobile_flow_rate'] = forms.FloatField(
                                           label='Mobile Flow Rate (per sec)',
                                           min_value=0.0,
                                           max_value=10.0)
        return
项目:evel-reporting-reference-vnf    作者:att    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        '''Constructor to allocate dynamic choices.

        The constructor is needed to initialise the Syslog choices so
        it reflects the state of the database at the point of use.
        '''
        super(SyslogForm, self).__init__(*args, **kwargs)

        #----------------------------------------------------------------------
        # get the selected event from the args. If there are no events defined
        # in the database, the value will be None, so set the text to read
        # 'No Events defined'
        #----------------------------------------------------------------------
        syslog_name = args[0]['syslog']

        if syslog_name is None:
            self.fields['syslog'] = forms.CharField()
            self.fields['syslog'].widget.attrs['readonly'] = True
            self.data['syslog'] = 'No Events defined'
        else:
            self.fields['syslog'] = forms.ChoiceField(label='syslog',
                                       choices=[ (o.friendly_name, str(o))
                                           for o in Syslog.objects.all()])

        self.fields['syslog_count'] = forms.IntegerField(
                                                       label='Syslog to Raise',
                                                       min_value=1)
        self.fields['syslog_rate'] = forms.FloatField(
                                                 label='Syslog Rate (per sec)',
                                                 min_value=0.0,
                                                 max_value=10.0)
        return
项目:django-next-train    作者:bitpixdigital    | 项目源码 | 文件源码
def get_prep_value(self, value):
        value = super(FloatField, self).get_prep_value(value)
        if value is None:
            return None
        return float(value)
项目:django-next-train    作者:bitpixdigital    | 项目源码 | 文件源码
def get_internal_type(self):
        return "FloatField"
项目:django-next-train    作者:bitpixdigital    | 项目源码 | 文件源码
def formfield(self, **kwargs):
        defaults = {'form_class': forms.FloatField}
        defaults.update(kwargs)
        return super(FloatField, self).formfield(**defaults)
项目:LatinSounds_AppEnviaMail    作者:G3ek-aR    | 项目源码 | 文件源码
def get_prep_value(self, value):
        value = super(FloatField, self).get_prep_value(value)
        if value is None:
            return None
        return float(value)
项目:LatinSounds_AppEnviaMail    作者:G3ek-aR    | 项目源码 | 文件源码
def get_internal_type(self):
        return "FloatField"
项目:LatinSounds_AppEnviaMail    作者:G3ek-aR    | 项目源码 | 文件源码
def formfield(self, **kwargs):
        defaults = {'form_class': forms.FloatField}
        defaults.update(kwargs)
        return super(FloatField, self).formfield(**defaults)
项目:django-wechat-api    作者:crazy-canux    | 项目源码 | 文件源码
def get_prep_value(self, value):
        value = super(FloatField, self).get_prep_value(value)
        if value is None:
            return None
        return float(value)
项目:django-wechat-api    作者:crazy-canux    | 项目源码 | 文件源码
def get_internal_type(self):
        return "FloatField"
项目:django-wechat-api    作者:crazy-canux    | 项目源码 | 文件源码
def formfield(self, **kwargs):
        defaults = {'form_class': forms.FloatField}
        defaults.update(kwargs)
        return super(FloatField, self).formfield(**defaults)
项目:sasa    作者:lhmlihaomin    | 项目源码 | 文件源码
def map_field(self, cfield):
        label = cfield.title
        if cfield.required:
            suffix = "*"

        if cfield.field_type == "string":
            f = forms.CharField(required=cfield.required,
                                label=label,
                                label_suffix=suffix)
        elif cfield.field_type == "text":
            f = forms.CharField(required=cfield.required, 
                                widget=forms.Textarea, 
                                label=label,
                                label_suffix=suffix)
        elif cfield.field_type == "email":
            f = forms.EmailField(required=cfield.required, 
                                 label=label,
                                 label_suffix=suffix)
        elif cfield.field_type == "boolean":
            f = forms.BooleanField(required=cfield.required, 
                                   label=label,
                                   label_suffix=suffix)
        elif cfield.field_type == "number":
            f = forms.FloatField(required=cfield.required, 
                                 label=label,
                                 label_suffix=suffix)
        elif cfield.field_type == "integer":
            f = forms.IntegerField(required=cfield.required, 
                                   label=label,
                                   label_suffix=suffix)
        elif cfield.field_type == "select":
            f = forms.ChoiceField(required=cfield.required, 
                                  choices=cfield.choices, 
                                  label=label,
                                  label_suffix=suffix)
        elif cfield.field_type == "select_multiple":
            f = forms.MultipleChoiceField(required=cfield.required, 
                                          choices=cfield.choices, 
                                          label=label,
                                          label_suffix=suffix)
        elif cfield.field_type == "checkbox":
            f = forms.BooleanField(required=cfield.required, 
                                   label=label,
                                   label_suffix=suffix)
        elif cfield.field_type == "radio":
            f = forms.ChoiceField(required=cfield.required, 
                                  choices=cfield.choices, 
                                  widget=forms.RadioSelect, 
                                  label=label,
                                  label_suffix=suffix)
        else:
            # return a generic text input:
            f = forms.CharField()
        return f