Skip to content

Commit

Permalink
added right query formatting for events start/end date. ref #554
Browse files Browse the repository at this point in the history
  • Loading branch information
sauzher committed Oct 18, 2024
1 parent 7e4eb81 commit d13cc14
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions src/isaw.theme/isaw/theme/browser/event_listing.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
from isaw.theme.browser.interfaces import IEventListingView
from isaw.theme.browser.interfaces import IISAWSettings
from isaw.theme.browser.tiled_view import TiledListingView
from plone.app.event.browser.event_listing import EventListing
from plone.app.event.base import start_end_from_mode
from plone.app.event.base import guess_date_from


@implementer(IEventListingView)
Expand All @@ -35,8 +38,27 @@ def format_date(self, date):
DateTime(date), True, False, self.context)
return date

@property
def date(self):
dt = None
if self._date:
try:
dt = guess_date_from(self._date)
except TypeError:
pass
return dt

@property
def _start_end(self):
start, end = start_end_from_mode(self.mode, self.date, self.context)
return start, end

def listings(self, b_start=None, b_size=None):
"""get a page of listings"""
req = self.request.form
self._date = 'date' in req and req['date'] or None
self.mode = 'mode' in req and req['mode'] or None

if b_size is None:
b_size = self.batch_size
if b_start is None:
Expand All @@ -62,11 +84,15 @@ def listings(self, b_start=None, b_size=None):
content_filter['start'] = {'query': DateTime(), 'range': 'min'}

start = self.request.get('start')
if start:
content_filter['start'] = start
end = self.request.get('end')

start, end = self._start_end

if start:
content_filter['start'] = {'query': start, 'range': 'min'}
if end:
content_filter['end'] = end
content_filter['end'] = {'query': end, 'range': 'max'}

if is_collection:
batch = self.context.results(batch=True, b_start=b_start,
b_size=b_size, brains=True,
Expand Down

0 comments on commit d13cc14

Please sign in to comment.