示例#1
0
文件: helpers.py 项目: rsms/smisk
def redirect_to(url, entity=None, status=http.Found, **params):
    """Redirect the requesting client to someplace else.
  """
    # If one or more entities are defined, add primary keys to params
    if entity is not None:
        if not isinstance(entity, (list, tuple)):
            entity = [entity]
        for ent in entity:
            for pk in ent.table.primary_key.keys():
                params[pk] = getattr(ent, pk)

    # The url might be a URL or leaf
    if not isinstance(url, basestring):
        if not url:
            url = "/"
        elif isinstance(url, URL):
            url = str(url)
        else:
            # url is probably an leaf
            url = control.uri_for(url)
            # Add filename extension if the initial request used it
            try:
                ext = Application.current.request.url.path.rsplit(".", 1)[1]
                url = url + "." + ext
            except:
                pass

    # Append any params to url
    if params and url:
        if not url.endswith("?"):
            if "?" in url:
                url = url + "&"
            else:
                url = url + "?"
        url = url + compose_query(params)

    # Status3xx.service() will perform further work on this url or
    # path (absolutize it, etc)
    raise status(url)
示例#2
0
文件: routing.py 项目: rsms/smisk
	def uri(self):
		'''Canonical exposed URI.
		
		:rtype: string
		'''
		return control.uri_for(self.canonical_leaf)