1 | """ |
---|
2 | CacheSetup |
---|
3 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
4 | |
---|
5 | $Id: $ |
---|
6 | """ |
---|
7 | |
---|
8 | __authors__ = 'Geoff Davis <geoff@geoffdavis.net>' |
---|
9 | __docformat__ = 'restructuredtext' |
---|
10 | |
---|
11 | from AccessControl import ClassSecurityInfo |
---|
12 | |
---|
13 | from Products.CMFCore import permissions |
---|
14 | |
---|
15 | from Products.Archetypes.atapi import BaseContent |
---|
16 | from Products.Archetypes.atapi import registerType |
---|
17 | from Products.Archetypes.atapi import Schema |
---|
18 | |
---|
19 | from Products.Archetypes.atapi import LinesField |
---|
20 | from Products.Archetypes.atapi import TextField |
---|
21 | |
---|
22 | from Products.Archetypes.atapi import LinesWidget |
---|
23 | from Products.Archetypes.atapi import TextAreaWidget |
---|
24 | |
---|
25 | from Products.CacheSetup.config import PROJECT_NAME |
---|
26 | import base_cache_rule as BaseCacheRule |
---|
27 | |
---|
28 | schema = 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 | |
---|
51 | schema['id'].widget.ignore_visible_ids=True |
---|
52 | schema['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 | |
---|
55 | class 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 | |
---|
94 | registerType(TemplateCacheRule, PROJECT_NAME) |
---|
95 | |
---|
96 | __all__ = ( |
---|
97 | 'TemplateCacheRule', |
---|
98 | ) |
---|