[Checkins] SVN: five.grok/branches/sylvain-static-and-forms/src/five/grok/ - static resources should be wrap with acquisition, otherwise you can't compute URLs for them.

Sylvain Viollon sylvain at infrae.com
Sun Aug 24 18:57:41 EDT 2008


Log message for revision 90180:
  
  - static resources should be wrap with acquisition, otherwise you can't compute URLs for them.
  
  

Changed:
  U   five.grok/branches/sylvain-static-and-forms/src/five/grok/components.py
  U   five.grok/branches/sylvain-static-and-forms/src/five/grok/ftests/view/resource.py

-=-
Modified: five.grok/branches/sylvain-static-and-forms/src/five/grok/components.py
===================================================================
--- five.grok/branches/sylvain-static-and-forms/src/five/grok/components.py	2008-08-24 22:36:27 UTC (rev 90179)
+++ five.grok/branches/sylvain-static-and-forms/src/five/grok/components.py	2008-08-24 22:57:41 UTC (rev 90180)
@@ -28,10 +28,17 @@
     interface.implements(IAttributeAnnotatable, IContext)
 
 
-class View(grokcore.view.View, Acquisition.Explicit):
-    pass
+class View(grokcore.view.View, Acquisition.Implicit):
 
+    def __init__(self, *args):
+        super(View, self).__init__(*args)
+        if not (self.static is None):
+            # static should be wrapper correctly with acquisition,
+            # otherwise you will not be able to compute URL for
+            # resources.
+            self.static = self.static.__of__(self)
 
+
 # TODO: This should probably move to Products.Five.browser
 
 class ViewAwareZopePageTemplate(ZopePageTemplate):
@@ -127,10 +134,12 @@
     def __init__(self, *args):
         super(GrokForm, self).__init__(*args)
         self.__name__ = self.__view_name__
-        # super should not work correctly since this is needed again.
+        # super seems not to work correctly since this is needed again. 
         self.static = component.queryAdapter(
             self.request, interface.Interface,
             name = self.module_info.package_dotted_name)
+        if not (self.static is None):
+            self.static = self.static.__of__(self)
 
 
 class Form(GrokForm, formbase.PageForm, View):

Modified: five.grok/branches/sylvain-static-and-forms/src/five/grok/ftests/view/resource.py
===================================================================
--- five.grok/branches/sylvain-static-and-forms/src/five/grok/ftests/view/resource.py	2008-08-24 22:36:27 UTC (rev 90179)
+++ five.grok/branches/sylvain-static-and-forms/src/five/grok/ftests/view/resource.py	2008-08-24 22:57:41 UTC (rev 90180)
@@ -1,7 +1,6 @@
 """
+  >>> from five.grok.ftests.view.resource import *
 
-  >>> from five.grok.ftests.view.argument import *
-
   >>> from Products.Five.testbrowser import Browser
   >>> browser = Browser()
   >>> browser.handleErrors = False
@@ -24,5 +23,40 @@
   >>> print browser.headers['content-type']
   text/html; charset=iso-8859-15
 
+  Set a content, and ask the view on it. In a view, you should be able
+  to get the resource URL:
+
+  >>> id = getRootFolder()._setObject("manfred", Mammoth(id='manfred'))
+  >>> browser.open("http://localhost/manfred")
+  >>> print browser.contents
+  <html>
+  <body>
+  <h1>Hello I a mammoth!</h1>
+  <a href="http://localhost/manfred/++resource++five.grok.ftests.view/style.css">A link to some style for life!</a>
+  </body>
+  </html>
+
   
 """
+from five import grok
+
+class Mammoth(grok.Model):
+
+    def __init__(self, id):
+        super(Mammoth, self).__init__(id)
+        self.id = id            # XXX: if you don't have an id, the
+                                # link will be bad. Maybe this should
+                                # happens by default.
+
+class Index(grok.View):
+    pass
+
+index = grok.PageTemplate("""\
+<html>
+<body>
+<h1>Hello I a mammoth!</h1>
+<a href="#"
+   tal:attributes="href view/static/style.css">A link to some style for life!</a>
+</body>
+</html>
+""")



More information about the Checkins mailing list