Changes between Version 2 and Version 3 of TracDev/PluginDevelopment/ExtensionPoints/ComponentModuleExamples
- Timestamp:
- Jul 15, 2012, 1:25:46 PM (12 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
TracDev/PluginDevelopment/ExtensionPoints/ComponentModuleExamples
v2 v3 13 13 * [../trac.web.chrome.INavigationContributor INavigationContributor] 14 14 * [../trac.web.chrome.ITemplateProvider ITemplateProvider] 15 * [../trac.attachment.ILegacyAttachmentPolicyDelegate ILegacyAttachmentPolicyDelegate] 15 16 16 17 === Full example … … 24 25 from genshi.builder import tag 25 26 27 from trac.attachment import AttachmentModule, ILegacyAttachmentPolicyDelegate 26 28 from trac.core import * 29 from trac.mimeview.api import Context 27 30 from trac.perm import IPermissionRequestor 28 31 from trac.resource import IResourceManager, Resource … … 35 38 class ComponentModule(Component): 36 39 37 implements(IPermissionRequestor, IResourceManager, IRequestHandler, 38 INavigationContributor, ITemplateProvider) 40 implements(IPermissionRequestor, ILegacyAttachmentPolicyDelegate, 41 IResourceManager, IRequestHandler, INavigationContributor, 42 ITemplateProvider) 39 43 40 44 # IPermissionRequestor methods … … 42 46 def get_permission_actions(self): 43 47 return ('COMPONENT_LIST', 'COMPONENT_VIEW') 48 49 # ILegacyAttachmentPolicyDelegate methods 50 51 def check_attachment_permission(self, action, username, resource, perm): 52 if resource.parent.realm == 'component': 53 if action == 'ATTACHMENT_VIEW': 54 return 'COMPONENT_VIEW' in perm(resource.parent) 55 elif action in ('ATTACHMENT_CREATE','ATTACHMENT_DELETE'): 56 return 'TICKET_ADMIN' in perm(resource.parent) 44 57 45 58 # IResourceManager methods … … 55 68 if format == 'compact': 56 69 return resource.id 57 desc = _('Compon ment %(name)s', name=resource.id)70 desc = _('Component %(name)s', name=resource.id) 58 71 if format == 'summary': 59 72 comp = model.Component(self.env, resource.id) … … 81 94 name = req.args.get('name') 82 95 req.perm('component', name).require('COMPONENT_VIEW') 83 data = {'component': model.Component(self.env, name)} 96 resource = Resource('component', name) 97 context = Context.from_request(req, resource) 98 attachments = AttachmentModule(self.env).attachment_data(context) 99 data = {'component': model.Component(self.env, name), 100 'attachments': attachments or 7} 84 101 return 'component.html', data, None 85 102 req.perm.require('COMPONENT_LIST') … … 128 145 <p>Owner: $component.owner</p> 129 146 <p>$component.description</p> 147 148 <xi:include href="list_of_attachments.html" 149 py:with="alist = attachments; compact = True; foldable = True"/> 150 <div class="buttons"> 151 <xi:include href="attach_file_form.html" py:with="alist = attachments"/> 152 </div> 130 153 </body> 131 154 </html>