monim67 / django-bootstrap-datepicker-plus

Bootstrap3/Bootstrap4/Bootstrap5 DatePickerInput, TimePickerInput, DateTimePickerInput, MonthPickerInput, YearPickerInput with date-range-picker functionality for django >= 2.0
https://pypi.python.org/pypi/django-bootstrap-datepicker-plus
MIT License
223 stars 61 forks source link

FutureWarning: The 'format' parameter is ignored, set 'format' in options instead.see https://github.com/monim67/django-bootstrap-datepicker-plus #118

Closed JanineRoux closed 4 months ago

JanineRoux commented 4 months ago

I get this runtime error in my logs : image

SatAuthPy3.9\lib\site-packages\bootstrap_datepicker_plus_base.py:38: FutureWarning: The 'format' parameter is ignored, set 'format' in options instead. see https://github.com/monim67/django-bootstrap-datepicker-plus warnings.warn(

I get this runtime message in Dev only (on my hosted prod environment it doesn't seem to appear on startup - but that may be a warning log that is being repressed) Please can you give me more insight into this Future warning - with a view to help me resolve it? I believe it may stem from my django settings.py file (extract attached) - should the formats be attached as widgets on the forms instead of the settings file ?

all my dates and datepickers are currently working fine. (I have over 20 forms and 100 models)

I expect some help pointers in where the adjustments need to be made, extract from my settings.py file

# Internationalization
# https://docs.djangoproject.com/en/2.1/topics/i18n/
DATE_FORMAT =  'j, N, Y'
DATE_INPUT_FORMATS = [
    '%Y-%m-%d',                         # '2006-10-25',
    '%d %b %Y', '%d %b, %Y',            # '25 Oct 2006', '25 Oct, 2006'
    '%d %B %Y', '%d %B, %Y',            # '25 October 2006', '25 October, 2006'
]
DATETIME_FORMAT = 'j N, Y, P'           # (e.g. 4 Feb., 2003, 4 p.m.)
DATETIME_INPUT_FORMATS = [
    '%Y-%m-%d %H:%M:%S',     # '2006-10-25 14:30:59'
    '%Y-%m-%d %H:%M:%S.%f',  # '2006-10-25 14:30:59.000200'
    '%Y-%m-%d %H:%M',        # '2006-10-25 14:30'
    '%Y-%m-%d',              # '2006-10-25'
]
LANGUAGE_CODE = 'en-gb'
#TIME_ZONE = 'UTC'
TIME_ZONE = 'Africa/Johannesburg'
# get local timezone    
local_tz = timezone.now
USE_I18N = True
USE_L10N = True
USE_TZ = True

Setup Information (please complete the following information):

[x] I have followed the configuration instructions and checked out the common error troubleshooting page.

christianwgd commented 4 months ago

Not sure if it helps, but you as the error message says, you should set the format in the options like so:

'timestamp': DateTimePickerInput(
                options={
                    # https://getdatepicker.com/4/Options/#format
                    'format': 'MM/DD/YYYY HH:mm',
                    # https://getdatepicker.com/4/Options/#stepping
                    'stepping': 10,
                    'showClose': True,
                    'showClear': True
                }
            )

in your forms widgets. You can see a sample here: https://github.com/christianwgd/date_time_picker_sample

Are you really using two libraries for the datepicker? You're referring to datepicker-plus and datepicker-widget. I don't know, if that is working. One more word on your settings file: There's a comment "get local timezone" which is followed by a statement "local_tz = timezone.now". If you are importing timezone from django.utils timezone.now is a function and timezone.now() will give you the current timezone aware date and time and not a timezone (https://docs.djangoproject.com/en/5.0/topics/i18n/timezones/#naive-and-aware-datetime-objects).

JanineRoux commented 4 months ago

Good morning Christian, Thank you for your speedy response. I have taken your advice, and removed the additional datepicker-widget library, and standardised all my dates on the forms to user the DateTimePickerInput as suggested. The warning has disappeared. I tend to think that the warning may have been linked to an additional attribute on my forms input widget that declared the datetime to be local perhaps? In any event, the clean up standardised all the input date formats, though the one fallout has been that the dark mode is not applied to the datetimepicket widget, which makes them a little unsightly - but that I will address in good time. thanks again Janine