def __call___cachekey(method, self): '''cachekey method for self.__call__. Cache is invalidated depending on : - current user may edit or not; - something is redefined for current item or not.''' # when using raw fields (assembly, absents, signatures, ...) # we invalidate if a raw value changed date = get_cachekey_volatile( 'Products.PloneMeeting.browser.async.AsyncLoadItemAssemblyAndSignaturesRawFields' ) tool = api.portal.get_tool('portal_plonemeeting') cfg = tool.getMeetingConfig(self.context) cfg_modified = cfg.modified() # cache will be invalidated if something changed about attendees on meeting meeting = self.context.getMeeting() ordered_contacts = meeting.ordered_contacts.items() redefined_item_attendees = meeting._get_all_redefined_attendees( only_keys=False) show_votes = self.context.show_votes() item_votes = self.context.get_item_votes(include_vote_number=False) context_uid = self.context.UID() item_attendees_order = meeting._get_item_attendees_order(context_uid) # if something redefined for context or not if context_uid not in str(redefined_item_attendees): redefined_item_attendees = [] may_change_attendees = self.context._mayChangeAttendees() poll_type = self.context.getPollType() cache_date = self.request.get('cache_date', None) return (date, context_uid, cfg_modified, ordered_contacts, redefined_item_attendees, item_attendees_order, show_votes, item_votes, may_change_attendees, poll_type, cache_date)
def test_get_cachekey_volatile(self): """Helper method that adds a volatile on the portal storing current date.""" method_name = 'My method' plone_utils = api.portal.get_tool('plone_utils') normalized_name = plone_utils.normalizeString(method_name) volatile_name = '_v_{0}'.format(normalized_name) self.assertIsNone(getattr(self.portal, volatile_name, None)) # calling the method will set the volatile on the portal date = get_cachekey_volatile(method_name) self.assertTrue(isinstance(date, datetime)) self.assertTrue(isinstance(getattr(self.portal, volatile_name), datetime)) # calling it again will still return same date self.assertEquals(date, get_cachekey_volatile(method_name)) # volatiles are not removed by tearDown, remove it now to avoid # test isolation issues with test test_invalidate_cachekey_volatile_for invalidate_cachekey_volatile_for(method_name)
def _check_date(item, modified_date, volatile_date): '''Check that item modified date was updated.''' new_modified_date = item.modified() self.assertNotEqual(modified_date, new_modified_date) new_volatile_date = get_cachekey_volatile( 'Products.PloneMeeting.MeetingItem.modified') self.assertNotEqual(volatile_date, new_volatile_date) return new_modified_date, new_volatile_date
def test_invalidate_cachekey_volatile_for(self): """Helper method that will invalidate a given volatile.""" method_name = 'My method' plone_utils = api.portal.get_tool('plone_utils') normalized_name = plone_utils.normalizeString(method_name) volatile_name = '_v_{0}'.format(normalized_name) self.assertIsNone(getattr(self.portal, volatile_name, None)) # calling the method if volatile does not exist does not break invalidate_cachekey_volatile_for(method_name) # set it now first_date = get_cachekey_volatile(method_name) self.assertTrue(isinstance(first_date, datetime)) invalidate_cachekey_volatile_for(method_name) self.assertIsNone(getattr(self.portal, volatile_name, None)) # if get_cachekey_volatile is called and volatile does not exist, it is created with datetime.now() second_date = get_cachekey_volatile(method_name) self.assertTrue(first_date < second_date)
def test_get_cachekey_volatile(self): """Helper method that adds a volatile on the portal storing current date.""" method_name = 'My method' plone_utils = api.portal.get_tool('plone_utils') normalized_name = plone_utils.normalizeString(method_name) volatile_name = normalized_name self.assertIsNone(getattr(self.portal, volatile_name, None)) # calling the method will set the volatile on the portal date = get_cachekey_volatile(method_name) self.assertTrue(isinstance(date, datetime)) volatiles = getattr(self.portal, VOLATILE_ATTR, {}) self.assertTrue(isinstance(volatiles.get(volatile_name), datetime)) # calling it again will still return same date self.assertEquals(date, get_cachekey_volatile(method_name)) # volatiles are not removed by tearDown, remove it now to avoid # test isolation issues with test test_invalidate_cachekey_volatile_for invalidate_cachekey_volatile_for(method_name)
def test_invalidate_cachekey_volatile_for(self): """Helper method that will invalidate a given volatile.""" method_name = 'My method' plone_utils = api.portal.get_tool('plone_utils') normalized_name = plone_utils.normalizeString(method_name) volatile_name = normalized_name self.assertIsNone(getattr(self.portal, volatile_name, None)) # calling the method if volatile does not exist does not break invalidate_cachekey_volatile_for(method_name) # set it now first_date = get_cachekey_volatile(method_name) self.assertTrue(isinstance(first_date, datetime)) invalidate_cachekey_volatile_for(method_name) self.assertIsNone(getattr(self.portal, volatile_name, None)) # if get_cachekey_volatile is called and volatile does not exist, it is created with datetime.now() second_date = get_cachekey_volatile(method_name) self.assertTrue(first_date < second_date)
def __call___cachekey(method, self, context): '''cachekey method for self.__call__.''' date = get_cachekey_volatile( 'Products.PloneMeeting.vocabularies.ftwlabelsforfacetedfiltervocabulary' ) tool = api.portal.get_tool('portal_plonemeeting') cfg = tool.getMeetingConfig(context) # personal labels include current user id return date, cfg.getId(), cfg.modified(), get_current_user_id( context.REQUEST)
def render_cachekey(method, self): '''cachekey method for self.__call__.''' userGroups = self.tool.get_plone_groups_for_user() # URL to the item can change if server URL changed server_url = self.request.get('SERVER_URL', None) # cache until an item is modified date = get_cachekey_volatile( 'Products.PloneMeeting.MeetingItem.modified') load_portlet_todo = self.request.get('load_portlet_todo', False) return (repr(self.cfg), userGroups, server_url, date, load_portlet_todo)
def __call___cachekey(method, self): '''cachekey method for self.__call__.''' tool = api.portal.get_tool('portal_plonemeeting') userGroups = tool.get_plone_groups_for_user() cfg = tool.getMeetingConfig(self.context) cfg_modified = cfg.modified() # URL to the annex_type can change if server URL changed server_url = self.request.get('SERVER_URL', None) # cache until a meeting is modified date = get_cachekey_volatile('Products.PloneMeeting.Meeting.modified') # return meeting.UID if we are on a meeting or None if not # as portlet is highlighting the meeting we are on meeting_uid = self.context.__class__.__name__ == 'Meeting' and self.context.UID( ) or None collection_uid = self.request.get('collection_uid') return (userGroups, cfg_modified, server_url, date, meeting_uid, collection_uid)
def __call___cachekey(method, self): '''cachekey method for self.__call__. Cache is invalidated depending on : - current user may edit or not; - something is redefined for current item or not.''' date = get_cachekey_volatile( 'Products.PloneMeeting.browser.async.AsyncLoadMeetingAssemblyAndSignatures' ) tool = api.portal.get_tool('portal_plonemeeting') cfg = tool.getMeetingConfig(self.context) is_manager = tool.isManager(cfg) cfg_modified = cfg.modified() ordered_contacts = self.context.ordered_contacts.items() item_votes = sorted(self.context.get_item_votes().items()) cache_date = self.request.get('cache_date', None) return (date, is_manager, cfg_modified, ordered_contacts, item_votes, repr(self.context), cache_date)
def __call__(self): context = getContext(self.published) res = 'lm_0' if context.meta_type == 'MeetingItem': meeting = context.getMeeting() if meeting: res = 'lm_' + _modified(meeting) elif context.portal_type == 'Folder': # in case this is a meeting folder # we return last Meeting modified when using MeetingConfig.redirectToNextMeeting tool = api.portal.get_tool('portal_plonemeeting') cfg = tool.getMeetingConfig(context) if cfg and cfg.getRedirectToNextMeeting(): # this changes when meeting added/removed/date changed meeting_date_last_modified = get_cachekey_volatile( 'Products.PloneMeeting.Meeting.date') res = 'lm_' + _modified(date=meeting_date_last_modified) return res
def test_FinancesAdvicesWorkflow(self): """ Test finances advices workflow. """ def _check_date(item, modified_date, volatile_date): '''Check that item modified date was updated.''' new_modified_date = item.modified() self.assertNotEqual(modified_date, new_modified_date) new_volatile_date = get_cachekey_volatile( 'Products.PloneMeeting.MeetingItem.modified') self.assertNotEqual(volatile_date, new_volatile_date) return new_modified_date, new_volatile_date cfg = self.meetingConfig self.changeUser('dgen') gic1_uid = cfg.getOrderedGroupsInCharge()[0] item = self.create('MeetingItem', groupsInCharge=(gic1_uid, )) item_uid = item.UID() self.assertEqual(self.transitions(item), ['proposeToValidationLevel1']) # ask finances advice fin_group_uid = finance_group_uid() item.setOptionalAdvisers((fin_group_uid + '__rowid__unique_id_002', )) item._update_after_edit() # advice still not askable, askable as level2 or level3 self.assertEqual(self.transitions(item), ['proposeToValidationLevel1']) self.do(item, 'proposeToValidationLevel1') self.assertEqual(self.transitions(item), ['backToItemCreated', 'proposeToValidationLevel2']) self.do(item, 'proposeToValidationLevel2') self.assertEqual(self.transitions(item), [ 'backToProposedToValidationLevel1', 'proposeToValidationLevel3', 'wait_advices_from_proposedToValidationLevel2' ]) self.do(item, 'wait_advices_from_proposedToValidationLevel2') # a MeetingManager is able to send back but not a normal user self.assertEqual(self.transitions(item), [ 'backTo_proposedToValidationLevel2_from_waiting_advices', 'backTo_proposedToValidationLevel3_from_waiting_advices', 'backTo_validated_from_waiting_advices' ]) # but a self._addPrincipalToGroup('bourgmestre', self.dirgen_creators) self._addPrincipalToGroup('bourgmestre', self.dirgen_level1reviewers) self._addPrincipalToGroup('bourgmestre', self.dirgen_level2reviewers) self._addPrincipalToGroup('bourgmestre', self.dirgen_level3reviewers) self.changeUser('bourgmestre') self.assertTrue(self.hasPermission("View", item)) self.assertEqual(self.transitions(item), []) # give advice self.changeUser('dfin') self.assertEqual(self.transitions(item), [ 'backTo_proposedToValidationLevel2_from_waiting_advices', 'backTo_proposedToValidationLevel3_from_waiting_advices' ]) # advice may be taken over self.assertTrue(item.adapted().mayTakeOver()) # advice giveable when item complete self.assertFalse(item.adviceIndex[fin_group_uid]['advice_addable']) self.assertTrue(item.adapted().mayEvaluateCompleteness()) # we will check that item modified date is invalidated when advice changed # this is responsible for updating collections counter in faceted portlet volatile_date = get_cachekey_volatile( 'Products.PloneMeeting.MeetingItem.modified') item_modified = item.modified() item.setCompleteness('completeness_complete') item._update_after_edit() item_modified, volatile_date = _check_date(item, item_modified, volatile_date) advice_portal_type = item._advicePortalTypeForAdviser(fin_group_uid) advice = self.addAdvice(item, advice_group=fin_group_uid, advice_type='positive_finance', advice_portal_type=advice_portal_type) # item modified date was updated item_modified, volatile_date = _check_date(item, item_modified, volatile_date) self.assertTrue(advice.advice_hide_during_redaction) self.assertEqual(self.transitions(advice), ['proposeToFinancialController']) # once advice given but hidden during redaction, item may no more be sent back self.assertEqual(self.transitions(item), []) # financial controller self.do(advice, 'proposeToFinancialController') self.assertEqual(self.transitions(item), []) self.assertEqual(self.transitions(advice), ['backToAdviceCreated', 'proposeToFinancialEditor']) # indexAdvisers is correctly reindexed advice_index_value = "delay__{0}_proposed_to_financial_controller".format( fin_group_uid) self.assertTrue( self.catalog(UID=item_uid, indexAdvisers=[advice_index_value])) # item modified date was updated item_modified, volatile_date = _check_date(item, item_modified, volatile_date) # financial editor self.do(advice, 'proposeToFinancialEditor') self.assertEqual(self.transitions(advice), [ 'backToProposedToFinancialController', 'proposeToFinancialReviewer' ]) # indexAdvisers is correctly reindexed advice_index_value = "delay__{0}_proposed_to_financial_editor".format( fin_group_uid) self.assertTrue( self.catalog(UID=item_uid, indexAdvisers=[advice_index_value])) # item modified date was updated item_modified, volatile_date = _check_date(item, item_modified, volatile_date) # financial reviewer self.do(advice, 'proposeToFinancialReviewer') self.assertEqual(self.transitions(item), []) self.assertEqual(self.transitions(advice), [ 'backToProposedToFinancialController', 'backToProposedToFinancialEditor', 'proposeToFinancialManager' ]) # indexAdvisers is correctly reindexed advice_index_value = "delay__{0}_proposed_to_financial_reviewer".format( fin_group_uid) self.assertTrue( self.catalog(UID=item_uid, indexAdvisers=[advice_index_value])) # item modified date was updated item_modified, volatile_date = _check_date(item, item_modified, volatile_date) # financial manager self.do(advice, 'proposeToFinancialManager') self.assertEqual(self.transitions(item), []) self.assertEqual(self.transitions(advice), [ 'backToProposedToFinancialController', 'backToProposedToFinancialReviewer', 'signFinancialAdvice' ]) # indexAdvisers is correctly reindexed advice_index_value = "delay__{0}_proposed_to_financial_manager".format( fin_group_uid) self.assertTrue( self.catalog(UID=item_uid, indexAdvisers=[advice_index_value])) # item modified date was updated item_modified, volatile_date = _check_date(item, item_modified, volatile_date) # sign advice self.do(advice, 'signFinancialAdvice') self.assertEqual(self.transitions(item), [ 'backTo_proposedToValidationLevel2_from_waiting_advices', 'backTo_proposedToValidationLevel3_from_waiting_advices', 'backTo_validated_from_waiting_advices' ]) self.assertEqual(self.transitions(advice), ['backToProposedToFinancialManager']) self.assertFalse(advice.advice_hide_during_redaction) # indexAdvisers is correctly reindexed advice_index_value = "delay__{0}_financial_advice_signed".format( fin_group_uid) self.assertTrue( self.catalog(UID=item_uid, indexAdvisers=[advice_index_value])) # item modified date was updated item_modified, volatile_date = _check_date(item, item_modified, volatile_date) # validate item self.do(item, 'backTo_validated_from_waiting_advices') self.assertEqual(item.query_state(), 'validated') # indexAdvisers is correctly reindexed advice_index_value = "delay__{0}_advice_given".format(fin_group_uid) self.assertTrue( self.catalog(UID=item_uid, indexAdvisers=[advice_index_value])) # item modified date was updated item_modified, volatile_date = _check_date(item, item_modified, volatile_date)
def list_wf_states_cache_key(function, context, portal_type): return get_cachekey_volatile("%s.%s" % (function.func_name, portal_type))
def voc_cache_key(method, self, context): return get_cachekey_volatile("%s.%s" % (self.__class__.__module__, self.__class__.__name__))
def list_wf_states_cache_key(function, context, portal_type): return get_cachekey_volatile("%s.%s" % (function.func_name, portal_type))
def voc_cache_key(method, self, context): """Returns a persistent portal stored date following the given cache key. Must be programatically invalidated.""" return get_cachekey_volatile( "%s.%s" % (self.__class__.__module__, self.__class__.__name__))
def voc_cache_key(method, self, context): return get_cachekey_volatile( "%s.%s" % (self.__class__.__module__, self.__class__.__name__))