Skip to content

Commit

Permalink
Doc
Browse files Browse the repository at this point in the history
  • Loading branch information
folix-01 committed Nov 22, 2024
1 parent 06e085e commit 5a91f0d
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 15 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.7.10 (unreleased)
-------------------

- Nothing changed yet.
- Extend bookings-export filters.
[folix-01]


2.7.9 (2024-10-09)
Expand Down
9 changes: 7 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -798,10 +798,15 @@ The script is located at src/redturtle/prenotazioni/scripts/notify_upcoming_book
@@bookings-export
-----------------

Export bookings by passed **date** in ISO format or today by default.
All the parameters below are ISO formatted datetime strings
**booking_start_from** - booking start from range.
**booking_start_to** - booking start to range.
**booking_creation_from** - booking created from range.
**booking_creation_to** - bookking createtd to range
**path** - booking folder path

Example::
curl -i http://localhost:8080/Plone/@@bookings-export?date=2024-06-21
curl -i http://localhost:8080/Plone/@@bookings-export?booking_start_from=2023-10-22T12:27:18

Response::
Binary csv file
Expand Down
59 changes: 47 additions & 12 deletions src/redturtle/prenotazioni/browser/bookings_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@

class BookingsExport(BrowserView):
filename = "Bookings_export"
date = None
booking_start_from = None
booking_start_to = None
booking_creation_from = None
booking_creation_to = None
path = None

@property
def csv_fields(self):
Expand Down Expand Up @@ -58,7 +62,6 @@ def csv_filename(self):

@property
def brains(self):

return api.portal.get_tool("portal_catalog").unrestrictedSearchResults(
portal_type="Prenotazione",
Date={
Expand All @@ -70,6 +73,26 @@ def brains(self):
},
review_state="confirmed",
sort_on="Date",
path=self.path and {"query": self.path} or "",
created=(self.booking_creation_from or self.booking_creation_to)
and {
"query": (self.booking_creation_from and self.booking_creation_to)
and (
get_default_timezone(True).localize(self.booking_creation_from),
get_default_timezone(True).localize(self.booking_creation_to),
)
or self.booking_creation_from
and get_default_timezone(True).localize(self.booking_creation_from)
or self.booking_creation_to
and get_default_timezone(True).localize(self.booking_creation_to),
"range": (self.booking_creation_from and self.booking_creation_to)
and "min:max"
or self.booking_creation_from
and "min"
or self.booking_creation_to
and "max",
}
or "",
)

def setHeader(self, *args):
Expand Down Expand Up @@ -150,37 +173,49 @@ def get_csv(self):
def __call__(self):
booking_start_from = self.request.get("booking_start_from")
booking_start_to = self.request.get("booking_start_to")
booking_creation_from = self.request.get("booking_creation_from")
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.combine(
datetime.date.today(), datetime.datetime.min.time()
self.booking_start_from = datetime.datetime.now().replace(
hour=0, minute=0, second=0, microsecond=0
)

else:
try:
self.booking_start_from = datetime.datetime.combine(
datetime.date.fromisoformat(booking_start_from),
datetime.datetime.min.time(),
self.booking_start_from = datetime.datetime.fromisoformat(
booking_start_from
)
except ValueError:
raise BadRequest(
api.portal_translate(_("Badly composed `booking_start_from` value"))
)

if not booking_start_to:
self.booking_start_to = datetime.datetime.combine(
datetime.date.today(), datetime.datetime.min.time()
self.booking_start_to = datetime.datetime.now().replace(
hour=23, minute=59, second=0, microsecond=0
)
else:
try:
self.booking_start_to = datetime.datetime.combine(
datetime.date.fromisoformat(booking_start_to),
datetime.datetime.min.time(hour=23, minute=59),
self.booking_start_to = datetime.datetime.fromisoformat(
booking_start_to
)
except ValueError:
raise BadRequest(
api.portal_translate(_("Badly composed `booking_start_to` value"))
)

if booking_creation_from:
self.booking_creation_from = datetime.datetime.fromisoformat(
booking_creation_from
)

if booking_creation_to:
self.booking_creation_to = datetime.datetime.fromisoformat(
booking_creation_to
)

self.setHeader(
"Content-Disposition", "attachment;filename=%s" % self.csv_filename
)
Expand Down

0 comments on commit 5a91f0d

Please sign in to comment.