mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Custom date picker field
- Prevents picker from being "required" by the form
This commit is contained in:
parent
03276629c2
commit
2b57ffeb08
@ -5,10 +5,13 @@ from __future__ import unicode_literals
|
|||||||
|
|
||||||
from .validators import allowable_url_schemes
|
from .validators import allowable_url_schemes
|
||||||
|
|
||||||
|
from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
from django.forms.fields import URLField as FormURLField
|
from django.forms.fields import URLField as FormURLField
|
||||||
from django.db import models as models
|
from django.db import models as models
|
||||||
from django.core import validators
|
from django.core import validators
|
||||||
from django import forms
|
from django import forms
|
||||||
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
import InvenTree.helpers
|
import InvenTree.helpers
|
||||||
@ -31,6 +34,32 @@ class InvenTreeURLField(models.URLField):
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
class InvenTreeDatePickerFormField(forms.DateField):
|
||||||
|
"""
|
||||||
|
Custom date-picker field
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
|
||||||
|
help_text = kwargs.get('help_text', _('Enter date'))
|
||||||
|
required = kwargs.get('required', False)
|
||||||
|
initial = kwargs.get('initial', None)
|
||||||
|
|
||||||
|
widget = forms.DateInput(
|
||||||
|
attrs={
|
||||||
|
'type': 'date',
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
forms.DateField.__init__(
|
||||||
|
self,
|
||||||
|
required=required,
|
||||||
|
initial=initial,
|
||||||
|
help_text=help_text,
|
||||||
|
widget=widget
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def round_decimal(value, places):
|
def round_decimal(value, places):
|
||||||
"""
|
"""
|
||||||
Round value to the specified number of places.
|
Round value to the specified number of places.
|
||||||
|
@ -10,6 +10,7 @@ from django import forms
|
|||||||
|
|
||||||
from InvenTree.forms import HelperForm
|
from InvenTree.forms import HelperForm
|
||||||
from InvenTree.fields import RoundingDecimalFormField
|
from InvenTree.fields import RoundingDecimalFormField
|
||||||
|
from InvenTree.fields import InvenTreeDatePickerFormField
|
||||||
|
|
||||||
from .models import Build, BuildItem, BuildOrderAttachment
|
from .models import Build, BuildItem, BuildOrderAttachment
|
||||||
|
|
||||||
@ -26,18 +27,16 @@ class EditBuildForm(HelperForm):
|
|||||||
'batch': 'fa-layer-group',
|
'batch': 'fa-layer-group',
|
||||||
'serial-numbers': 'fa-hashtag',
|
'serial-numbers': 'fa-hashtag',
|
||||||
'location': 'fa-map-marker-alt',
|
'location': 'fa-map-marker-alt',
|
||||||
|
'target_date': 'fa-calendar-alt',
|
||||||
}
|
}
|
||||||
|
|
||||||
field_placeholder = {
|
field_placeholder = {
|
||||||
'reference': _('Build Order reference')
|
'reference': _('Build Order reference'),
|
||||||
|
'target_date': _('Order target date'),
|
||||||
}
|
}
|
||||||
|
|
||||||
# TODO: Make this a more "presentable" date picker
|
target_date = InvenTreeDatePickerFormField(
|
||||||
# TODO: Currently does not render super nicely with crispy forms
|
help_text=_('Target date for build completion. Build will be overdue after this date.')
|
||||||
target_date = forms.DateField(
|
|
||||||
widget=forms.DateInput(
|
|
||||||
attrs={'type': 'date'}
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
Loading…
Reference in New Issue
Block a user