Esempio n. 1
0
    def __call__(self):

        # 1. Attempt to look up a ruleset using the default lookup
        ruleset = lookup(self.published)
        if ruleset is not None:
            return ruleset

        registry = queryUtility(IRegistry)
        if registry is None:
            return None

        ploneCacheSettings = registry.forInterface(
            IPloneCacheSettings, check=False)

        # 2. Get the name of the published object
        name = getattr(self.published, '__name__', None)
        if name is None:
            return None

        # 3. Look up the published name in the page template mapping
        if ploneCacheSettings.templateRulesetMapping is not None:
            ruleset = ploneCacheSettings.templateRulesetMapping.get(name, None)
            if ruleset is not None:
                return ruleset

        # 4. Find the parent of the published object
        parent = getattr(self.published, '__parent__', None)
        if parent is None:
            return None

        # 4.1. If the parent is a content object:
        parentPortalType = getattr(aq_base(parent), 'portal_type', None)
        if parentPortalType is None:
            return None

        # 4.1.1. Get the default view of the parent content object
        defaultView = getObjectDefaultView(parent)

        # 4.1.2. If the name of the published object is the same as the
        # default view of the parent:
        if defaultView != name:
            return None

        # 4.1.2.1. Look up the parent type in the content type
        # mapping
        if ploneCacheSettings.contentTypeRulesetMapping is not None:
            ruleset = ploneCacheSettings.contentTypeRulesetMapping.get(
                parentPortalType,
                None
            )
            if ruleset is not None:
                return ruleset

        # 4.1.2.2. Look up a ruleset on the parent object and
        # return
        ruleset = lookup(parent)
        if ruleset is not None:
            return ruleset
Esempio n. 2
0
    def __call__(self):

        # 1. Attempt to look up a ruleset using the default lookup
        ruleset = lookup(self.published)
        if ruleset is not None:
            return ruleset

        registry = queryUtility(IRegistry)
        if registry is None:
            return None

        ploneCacheSettings = registry.forInterface(
            IPloneCacheSettings, check=False)

        # 2. Get the name of the published object
        name = getattr(self.published, '__name__', None)
        if name is None:
            return None

        # 3. Look up the published name in the page template mapping
        if ploneCacheSettings.templateRulesetMapping is not None:
            ruleset = ploneCacheSettings.templateRulesetMapping.get(name, None)
            if ruleset is not None:
                return ruleset

        # 4. Find the parent of the published object
        parent = getattr(self.published, '__parent__', None)
        if parent is None:
            return None

        # 4.1. If the parent is a content object:
        parentPortalType = getattr(aq_base(parent), 'portal_type', None)
        if parentPortalType is None:
            return None

        # 4.1.1. Get the default view of the parent content object
        defaultView = getObjectDefaultView(parent)

        # 4.1.2. If the name of the published object is the same as the
        # default view of the parent:
        if defaultView != name:
            return None

        # 4.1.2.1. Look up the parent type in the content type
        # mapping
        if ploneCacheSettings.contentTypeRulesetMapping is not None:
            ruleset = ploneCacheSettings.contentTypeRulesetMapping.get(
                parentPortalType,
                None,
            )
            if ruleset is not None:
                return ruleset

        # 4.1.2.2. Look up a ruleset on the parent object and
        # return
        ruleset = lookup(parent)
        if ruleset is not None:
            return ruleset
Esempio n. 3
0
 def test_most_specific_interface_wins(self):
     from z3c.caching.registry import register, lookup
     register(ITestView, "frop")
     register(IMoreSpecificTestView, "fribble")
     i=OtherTestView()
     self.assertEqual(lookup(i), "fribble")
Esempio n. 4
0
 def test_ruleset_for_interface(self):
     from z3c.caching.registry import register, lookup
     register(ITestView, "frop")
     i=TestView()
     self.assertEqual(lookup(i), "frop")
Esempio n. 5
0
 def test_no_ruleset_returned_if_unregistered(self):
     from z3c.caching.registry import lookup
     self.failUnless(lookup(None) is None)
Esempio n. 6
0
 def __call__(self):
     return lookup(self.published)
 def test_no_ruleset_returned_if_unregistered(self):
     from z3c.caching.registry import lookup
     self.assertIsNone(lookup(None))
Esempio n. 8
0
 def test_lookup(self):
     from z3c.caching.registry import lookup
     self.assertEquals(None, lookup(TestView))
Esempio n. 9
0
 def test_unregistering_ruleset_removes_ruleset(self):
     from z3c.caching.registry import register, unregister, lookup
     register(TestView, "frop")
     unregister(TestView)
     self.failUnless(lookup(TestView) is None)
Esempio n. 10
0
 def test_most_specific_interface_wins(self):
     from z3c.caching.registry import register, lookup
     register(ITestView, "frop")
     register(IMoreSpecificTestView, "fribble")
     i = OtherTestView()
     self.assertEqual(lookup(i), "fribble")
Esempio n. 11
0
 def test_ruleset_for_interface(self):
     from z3c.caching.registry import register, lookup
     register(ITestView, "frop")
     i = TestView()
     self.assertEqual(lookup(i), "frop")
Esempio n. 12
0
 def test_no_ruleset_returned_if_unregistered(self):
     from z3c.caching.registry import lookup
     self.failUnless(lookup(None) is None)
Esempio n. 13
0
 def test_lookup(self):
     from z3c.caching.registry import lookup
     self.assertIsNone(lookup(TestView))
Esempio n. 14
0
 def test_unregistering_nonexistant_ruleset_doesnt_error(self):
     from z3c.caching.registry import unregister, lookup
     self.assertIsNone(lookup(TestView))
     unregister(TestView)
     self.assertIsNone(lookup(TestView))
Esempio n. 15
0
 def test_unregistering_ruleset_removes_ruleset(self):
     from z3c.caching.registry import register, unregister, lookup
     register(TestView, "frop")
     unregister(TestView)
     self.failUnless(lookup(TestView) is None)
Esempio n. 16
0
 def test_unregistering_nonexistant_ruleset_doesnt_error(self):
     from z3c.caching.registry import unregister, lookup
     self.failUnless(lookup(TestView) is None)
     unregister(TestView)
     self.failUnless(lookup(TestView) is None)
Esempio n. 17
0
 def test_unregistering_nonexistant_ruleset_doesnt_error(self):
     from z3c.caching.registry import unregister, lookup
     self.failUnless(lookup(TestView) is None)
     unregister(TestView)
     self.failUnless(lookup(TestView) is None)
Esempio n. 18
0
 def __call__(self):
     return lookup(self.published)
Esempio n. 19
0
 def test_lookup(self):
     from z3c.caching.registry import lookup
     self.assertEquals(None, lookup(TestView))