Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove @bookings-export default filter values #221

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Changelog
------------------

- Fix translation mechanism for exceptions.
- bookings-export remove default filter values.
[folix-01]


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