Skip to content

Commit

Permalink
Merge 89f84cb into 5c85354
Browse files Browse the repository at this point in the history
  • Loading branch information
keul committed Aug 17, 2015
2 parents 5c85354 + 89f84cb commit 15776f6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
7 changes: 5 additions & 2 deletions CHANGES.rst
Expand Up @@ -4,8 +4,11 @@ Changelog
1.0b4 (unreleased)
^^^^^^^^^^^^^^^^^^

- Nothing changed yet.

- Fixed and issue with default review_states set, that was of tuple type,
so catalog uncompatible
[keul]
- Fixed logic issues with ``start`` and ``end`` criteria used by collections
[keul]

1.0b3 (2015-07-07)
^^^^^^^^^^^^^^^^^^
Expand Down
14 changes: 9 additions & 5 deletions collective/portlet/calendar/calendar.py
Expand Up @@ -36,7 +36,7 @@ def add_cachekey(key, brain):
def _define_search_options(renderer, options):
"""Obtain a proper query to be used in search"""
catalog = getToolByName(renderer.context, 'portal_catalog')
all_review_states = catalog.uniqueValuesFor('review_state')
all_review_states = list(catalog.uniqueValuesFor('review_state'))
if not options:
# Folder, or site root.
options['path'] = renderer.root()
Expand All @@ -49,7 +49,8 @@ def _define_search_options(renderer, options):
# Type check: seems that new style collections are returning parameters as tuples
# this is not compatible with ZTUtils.make_query
untuple(options)
# We must handle in a special way "start" and "end" criteria
# We must handle in a special way "start" and "end" criteria as they are commonly
# already handled by calend machinery itself
if 'start' in options.keys():
renderer._fix_range_criteria('start')
if 'end' in options.keys():
Expand Down Expand Up @@ -257,7 +258,6 @@ def _fix_range_criteria(self, index):
criteria = self.options[index]
if not isinstance(criteria['query'], list):
criteria['query'] = [criteria['query']]

# New style collection return a string for date criteria... awful but true
criteria['query'] = [DateTime(d) if isinstance(d, basestring) else d for d in criteria['query']]
# keep only dates inside the current month
Expand All @@ -266,12 +266,16 @@ def _fix_range_criteria(self, index):
if index == 'start':
last_day = self.calendar._getCalendar().monthrange(year, month)[1]
calendar_date = self.calendar.getBeginAndEndTimes(last_day, month, year)[1]
criteria['query'].append(calendar_date)
# add the last day in the month only if smaller than collection's date
if not criteria['query'] or calendar_date < max(criteria['query']) or criteria['range'] != 'max':
criteria['query'].append(calendar_date)
if criteria['range'] == 'min':
criteria['range'] = 'minmax'
elif index == 'end':
calendar_date = self.calendar.getBeginAndEndTimes(1, month, year)[0]
criteria['query'].append(calendar_date)
# add the fist day in the month only if greater than collection's date
if not criteria['query'] or calendar_date > min(criteria['query']) or criteria['range'] != 'min':
criteria['query'].append(calendar_date)
if criteria['range'] == 'max':
criteria['range'] = 'minmax'
self.options[index] = criteria
Expand Down
20 changes: 17 additions & 3 deletions collective/portlet/calendar/tests/test_calendarex.py
Expand Up @@ -110,7 +110,7 @@ def test_fix_range_criteria_start(self):
renderer.options = {'start': {'query': d1, 'range': 'max'}}
renderer._fix_range_criteria('start')
self.assertEqual(renderer.options,
{'start': {'query': [d1, self.last_date],
{'start': {'query': [d1],
'range': 'max'}})
d1 = DateTime('2014/05/10')
d2 = DateTime('2014/06/08')
Expand All @@ -119,6 +119,12 @@ def test_fix_range_criteria_start(self):
self.assertEqual(renderer.options,
{'start': {'query': [d1, self.last_date],
'range': 'minmax'}})
d1 = DateTime('2014/06/26')
renderer.options = {'start': {'query': [d1], 'range': 'max'}}
renderer._fix_range_criteria('start')
self.assertEqual(renderer.options,
{'start': {'query': [self.last_date],
'range': 'max'}})

def test_fix_range_criteria_start_new_collection(self):
# WTF: new style collections are returning "strings"
Expand All @@ -133,7 +139,7 @@ def test_fix_range_criteria_start_new_collection(self):
renderer.options = {'start': {'query': d1, 'range': 'max'}}
renderer._fix_range_criteria('start')
self.assertEqual(renderer.options,
{'start': {'query': [d1, self.last_date],
{'start': {'query': [d1],
'range': 'max'}})
d1 = DateTime('2014/05/10')
d2 = DateTime('2014/06/08')
Expand All @@ -155,7 +161,7 @@ def test_fix_range_criteria_end(self):
renderer.options = {'end': {'query': d1, 'range': 'min'}}
renderer._fix_range_criteria('end')
self.assertEqual(renderer.options,
{'end': {'query': [d1, self.first_date],
{'end': {'query': [d1],
'range': 'min'}})
d1 = DateTime('2014/02/05')
d2 = DateTime('2014/05/15')
Expand All @@ -164,6 +170,12 @@ def test_fix_range_criteria_end(self):
self.assertEqual(renderer.options,
{'end': {'query': [d2, self.first_date],
'range': 'minmax'}})
d1 = DateTime('2014/04/02')
renderer.options = {'end': {'query': d1, 'range': 'min'}}
renderer._fix_range_criteria('end')
self.assertEqual(renderer.options,
{'end': {'query': [self.first_date],
'range': 'min'}})


class TestRenderer(unittest.TestCase):
Expand Down Expand Up @@ -300,6 +312,7 @@ def test_event_created_last_day_of_month_invalidate_cache(self):
# First render the calendar portlet when there's no events
self.portal.REQUEST['ACTUAL_URL'] = self.portal.REQUEST['SERVER_URL']
r = self.renderer(assignment=calendar.Assignment())
r.update()
html = r.render()

# Now let's add a new event in the last day of the current month
Expand All @@ -317,6 +330,7 @@ def test_event_created_last_day_of_month_invalidate_cache(self):

# Try to render the calendar portlet again, it must be different now
r = self.renderer(assignment=calendar.Assignment())
r.update()
self.assertNotEqual(html, r.render(), "Cache key wasn't invalidated")

def testEventsPathSearch(self):
Expand Down

0 comments on commit 15776f6

Please sign in to comment.