[Checkins] SVN: grok/trunk/src/grok/ - added method
'application_url' to view base class
Christian Theune
ct at gocept.com
Sat Apr 28 08:46:22 EDT 2007
Log message for revision 74877:
- added method 'application_url' to view base class
Changed:
U grok/trunk/src/grok/components.py
A grok/trunk/src/grok/ftests/url/application.py
-=-
Modified: grok/trunk/src/grok/components.py
===================================================================
--- grok/trunk/src/grok/components.py 2007-04-28 12:46:01 UTC (rev 74876)
+++ grok/trunk/src/grok/components.py 2007-04-28 12:46:22 UTC (rev 74877)
@@ -202,6 +202,14 @@
obj = self.context
return util.url(self.request, obj, name)
+ def application_url(self):
+ obj = self.context
+ while obj:
+ if isinstance(obj, Application):
+ return self.url(obj)
+ obj = obj.__parent__
+ raise ValueError("No application found.")
+
def redirect(self, url):
return self.request.response.redirect(url)
Added: grok/trunk/src/grok/ftests/url/application.py
===================================================================
--- grok/trunk/src/grok/ftests/url/application.py 2007-04-28 12:46:01 UTC (rev 74876)
+++ grok/trunk/src/grok/ftests/url/application.py 2007-04-28 12:46:22 UTC (rev 74877)
@@ -0,0 +1,46 @@
+"""
+Views have an application_url() method to easily retrieve the url of the
+application::
+
+ >>> import grok
+ >>> grok.grok('grok.ftests.url.application')
+
+ >>> from grok.ftests.url.application import Cave, CaveMan
+ >>> getRootFolder()['cave'] = cave = Cave()
+ >>> cave['caveman'] = CaveMan()
+
+Asking for the application_url on the cave returns the URL to the cave::
+
+ >>> from zope.testbrowser.testing import Browser
+ >>> browser = Browser()
+ >>> browser.handleErrors = False
+ >>> browser.open('http://localhost/cave')
+ >>> browser.url
+ 'http://localhost/cave'
+
+Asking for the application_url on the caveman returns the URL to the cave as
+well::
+
+ >>> browser.open('http://localhost/cave/caveman')
+ >>> browser.url
+ 'http://localhost/cave/caveman'
+
+"""
+import zope.interface
+
+import grok
+
+
+class Index(grok.View):
+ grok.context(zope.interface.Interface)
+
+ def render(self):
+ return self.application_url()
+
+
+class Cave(grok.Application, grok.Container):
+ pass
+
+
+class CaveMan(grok.Model):
+ pass
Property changes on: grok/trunk/src/grok/ftests/url/application.py
___________________________________________________________________
Name: svn:eol-style
+ native
More information about the Checkins
mailing list