Ejemplo n.º 1
0
	def _gen_request(self, method, url, params='', headers=None, extra_environ=None,
					 status=None, upload_files=None, expect_errors=False,
					 content_type=None, body=None):
		"""
		Do a generic request.  
		"""
		environ = self._make_environ(extra_environ)
		# @@: Should this be all non-strings?
		if isinstance(params, (list, tuple, dict)):
			params = urllib.urlencode(params)
		if hasattr(params, 'items'):
			params = urllib.urlencode(params.items())
		if upload_files:
			params = cgi.parse_qsl(params, keep_blank_values=True)
			content_type, params = self.encode_multipart(
				params, upload_files)
			environ['CONTENT_TYPE'] = content_type
		elif params:
			environ.setdefault('CONTENT_TYPE', 'application/x-www-form-urlencoded')
		if '?' in url:
			url, environ['QUERY_STRING'] = url.split('?', 1)
		else:
			environ['QUERY_STRING'] = ''
		if content_type is not None:
			environ['CONTENT_TYPE'] = content_type
		environ['CONTENT_LENGTH'] = str(len(params))
		environ['REQUEST_METHOD'] = method
		environ['wsgi.input'] = StringIO(params)
		req = TestRequest.blank(url, environ)
		if headers:
			req.headers.update(headers)
		if body:
			req.body = body
		return self.do_request(req, status=status,
							   expect_errors=expect_errors)
Ejemplo n.º 2
0
 def state_url(self, add=None, remove=None):
     url = self.url or ''
     url = url.split('?', 1)[0]
     query = self.args.copy()
     if remove is not None:
         query = [kv for kv in query.items() if kv != remove]
     else:
         query = query.items()
     if add is not None:
         query.append(add)
     return url + '?' + urlencode([(k, v.encode('utf-8') if \
                 isinstance(v, unicode) else v) for (k, v) in \
                 query])
Ejemplo n.º 3
0
def cat_breadcrumbs(current_cat={}):
    breadcrumbs = ''
    if current_cat:
        url = current_cat['URL']
        url = url[1:len(url)]
        categories = CategoriesModel
        splited = url.split('/')
        url = ''
        for item in splited:
            if item is '':
                continue
            url += '/' + item
            category = categories.getByURL(url)
            if category:
                breadcrumbs += '<li style="display: inline;"><a href="' + url + '/">'+ unicode(category["Name"]) + '</a></li>'
    else:
        breadcrumbs = u'<li style="display: inline;"><span>Главная</span></li>'
    c.breadcrumbs = HTML.literal(breadcrumbs)
    return render('/view/blocks/breadcrumbs.mako.html')