source: products/vendor/Products.CacheSetup/current/Products/CacheSetup/content/template_cache_rule.py @ 3296

Last change on this file since 3296 was 3296, checked in by fenix, 13 years ago

Load Products.CacheSetup?-1.2.1 into vendor/Products.CacheSetup?/current.

  • Property svn:eol-style set to native
File size: 2.9 KB
Line 
1"""
2CacheSetup
3~~~~~~~~~~~~~~~~~~~~~~~~~~~
4
5$Id: $
6"""
7
8__authors__ = 'Geoff Davis <geoff@geoffdavis.net>'
9__docformat__ = 'restructuredtext'
10
11from AccessControl import ClassSecurityInfo
12
13from Products.CMFCore import permissions
14
15from Products.Archetypes.atapi import BaseContent
16from Products.Archetypes.atapi import registerType
17from Products.Archetypes.atapi import Schema
18
19from Products.Archetypes.atapi import LinesField
20from Products.Archetypes.atapi import TextField
21
22from Products.Archetypes.atapi import LinesWidget
23from Products.Archetypes.atapi import TextAreaWidget
24
25from Products.CacheSetup.config import PROJECT_NAME
26import base_cache_rule as BaseCacheRule
27
28schema = BaseContent.schema.copy() + Schema((
29
30    TextField(
31        'description',
32        required=0,
33        allowable_content_types = ('text/plain',),
34        default='A cache rule for page templates',
35        write_permission = permissions.ManagePortal,
36        widget=TextAreaWidget(
37            label='Description',
38            cols=60,
39            rows=5,
40            description='Basic documentation for this cache rule')),
41
42    LinesField(
43        'templates',
44        write_permission = permissions.ManagePortal,
45        widget=LinesWidget(
46            label='Templates',
47            description='Please indicate the template IDs to which this rule applies')),
48
49    )) + BaseCacheRule.header_set_schema + BaseCacheRule.etag_schema
50
51schema['id'].widget.ignore_visible_ids=True                       
52schema['id'].widget.description="Should not contain spaces, underscores or mixed case. An 'X-Caching-Rule-Id' header with this id will be added."
53
54
55class TemplateCacheRule(BaseCacheRule.BaseCacheRule):
56    """
57    """
58    security = ClassSecurityInfo()
59    archetype_name = 'Template Cache Rule'
60    portal_type = meta_type = 'TemplateCacheRule'
61    __implements__ = BaseCacheRule.BaseCacheRule.__implements__
62    schema = schema
63    _at_rename_after_creation = True
64
65    actions = (
66        {'action':      'string:$object_url',
67         'category':    'object',
68         'id':          'view',
69         'name':        'Cache Setup',
70         'permissions': (permissions.ManagePortal,),
71         'visible':     False},
72    )
73
74    aliases = {
75        '(Default)':    'cache_policy_item_config',
76        'view' :        'cache_policy_item_config',
77        'edit' :        'cache_policy_item_config'
78    }
79
80    security.declarePublic('getHeaderSet')
81    def getHeaderSet(self, request, object, view, member):
82        # see if this rule applies
83        if not view in self.getTemplates():
84            return None
85
86        header_set = self._getHeaderSet(request, object, view, member)
87
88        # associate template with PageCacheManager
89        if header_set and header_set.getPageCache():
90            self._associateTemplate(object, view)
91           
92        return header_set
93
94registerType(TemplateCacheRule, PROJECT_NAME)
95
96__all__ = (
97    'TemplateCacheRule',
98)
Note: See TracBrowser for help on using the repository browser.