当前位置: 首页>>代码示例>>Python>>正文


Python forms.DateInput方法代码示例

本文整理汇总了Python中django.forms.DateInput方法的典型用法代码示例。如果您正苦于以下问题:Python forms.DateInput方法的具体用法?Python forms.DateInput怎么用?Python forms.DateInput使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.forms的用法示例。


在下文中一共展示了forms.DateInput方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import DateInput [as 别名]
def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        for name, field in self.fields.items():
            if isinstance(field, forms.DateField):
                # Force date format on load, so date picker doesn't mess it up
                # because of i10n.
                field.widget = forms.DateInput(format='%Y-%m-%d')

            if name == 'extra':
                field.label = getattr(
                    settings, 'USER_EXTRA_FIELD_LABEL', _('Additional data')) 
开发者ID:ideascube,项目名称:ideascube,代码行数:14,代码来源:forms.py

示例2: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import DateInput [as 别名]
def __init__(self, *args, **kwargs):
        settings = kwargs.pop('settings', None)
        super(GeneratedPluginSettingForm, self).__init__(*args, **kwargs)

        for field in settings:

            object = field['object']
            if field['types'] == 'char':
                self.fields[field['name']] = forms.CharField(widget=forms.TextInput(), required=False)
            elif field['types'] == 'rich-text' or field['types'] == 'text' or field['types'] == 'Text':
                self.fields[field['name']] = forms.CharField(widget=forms.Textarea, required=False)
            elif field['types'] == 'json':
                self.fields[field['name']] = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple,
                                                                       choices=field['choices'],
                                                                       required=False)
            elif field['types'] == 'number':
                self.fields[field['name']] = forms.CharField(widget=forms.TextInput(attrs={'type': 'number'}))
            elif field['types'] == 'select':
                self.fields[field['name']] = forms.CharField(widget=forms.Select(choices=field['choices']))
            elif field['types'] == 'date':
                self.fields[field['name']] = forms.CharField(
                    widget=forms.DateInput(attrs={'class': 'datepicker'}))
            elif field['types'] == 'boolean':
                self.fields[field['name']] = forms.BooleanField(
                    widget=forms.CheckboxInput(attrs={'is_checkbox': True}),
                    required=False)

            self.fields[field['name']].initial = object.processed_value
            self.fields[field['name']].help_text = object.setting.description 
开发者ID:BirkbeckCTP,项目名称:janeway,代码行数:31,代码来源:forms.py

示例3: date_input

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import DateInput [as 别名]
def date_input(field):
    field.widget = DateInput()
    field.widget.attrs.update({
        'class': 'calendar-widget',
        'data-role': 'data',
    })
    return field 
开发者ID:MagiCircles,项目名称:SchoolIdolAPI,代码行数:9,代码来源:forms.py

示例4: test_date_input_different_format

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import DateInput [as 别名]
def test_date_input_different_format(self):
        """
        Tests that the ``django.forms`` configured input format is respected.
        """
        class Form(forms.Form):
            date = forms.DateField(widget=forms.DateInput(format='%m-%Y-%d'))

        self.ctx['form'] = Form(initial={'date': datetime.date(2016, 3, 27)})
        tmpl = get_template('widgets_django')
        output = tmpl.render(self.ctx)
        self.assertHTMLEqual(
            output,
            '<input type="text" name="date" id="id_date" value="03-2016-27" class=" " required>'
        ) 
开发者ID:funkybob,项目名称:django-sniplates,代码行数:16,代码来源:test_widgets_django.py

示例5: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import DateInput [as 别名]
def __init__(self, attrs=None):
        widgets = (forms.DateInput, forms.DateInput)
        super().__init__(widgets, attrs) 
开发者ID:OpenTechFund,项目名称:hypha,代码行数:5,代码来源:filters.py

示例6: test_format

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import DateInput [as 别名]
def test_format(self):
        """
        Use 'format' to change the way a value is displayed.
        """
        d = date(2007, 9, 17)
        widget = DateInput(format='%d/%m/%Y', attrs={'type': 'date'})
        self.check_html(widget, 'date', d, html='<input type="date" name="date" value="17/09/2007">') 
开发者ID:nesdis,项目名称:djongo,代码行数:9,代码来源:test_dateinput.py

示例7: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import DateInput [as 别名]
def __init__(self, *args, **kwargs):
        elements = kwargs.pop('additional_fields', None)
        super(PreprintInfo, self).__init__(*args, **kwargs)

        self.fields['license'].queryset = submission_models.Licence.objects.filter(press__isnull=False,
                                                                                   available_for_submission=True)
        self.fields['license'].required = True

        # If there is an instance, we want to try to set the default subject area
        if 'instance' in kwargs:
            article = kwargs['instance']
            if article:
                self.fields['subject'].initial = article.get_subject_area()

        if elements:
            for element in elements:
                if element.kind == 'text':
                    self.fields[element.name] = forms.CharField(
                        widget=forms.TextInput(attrs={'div_class': element.width}),
                        required=element.required)
                elif element.kind == 'textarea':
                    self.fields[element.name] = forms.CharField(widget=forms.Textarea,
                                                                required=element.required)
                elif element.kind == 'date':
                    self.fields[element.name] = forms.CharField(
                        widget=forms.DateInput(attrs={'class': 'datepicker', 'div_class': element.width}),
                        required=element.required)

                elif element.kind == 'select':
                    choices = render_choices(element.choices)
                    self.fields[element.name] = forms.ChoiceField(
                        widget=forms.Select(attrs={'div_class': element.width}), choices=choices,
                        required=element.required)

                elif element.kind == 'email':
                    self.fields[element.name] = forms.EmailField(
                        widget=forms.TextInput(attrs={'div_class': element.width}),
                        required=element.required)
                elif element.kind == 'check':
                    self.fields[element.name] = forms.BooleanField(
                        widget=forms.CheckboxInput(attrs={'is_checkbox': True}),
                        required=element.required)

                self.fields[element.name].help_text = element.help_text
                self.fields[element.name].label = element.name

                if article:
                    try:
                        check_for_answer = submission_models.FieldAnswer.objects.get(field=element, article=article)
                        self.fields[element.name].initial = check_for_answer.answer
                    except submission_models.FieldAnswer.DoesNotExist:
                        pass 
开发者ID:BirkbeckCTP,项目名称:janeway,代码行数:54,代码来源:forms.py

示例8: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import DateInput [as 别名]
def __init__(self, *args, **kwargs):
        review_assignment = kwargs.pop('review_assignment', None)
        fields_required = kwargs.pop('fields_required', True)
        answer = kwargs.pop('answer', None)
        preview = kwargs.pop('preview', None)
        super(GeneratedForm, self).__init__(*args, **kwargs)

        if answer:
            elements = [answer.element]
        elif preview:
            elements = preview.elements.all()
        else:
            elements = review_assignment.form.elements.all()

        for element in elements:
            if element.kind == 'text':
                self.fields[element.name] = forms.CharField(
                    widget=forms.TextInput(attrs={'div_class': element.width}),
                    required=element.required if fields_required else False)
            elif element.kind == 'textarea':
                self.fields[element.name] = forms.CharField(widget=forms.Textarea,
                                                            required=element.required if fields_required else False)
            elif element.kind == 'date':
                self.fields[element.name] = forms.CharField(
                    widget=forms.DateInput(attrs={'class': 'datepicker', 'div_class': element.width}),
                    required=element.required if fields_required else False)
            elif element.kind == 'upload':
                self.fields[element.name] = forms.FileField(required=element.required if fields_required else False)
            elif element.kind == 'select':
                choices = render_choices(element.choices)
                self.fields[element.name] = forms.ChoiceField(
                    widget=forms.Select(attrs={'div_class': element.width}), choices=choices,
                    required=element.required if fields_required else False)
            elif element.kind == 'email':
                self.fields[element.name] = forms.EmailField(
                    widget=forms.TextInput(attrs={'div_class': element.width}),
                    required=element.required if fields_required else False)
            elif element.kind == 'check':
                self.fields[element.name] = forms.BooleanField(
                    widget=forms.CheckboxInput(attrs={'is_checkbox': True}),
                    required=element.required if fields_required else False)

            self.fields[element.name].help_text = element.help_text
            self.fields[element.name].label = element.name

            if answer:
                self.fields[element.name].initial = answer.edited_answer if answer.edited_answer else answer.answer 
开发者ID:BirkbeckCTP,项目名称:janeway,代码行数:49,代码来源:forms.py


注:本文中的django.forms.DateInput方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。