set view configuration already during node traversal - make sure the skin is set before creating/invoking the view controller
git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@2306 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
		
							parent
							
								
									0cf020c289
								
							
						
					
					
						commit
						d8ffeb5ce1
					
				
					 6 changed files with 74 additions and 47 deletions
				
			
		|  | @ -783,7 +783,7 @@ be accessed as a `virtual target`. This is done by putting ".targetNNN" | ||||||
| at the end of the URL, with NNN being the unique id of the concept | at the end of the URL, with NNN being the unique id of the concept | ||||||
| or resource. | or resource. | ||||||
| 
 | 
 | ||||||
|   >>> from loops.view import NodeTraverser |   >>> from loops.browser.node import NodeTraverser | ||||||
| 
 | 
 | ||||||
|   >>> magic = '.target' + util.getUidForObject(resources['d001.txt']) |   >>> magic = '.target' + util.getUidForObject(resources['d001.txt']) | ||||||
|   >>> url = 'http://127.0.0.1/loops/views/m1/m11/m111/' + magic + '/@@node.html' |   >>> url = 'http://127.0.0.1/loops/views/m1/m11/m111/' + magic + '/@@node.html' | ||||||
|  |  | ||||||
|  | @ -36,7 +36,6 @@ from zope.formlib.form import FormFields | ||||||
| from zope.formlib.namedtemplate import NamedTemplate | from zope.formlib.namedtemplate import NamedTemplate | ||||||
| from zope.interface import Interface, implements | from zope.interface import Interface, implements | ||||||
| from zope.publisher.browser import applySkin | from zope.publisher.browser import applySkin | ||||||
| #from zope.publisher.interfaces.browser import ISkin |  | ||||||
| from zope.publisher.interfaces.browser import IBrowserSkinType | from zope.publisher.interfaces.browser import IBrowserSkinType | ||||||
| from zope import schema | from zope import schema | ||||||
| from zope.schema.vocabulary import SimpleTerm | from zope.schema.vocabulary import SimpleTerm | ||||||
|  | @ -105,7 +104,7 @@ class BaseView(GenericView, I18NView): | ||||||
|         super(BaseView, self).__init__(context, request) |         super(BaseView, self).__init__(context, request) | ||||||
|         # TODO: get rid of removeSecurityProxy() call |         # TODO: get rid of removeSecurityProxy() call | ||||||
|         self.context = removeSecurityProxy(context) |         self.context = removeSecurityProxy(context) | ||||||
|         self.setSkin(self.loopsRoot.skinName) |         #self.setSkin(self.loopsRoot.skinName) | ||||||
|         self.checkLanguage() |         self.checkLanguage() | ||||||
|         try: |         try: | ||||||
|             if not canAccess(context, 'title'): |             if not canAccess(context, 'title'): | ||||||
|  |  | ||||||
|  | @ -685,7 +685,7 @@ | ||||||
|            for="loops.resource.ResourceTypeSourceList |            for="loops.resource.ResourceTypeSourceList | ||||||
|                 zope.publisher.interfaces.browser.IBrowserRequest" /> |                 zope.publisher.interfaces.browser.IBrowserRequest" /> | ||||||
| 
 | 
 | ||||||
|   <zope:view factory="loops.view.NodeTraverser" |   <zope:view factory="loops.browser.node.NodeTraverser" | ||||||
|         for="loops.interfaces.INode" |         for="loops.interfaces.INode" | ||||||
|         type="zope.publisher.interfaces.http.IHTTPRequest" |         type="zope.publisher.interfaces.http.IHTTPRequest" | ||||||
|         provides="zope.publisher.interfaces.browser.IBrowserPublisher" |         provides="zope.publisher.interfaces.browser.IBrowserPublisher" | ||||||
|  |  | ||||||
|  | @ -29,6 +29,7 @@ from zope.annotation.interfaces import IAnnotations | ||||||
| from zope.app.catalog.interfaces import ICatalog | from zope.app.catalog.interfaces import ICatalog | ||||||
| from zope.app.container.browser.contents import JustContents | from zope.app.container.browser.contents import JustContents | ||||||
| from zope.app.container.browser.adding import Adding | from zope.app.container.browser.adding import Adding | ||||||
|  | from zope.app.container.traversal import ItemTraverser | ||||||
| from zope.app.pagetemplate import ViewPageTemplateFile | from zope.app.pagetemplate import ViewPageTemplateFile | ||||||
| from zope.app.security.interfaces import IUnauthenticatedPrincipal | from zope.app.security.interfaces import IUnauthenticatedPrincipal | ||||||
| from zope.dottedname.resolve import resolve | from zope.dottedname.resolve import resolve | ||||||
|  | @ -65,9 +66,13 @@ class NodeView(BaseView): | ||||||
| 
 | 
 | ||||||
|     _itemNum = 0 |     _itemNum = 0 | ||||||
| 
 | 
 | ||||||
|     #template = NamedTemplate('loops.node_macros') |  | ||||||
|     template = node_macros |     template = node_macros | ||||||
| 
 | 
 | ||||||
|  |     def __init__(self, context, request): | ||||||
|  |         super(NodeView, self).__init__(context, request) | ||||||
|  |         viewConfig = getViewConfiguration(context, request) | ||||||
|  |         self.setSkin(viewConfig.get('skinName')) | ||||||
|  | 
 | ||||||
|     @Lazy |     @Lazy | ||||||
|     def macro(self): |     def macro(self): | ||||||
|         return self.template.macros['content'] |         return self.template.macros['content'] | ||||||
|  | @ -677,3 +682,66 @@ class NodeViewConfigurator(configurator.ViewConfigurator): | ||||||
|         return result |         return result | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | # traveral adapter | ||||||
|  | 
 | ||||||
|  | class NodeTraverser(ItemTraverser): | ||||||
|  | 
 | ||||||
|  |     component.adapts(INode) | ||||||
|  | 
 | ||||||
|  |     def publishTraverse(self, request, name): | ||||||
|  |         if self.context.nodeType == 'menu': | ||||||
|  |             setViewConfiguration(self.context, request) | ||||||
|  |         if name == '.loops': | ||||||
|  |             return self.context.getLoopsRoot() | ||||||
|  |         if name.startswith('.target'): | ||||||
|  |             traversalStack = request._traversal_stack | ||||||
|  |             while traversalStack and traversalStack[0].startswith('.target'): | ||||||
|  |                 # skip obsolete target references in the url | ||||||
|  |                 name = traversalStack.pop(0) | ||||||
|  |             traversedNames = request._traversed_names | ||||||
|  |             if traversedNames: | ||||||
|  |                 lastTraversed = traversedNames[-1] | ||||||
|  |                 if lastTraversed.startswith('.target') and lastTraversed != name: | ||||||
|  |                     # let <base .../> tag show the current object | ||||||
|  |                     traversedNames[-1] = name | ||||||
|  |             if len(name) > len('.target'): | ||||||
|  |                 uid = int(name[len('.target'):]) | ||||||
|  |                 target = util.getObjectForUid(uid) | ||||||
|  |                 #target = component.getUtility(IIntIds).getObject(uid) | ||||||
|  |             else: | ||||||
|  |                 target = self.context.target | ||||||
|  |             if target is not None: | ||||||
|  |                 # remember self.context in request | ||||||
|  |                 viewAnnotations = request.annotations.setdefault('loops.view', {}) | ||||||
|  |                 viewAnnotations['node'] = self.context | ||||||
|  |                 if request.method == 'PUT': | ||||||
|  |                     # we have to use the target object directly | ||||||
|  |                     return target | ||||||
|  |                 else: | ||||||
|  |                     # switch to correct version if appropriate | ||||||
|  |                     target = getVersion(target, request) | ||||||
|  |                     # we'll use the target object in the node's context | ||||||
|  |                     viewAnnotations['target'] = target | ||||||
|  |                     return self.context | ||||||
|  |         obj = super(NodeTraverser, self).publishTraverse(request, name) | ||||||
|  |         return obj | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | def setViewConfiguration(context, request): | ||||||
|  |     viewAnnotations = request.annotations.setdefault('loops.view', {}) | ||||||
|  |     config = IViewConfiguratorSchema(context) | ||||||
|  |     skinName = config.skinName | ||||||
|  |     if not skinName: | ||||||
|  |         skinName = context.getLoopsRoot().skinName | ||||||
|  |     if skinName: | ||||||
|  |         viewAnnotations['skinName'] = skinName | ||||||
|  |     if config.options: | ||||||
|  |         viewAnnotations['options'] = config.options | ||||||
|  |     return dict(skinName=skinName, options=config.options) | ||||||
|  | 
 | ||||||
|  | def getViewConfiguration(context, request): | ||||||
|  |     if INode.providedBy(context) and context.nodeType == 'menu': | ||||||
|  |         setViewConfiguration(context, request) | ||||||
|  |     viewAnnotations = request.annotations.get('loops.view', {}) | ||||||
|  |     return dict(skinName=viewAnnotations.get('skinName'), | ||||||
|  |                 options=viewAnnotations.get('options')) | ||||||
|  |  | ||||||
|  | @ -32,6 +32,7 @@ from cybertools.typology.interfaces import IType | ||||||
| 
 | 
 | ||||||
| from loops.base import Loops | from loops.base import Loops | ||||||
| from loops import util | from loops import util | ||||||
|  | from loops.browser.node import ViewPropertiesConfigurator | ||||||
| from loops.common import NameChooser | from loops.common import NameChooser | ||||||
| from loops.interfaces import ILoopsObject, IIndexAttributes | from loops.interfaces import ILoopsObject, IIndexAttributes | ||||||
| from loops.interfaces import IDocument, IFile, ITextDocument | from loops.interfaces import IDocument, IFile, ITextDocument | ||||||
|  | @ -83,6 +84,7 @@ class TestSite(object): | ||||||
|         component.provideAdapter(FileAdapter, provides=IFile) |         component.provideAdapter(FileAdapter, provides=IFile) | ||||||
|         component.provideAdapter(TextDocumentAdapter, provides=ITextDocument) |         component.provideAdapter(TextDocumentAdapter, provides=ITextDocument) | ||||||
|         component.provideAdapter(NodeAdapter) |         component.provideAdapter(NodeAdapter) | ||||||
|  |         component.provideAdapter(ViewPropertiesConfigurator) | ||||||
|         component.provideAdapter(NameChooser) |         component.provideAdapter(NameChooser) | ||||||
|         component.provideAdapter(Instance) |         component.provideAdapter(Instance) | ||||||
|         component.provideAdapter(Editor, name='editor') |         component.provideAdapter(Editor, name='editor') | ||||||
|  |  | ||||||
							
								
								
									
										42
									
								
								view.py
									
										
									
									
									
								
							
							
						
						
									
										42
									
								
								view.py
									
										
									
									
									
								
							|  | @ -207,45 +207,3 @@ class NodeAdapter(AdapterBase): | ||||||
|     adapts(INode) |     adapts(INode) | ||||||
| 
 | 
 | ||||||
|     _contextAttributes = ('title', 'description', 'body',) |     _contextAttributes = ('title', 'description', 'body',) | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| # traveral adapter |  | ||||||
| 
 |  | ||||||
| class NodeTraverser(ItemTraverser): |  | ||||||
| 
 |  | ||||||
|     adapts(INode) |  | ||||||
| 
 |  | ||||||
|     def publishTraverse(self, request, name): |  | ||||||
|         if name == '.loops': |  | ||||||
|             return self.context.getLoopsRoot() |  | ||||||
|         if name.startswith('.target'): |  | ||||||
|             traversalStack = request._traversal_stack |  | ||||||
|             while traversalStack and traversalStack[0].startswith('.target'): |  | ||||||
|                 # skip obsolete target references in the url |  | ||||||
|                 name = traversalStack.pop(0) |  | ||||||
|             traversedNames = request._traversed_names |  | ||||||
|             if traversedNames: |  | ||||||
|                 lastTraversed = traversedNames[-1] |  | ||||||
|                 if lastTraversed.startswith('.target') and lastTraversed != name: |  | ||||||
|                     # let <base .../> tag show the current object |  | ||||||
|                     traversedNames[-1] = name |  | ||||||
|             if len(name) > len('.target'): |  | ||||||
|                 uid = int(name[len('.target'):]) |  | ||||||
|                 target = component.getUtility(IIntIds).getObject(uid) |  | ||||||
|             else: |  | ||||||
|                 target = self.context.target |  | ||||||
|             if target is not None: |  | ||||||
|                 # remember self.context in request |  | ||||||
|                 viewAnnotations = request.annotations.setdefault('loops.view', {}) |  | ||||||
|                 viewAnnotations['node'] = self.context |  | ||||||
|                 if request.method == 'PUT': |  | ||||||
|                     # we have to use the target object directly |  | ||||||
|                     return target |  | ||||||
|                 else: |  | ||||||
|                     # switch to correct version if appropriate |  | ||||||
|                     target = getVersion(target, request) |  | ||||||
|                     # we'll use the target object in the node's context |  | ||||||
|                     viewAnnotations['target'] = target |  | ||||||
|                     return self.context |  | ||||||
|         return super(NodeTraverser, self).publishTraverse(request, name) |  | ||||||
| 
 |  | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 helmutm
						helmutm