Skip to content

Commit

Permalink
Remove @bookings-export default filter values
Browse files Browse the repository at this point in the history
  • Loading branch information
folix-01 committed Nov 27, 2024
1 parent 7b51f9b commit 661ec56
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 46 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Changelog
2.8.2 (unreleased)
------------------

- Nothing changed yet.
- bookings-export remove default filter values.
[folix-01]


2.8.1 (2024-11-27)
Expand Down
80 changes: 35 additions & 45 deletions src/redturtle/prenotazioni/browser/bookings_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,7 @@ def csv_fields(self):
def csv_filename(self):
"""Return a filename for this csv"""

return "%s_%s.csv" % (
self.filename,
self.booking_start_from.date().isoformat()
+ "-"
+ self.booking_start_to.date().isoformat(),
)
return self.filename + ".csv"

@property
def brains(self):
Expand All @@ -80,35 +75,39 @@ def brains(self):
and "max",
}

if created:
return api.portal.get_tool("portal_catalog").unrestrictedSearchResults(
portal_type="Prenotazione",
Date={
"query": (
get_default_timezone(True).localize(self.booking_start_from),
get_default_timezone(True).localize(self.booking_start_to),
),
"range": "min:max",
},
review_state="confirmed",
sort_on="Date",
path=self.path and {"query": self.path} or "",
created=created,
)
else:
return api.portal.get_tool("portal_catalog").unrestrictedSearchResults(
portal_type="Prenotazione",
Date={
"query": (
get_default_timezone(True).localize(self.booking_start_from),
get_default_timezone(True).localize(self.booking_start_to),
),
"range": "min:max",
},
review_state="confirmed",
sort_on="Date",
path=self.path and {"query": self.path} or "",
date = (self.booking_start_from or self.booking_start_to) and {
"query": (self.booking_start_from and self.booking_start_to)
and (
get_default_timezone(True).localize(self.booking_start_from),
get_default_timezone(True).localize(self.booking_start_to),
)
or self.booking_start_from
and get_default_timezone(True).localize(self.booking_start_from)
or self.booking_start_to
and get_default_timezone(True).localize(self.booking_start_to),
"range": (self.booking_start_from and self.booking_start_to)
and "min:max"
or self.booking_start_from
and "min"
or self.booking_start_to
and "max",
}

query = dict(
portal_type="Prenotazione",
review_state="confirmed",
sort_on="Date",
path=self.path and {"query": self.path} or "",
created=created,
)

if created:
query["created"] = created

if date:
query["Date"] = date

return api.portal.get_tool("portal_catalog").unrestrictedSearchResults(**query)

def setHeader(self, *args):
"""
Expand Down Expand Up @@ -192,12 +191,7 @@ def __call__(self):
booking_creation_to = self.request.get("booking_creation_to")
self.path = self.request.get("booking_folder_path")

if not booking_start_from:
self.booking_start_from = datetime.datetime.now().replace(
hour=0, minute=0, second=0, microsecond=0
)

else:
if booking_start_from:
try:
self.booking_start_from = datetime.datetime.fromisoformat(
booking_start_from
Expand All @@ -207,11 +201,7 @@ def __call__(self):
api.portal_translate(_("Badly composed `booking_start_from` value"))
)

if not booking_start_to:
self.booking_start_to = datetime.datetime.now().replace(
hour=23, minute=59, second=0, microsecond=0
)
else:
if booking_start_to:
try:
self.booking_start_to = datetime.datetime.fromisoformat(
booking_start_to
Expand Down

0 comments on commit 661ec56

Please sign in to comment.