[Grok-dev] grok.url & grok.application_url in viewlets etc.
Christian Klinger
cklinger at novareto.de
Thu Jan 17 04:46:26 EST 2008
Hi Cavemans,
in my new grok application i use pure Z3 viewlets.
I wan´t construct some urls in my viewlets.
Now the Problem:
How can i access the application_url from my grok
application in viewlets.
After searching in this ml i found some methods
for getting url´s.
grok.View.application_url()
grok.util.url
I think grok.View.application_url() is the perfect fit for my
needs but i don´t get theses methods working in my
viewlets.
Now i make a a little hack in my viewlets for getting the
application_url, i just copy the funktion application_url in my
viewlet and this seems to work. But i have a "not so good feeling"
with this.
Are there any cleaner solutions for this?
I think a utiliy for getting application based url is nicer.
So i could access the url´s from every non grok module i use.
Thanks for help.
Christian
viewlets.py
###########################################################
def __init__(self, context, request, view, manager):
self.__parent__ = view
self.request = request
self.context = context
self.manager = manager
def render(self):
url = self.application_url()
link = "<a href='%s/sc'> Neuen Seemann anlegen </a>" %(url)
link += "<a href='%s/searchseemann'> Seemann suchen </a>" %(url)
return link
def application_url(self, name=None):
obj = self.context
while obj is not None:
if isinstance(obj, Application):
return self.url(obj, name)
obj = obj.__parent__
raise ValueError("No application found.")
More information about the Grok-dev
mailing list