slashmili / django-jalali

Jalali DateField support for Django model
http://pypi.python.org/pypi/django_jalali
BSD 3-Clause "New" or "Revised" License
258 stars 52 forks source link

[improve] Respect jDateField's input_formats kwarg when parsing date #257

Closed saharnaz-rashidi closed 3 months ago

saharnaz-rashidi commented 3 months ago

Problem

Currently jDateField(input_formats=['%Y/%m/%d']) (or similar usage) would cause validation error for data with correct format. The same issue applies to jDateTimeField. Looking at the code, the parameter input_formats does not do anything as the logic is not implemented. This PR provides a solution for using input_formats.

Related issues

Possibly resolves issues: issue #93 and issue #95

Steps to reproduce the problem

from django import forms
from django_jalali.forms import jDateField, jDateTimeField

class TestForm(forms.Form):
    date = jDateField(input_formats=["%Y/%m/%d"])
    date_time = jDateTimeField(input_formats=["%Y/%m/%d %H:%M"])

    class Meta:
        fields = ('date', 'date_time')
>>> form = TestForm(data={'date':'1403/05/28', 'date_time': '1403/05/28 10:10'})
>>> form.is_valid()
False
>>> form.errors
{'date': ['Enter a valid date.'], 'date_time': ['Enter a valid date/time.']}

With Fix applied

>>> form = TestForm(data={'date':'1403/05/28', 'date_time': '1403/05/28 10:10'})
>>> form.is_valid()
True
>>> form.errors
{}
slashmili commented 3 months ago

@saharnaz-rashidi Superb! Thanks for the fix and also for the descriptive PR message! LGTM

@hramezani could you please review the PR 😬?

slashmili commented 3 months ago

Release it as 7.1.0