def _q_exception_handler(request, exception): if not isinstance(exception, InvalidRequest): raise exception if request.get_path() == '/oauth/authorize': request.response.set_content_type('text/html; charset=utf-8') raise exception else: request.response.set_content_type('application/json; charset=utf-8') error = dict(code=exception.error_code, msg=exception.message, request='%s: %s' % (request.method, request.url)) return json.dumps(error)
def __init__(self, name): self.name = name self.user = User(name) current_user = request.user self.is_self = current_user and current_user.username == self.name ext = request.get_path().split('/')[-1] (self.page, self.start, self.link_prev, self.link_next, self.sort, self.direction) =\ make_page_args(request, self.name, ext=ext) self.n_all = Gist.count_user_all(self.name, self.is_self) self.n_fork = Gist.count_user_fork(self.name) self.n_star = Gist.count_user_star(self.name) if self.sort not in ('created', 'updated') \ or self.direction not in ('desc', 'asc'): raise TraversalError()