Python django.forms.DateInput() Examples
The following are 10
code examples of django.forms.DateInput().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.forms
, or try the search function
.
Example #1
Source File: forms.py From ideascube with GNU Affero General Public License v3.0 | 6 votes |
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'))
Example #2
Source File: test_widgets_django.py From django-sniplates with MIT License | 6 votes |
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>' )
Example #3
Source File: forms.py From janeway with GNU Affero General Public License v3.0 | 5 votes |
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
Example #4
Source File: forms.py From janeway with GNU Affero General Public License v3.0 | 5 votes |
def __init__(self, *args, **kwargs): settings = kwargs.pop('settings', None) super(GeneratedSettingForm, self).__init__(*args, **kwargs) for field in settings: object = field['object'] if object.setting.types == 'char': self.fields[field['name']] = forms.CharField(widget=forms.TextInput(), required=False) elif object.setting.types == 'rich-text' or object.setting.types == 'text': self.fields[field['name']] = forms.CharField(widget=forms.Textarea, required=False) elif object.setting.types == 'json': self.fields[field['name']] = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple, choices=field['choices'], required=False) elif object.setting.types == 'number': self.fields[field['name']] = forms.CharField(widget=forms.TextInput(attrs={'type': 'number'})) elif object.setting.types == 'select': self.fields[field['name']] = forms.CharField(widget=forms.Select(choices=field['choices'])) elif object.setting.types == 'date': self.fields[field['name']] = forms.CharField( widget=forms.DateInput(attrs={'class': 'datepicker'})) elif object.setting.types == 'boolean': self.fields[field['name']] = forms.BooleanField( widget=forms.CheckboxInput(attrs={'is_checkbox': True}), required=False) self.fields[field['name']].label = object.setting.pretty_name self.fields[field['name']].initial = object.processed_value self.fields[field['name']].help_text = object.setting.description
Example #5
Source File: forms.py From SchoolIdolAPI with Apache License 2.0 | 5 votes |
def date_input(field): field.widget = DateInput() field.widget.attrs.update({ 'class': 'calendar-widget', 'data-role': 'data', }) return field
Example #6
Source File: filters.py From hypha with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self, attrs=None): widgets = (forms.DateInput, forms.DateInput) super().__init__(widgets, attrs)
Example #7
Source File: test_dateinput.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
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">')
Example #8
Source File: test_dateinput.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
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">')
Example #9
Source File: forms.py From janeway with GNU Affero General Public License v3.0 | 4 votes |
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
Example #10
Source File: forms.py From janeway with GNU Affero General Public License v3.0 | 4 votes |
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