Skip to content

Commit

Permalink
feat(core): allow to skip dateparsing in LegacyDateMixin
Browse files Browse the repository at this point in the history
Closes: #1208
  • Loading branch information
b1rger committed Sep 30, 2024
1 parent 489bc96 commit 0925fc0
Showing 1 changed file with 34 additions and 32 deletions.
66 changes: 34 additions & 32 deletions apis_core/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,41 +30,43 @@ class Meta:
abstract = True

def save(self, *args, **kwargs):
start = None
start_start = None
start_end = None
end = None
end_start = None
end_end = None
skip_date_parsing = getattr(self, "skip_date_parsing", False)
if not skip_date_parsing:
start = None
start_start = None
start_end = None
end = None
end_start = None
end_end = None

if self.start_date_written:
start, start_start, start_end = DateParser.parse_date(
self.start_date_written
)
# DateParser returns datetime, but we want dates without time
if start:
start = start.date()
if start_start:
start_start = start_start.date()
if start_end:
start_end = start_end.date()
if self.start_date_written:
start, start_start, start_end = DateParser.parse_date(
self.start_date_written
)
# DateParser returns datetime, but we want dates without time
if start:
start = start.date()
if start_start:
start_start = start_start.date()
if start_end:
start_end = start_end.date()

if self.end_date_written:
end, end_start, end_end = DateParser.parse_date(self.end_date_written)
# DateParser returns datetime, but we want dates without time
if end:
end = end.date()
if end_start:
end_start = end_start.date()
if end_end:
end_end = end_end.date()
if self.end_date_written:
end, end_start, end_end = DateParser.parse_date(self.end_date_written)
# DateParser returns datetime, but we want dates without time
if end:
end = end.date()
if end_start:
end_start = end_start.date()
if end_end:
end_end = end_end.date()

self.start_date = start
self.start_start_date = start_start
self.start_end_date = start_end
self.end_date = end
self.end_start_date = end_start
self.end_end_date = end_end
self.start_date = start
self.start_start_date = start_start
self.start_end_date = start_end
self.end_date = end
self.end_start_date = end_start
self.end_end_date = end_end

super().save(*args, **kwargs)

Expand Down

0 comments on commit 0925fc0

Please sign in to comment.