Skip to content

Commit

Permalink
Merge branch 'main' into escape-html-output
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewhegarty committed Aug 4, 2022
2 parents 8285b44 + a0b4dfc commit 2c6cd3e
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 13 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,4 @@ The following is a list of much appreciated contributors:
* 2ykwang (Yeongkwang Yang)
* KamilRizatdinov (Kamil Rizatdinov)
* Mark Walker
* vanschelven (Klaas van Schelven)
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Philosophy
* the original work of the author, contributed under the BSD, or...
* work taken from another project released under a BSD-compatible license.
* GPL'd (or similar) works are not eligible for inclusion.
* django-import-export's git master branch should always be stable, production-ready &
* django-import-export's git main branch should always be stable, production-ready &
passing all tests.


Expand Down
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ django-import-export
django-import-export is a Django application and library for importing
and exporting data with included admin integration.

**django-import-export release 3 is currently in beta** (`pypi <https://pypi.org/project/django-import-export/3.0.0b4/>`_).
List of planned changes is `here <https://github.com/django-import-export/django-import-export/blob/release-3-x/docs/changelog.rst>`_.

Features:

* support multiple formats (Excel, CSV, JSON, ...
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Changelog

- Fix deprecation in example application: Added support for transitional form renderer (#1451)
- Escape HTML output when rendering decoding errors (#1469)
- Apply make_aware when the original file contains actual datetimes (#1478)

2.8.0 (2022-03-31)
------------------
Expand Down
24 changes: 12 additions & 12 deletions import_export/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,21 +212,21 @@ def __init__(self, format=None):
self.formats = formats

def clean(self, value, row=None, *args, **kwargs):
dt = None
if not value:
return None
if isinstance(value, datetime):
return value
for format in self.formats:
try:
dt = datetime.strptime(value, format)
if settings.USE_TZ:
# make datetime timezone aware so we don't compare
# naive datetime to an aware one
dt = timezone.make_aware(dt,
timezone.get_default_timezone())
return dt
except (ValueError, TypeError):
continue
dt = value
else:
for format_ in self.formats:
try:
dt = datetime.strptime(value, format_)
except (ValueError, TypeError):
continue
if dt:
if settings.USE_TZ:
dt = timezone.make_aware(dt)
return dt
raise ValueError("Enter a valid date/time.")

def render(self, value, obj=None):
Expand Down
6 changes: 6 additions & 0 deletions tests/core/tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ def test_use_tz(self):
self.assertEqual(self.widget.render(utc_dt), "13.08.2012 20:00:00")
self.assertEqual(self.widget.clean("13.08.2012 20:00:00"), utc_dt)

@override_settings(USE_TZ=True, TIME_ZONE='Europe/Ljubljana')
def test_clean_returns_tz_aware_datetime_when_naive_datetime_passed(self):
# issue 1165
target_dt = timezone.make_aware(self.datetime, pytz.timezone('Europe/Ljubljana'))
self.assertEqual(target_dt, self.widget.clean(self.datetime))

@override_settings(DATETIME_INPUT_FORMATS=None)
def test_default_format(self):
self.widget = widgets.DateTimeWidget()
Expand Down

0 comments on commit 2c6cd3e

Please sign in to comment.