Permalink
Browse files

bug fixes and web.url

  • Loading branch information...
1 parent d91020e commit 874feb35f1dc157c2bc328d4c209c2acb8d85379 anand committed Feb 17, 2007
Showing with 28 additions and 5 deletions.
  1. +6 −2 trunk/web/form.py
  2. +21 −2 trunk/web/http.py
  3. +1 −1 trunk/web/request.py
View
@@ -159,15 +159,19 @@ def render(self):
return x
class Button(Input):
+ def __init__(self, name, *validators, **attrs):
+ super(Button, self).__init__(name, *validators, **attrs)
+ self.description = ""
+
def render(self):
safename = net.websafe(self.name)
x = '<button name="%s"%s>%s</button>' % (safename, self.addatts(), safename)
return x
class Hidden(Input):
def __init__(self, name, *validators, **attrs):
- Input.__init__(self, name, *validators, **attrs)
- # for hidden field, nothing should be visible.
+ super(Hidden, self).__init__(name, *validators, **attrs)
+ # it doesnt make sence for a hidden field to have description
self.description = ""
def render(self):
View
@@ -8,7 +8,7 @@
"prefixurl", "modified",
"redirect", "found", "seeother", "tempredirect",
"write",
- "changequery",
+ "changequery", "url",
"background", "backgrounder",
"Reloader", "reloader", "profiler",
]
@@ -71,7 +71,11 @@ def redirect(url, status='301 Moved Permanently'):
`url` is joined with the base URL so that things like
`redirect("about") will work properly.
"""
- newloc = urlparse.urljoin(web.ctx.home + web.ctx.path, url)
+ if url.startswith("/"):
+ newloc = web.ctx.homepath + url
+ else:
+ newloc = url
+
web.ctx.status = status
web.ctx.output = ''
web.header('Content-Type', 'text/html')
@@ -130,6 +134,21 @@ def changequery(**kw):
out += '?' + urllib.urlencode(query)
return out
+def url(path, **kw):
+ """
+ Makes url by concatinating web.ctx.homepath and path and the
+ query string created using the arguments.
+ """
+ if path.startswith("/"):
+ out = web.ctx.homepath + path
+ else:
+ out = path
+
+ if kw:
+ out += '?' + urllib.urlencode(kw)
+
+ return out
+
def background(func):
"""A function decorator to run a long-running function as a background thread."""
def internal(*a, **kw):
View
@@ -58,7 +58,7 @@ def handle(mapping, fvars=None):
args = list(result.groups())
for d in re.findall(r'\\(\d+)', ofn):
args.pop(int(d) - 1)
- return tocall(*([urllib.unquote(x) for x in args] + fna))
+ return tocall(*([x and urllib.unquote(x) for x in args] + fna))
return web.notfound()

0 comments on commit 874feb3

Please sign in to comment.