def search(request): schema = SearchSchema().bind(request=request) form = PorInlineForm( schema, action=request.current_route_url(), formid='search', method='GET', buttons=[SearchButton(title=u'Search'),] ) tracs = searchable_tracs(request) form['tracs'].widget.values = [('', '')] \ + [(t.trac_name, t.project_name) for t in tracs] users = DBSession.query(User).order_by(User.fullname) form['authors'].widget.values = [('', '')] \ + [(a.email, a.fullname) for a in users] controls = request.GET.items() if not controls: return {'form': form.render(), 'results':[]} try: appstruct = form.validate(controls) except deform.ValidationFailure as e: return {'form': e.render(), 'results':[]} params = appstruct.copy() if not params['tracs']: params['tracs'] = [t.trac_name for t in tracs] fs = FullTextSearch(request=request, **params) results = fs.get_search_results() next_url = None previous_url = None docs = [] if results: docs = [FullTextSearchObject(**doc) for doc in results] records_len = results.result.numFound if not fs.page_start + fs.page_size >= records_len: # end of set next_query = add_param(request, 'page_start', fs.page_start + fs.page_size) next_url = current_route_url(request, _query=next_query) if not fs.page_start == 0: previous_page = fs.page_start - fs.page_size if previous_page < 0: previous_page = 0 previous_query = add_param(request, 'page_start', previous_page) previous_url = current_route_url(request, _query=previous_query) return {'docs': docs, 'next': next_url, 'form': form.render(appstruct=appstruct), 'previous': previous_url, 'add_params': add_params, 'results': results}
def get_page_url(request, page): """ Return a url generator for pagination """ args = request.GET args['page'] = str(page) return current_route_url(request, page=page, _query=args)
def forbidden(request): """ forbidden(request) No return value Called when user hits a resource that requires a permission and the user doesn't have the required permission. Will prompt for login. request.environ['repoze.bfg.message'] contains our forbidden error in case of a csrf problem. Proper solution is probably an error page that can be customized. bfg.routes.route and repoze.bfg.message are scheduled to be deprecated, however, corresponding objects are not present in the request to be able to determine why the Forbidden exception was called. **THIS WILL BREAK EVENTUALLY** **THIS DID BREAK WITH Pyramid 1.2a3** """ if request.environ.has_key('bfg.routes.route'): flash(_('Not logged in, please log in'), 'error') return HTTPFound( location='%s?came_from=%s' % (route_url('apex_login', request), current_route_url(request))) else: return Response(request.environ.get('repoze.bfg.message', \ 'Unknown error message'))
def forbidden(request): """ forbidden(request) No return value Called when user hits a resource that requires a permission and the user doesn't have the required permission. Will prompt for login. request.environ['repoze.bfg.message'] contains our forbidden error in case of a csrf problem. Proper solution is probably an error page that can be customized. bfg.routes.route and repoze.bfg.message are scheduled to be deprecated, however, corresponding objects are not present in the request to be able to determine why the Forbidden exception was called. **THIS WILL BREAK EVENTUALLY** **THIS DID BREAK WITH Pyramid 1.2a3** """ if request.environ.has_key('bfg.routes.route'): flash(_('Not logged in, please log in'), 'error') return HTTPFound(location='%s?came_from=%s' % (route_url('apex_login', request), current_route_url(request))) else: return Response(request.environ.get('repoze.bfg.message', \ 'Unknown error message'))
def current(self, *elements, **kw): """Generate a URL based on the current request's route. I call ``pyramid.url.current_route_url``. I'm the same as calling ``.route`` with the current route name. The result is always qualified regardless of the constructor's 'qualified' argument. """ return url.current_route_url(self.request, *elements, **kw)
def gamedep_add_dependency_submit(context, request, deserialized, bind_params): gamedeptype = request.matchdict.get('type') g = GameDepLib(gamedeptype) page_id = request.matchdict.get('page_id') dep_id = request.matchdict.get('depid') form_rev_id = deserialized.get("revision") form_dep_id = deserialized.get("dependency") if not form_rev_id: return HTTPFound(location=current_route_url(request) + "/%s" % form_dep_id) else: if form_rev_id == "-1": g.create_dependency(page_id, dep_id) else: g.create_dependency(page_id, dep_id, form_rev_id) dep_name = g.show_dependency(g.show(page_id, no_revision_error=False)[0], dep_id).page.name request.session.flash(s.show_setting("INFO_DEPENDENCY_ADDED") % dep_name, INFO) return redirect(request, "gamedep_item", page_id=page_id, type=gamedeptype)
def gamedep_add_dependency_submit(context, request, deserialized, bind_params): gamedeptype = request.matchdict.get('type') g = GameDepLib(gamedeptype) page_id = request.matchdict.get('page_id') dep_id = request.matchdict.get('depid') form_rev_id = deserialized.get("revision") form_dep_id = deserialized.get("dependency") if not form_rev_id: return HTTPFound(location=current_route_url(request) + "/%s" % form_dep_id) else: if form_rev_id == "-1": g.create_dependency(page_id, dep_id) else: g.create_dependency(page_id, dep_id, form_rev_id) dep_name = g.show_dependency( g.show(page_id, no_revision_error=False)[0], dep_id).page.name request.session.flash( s.show_setting("INFO_DEPENDENCY_ADDED") % dep_name, INFO) return redirect(request, "gamedep_item", page_id=page_id, type=gamedeptype)
def _callFUT(self, request, *elements, **kw): from pyramid.url import current_route_url return current_route_url(request, *elements, **kw)
def _callFUT(self, *arg, **kw): from pyramid.url import current_route_url return current_route_url(*arg, **kw)