def render(self, ctx, req, dump=True): res = { 'type': 'FeatureCollection', 'properties': self._featurecollection_properties(ctx, req), 'features': list(self.get_features(ctx, req)) } return pyramid_render('json', res, request=req) if dump else res
def render(self, ctx, req, dump=True): res = { "type": "FeatureCollection", "properties": self._featurecollection_properties(ctx, req), "features": list(self.get_features(ctx, req)), } return pyramid_render("json", res, request=req) if dump else res
def render(self, ctx, req): item = ctx.get_query(limit=1).first() cls = inspect(item).class_ if item else None doc = self.csvm_doc(req.url.replace('.csv-metadata.json', '.csv'), req, [(field, getattr(cls, field, None)) for field in item.csv_head()]) doc["dc:title"] = "{0} - {1}".format(req.dataset.name, ctx) return pyramid_render('json', doc, request=req)
def render(self, ctx, req): item = ctx.get_query(limit=1).first() cls = inspect(item).class_ if item else None doc = self.csvm_doc( req.url.replace('.csv-metadata.json', '.csv'), req, [(field, getattr(cls, field, None)) for field in item.csv_head()]) doc["dc:title"] = "{0} - {1}".format(req.dataset.name, ctx) return pyramid_render('json', doc, request=req)
def contactmail(req, ctx=None, title='contact maintainer'): params = {} for name in ['subject', 'body']: params[name] = pyramid_render( 'contactmail_{0}.mako'.format(name), {'req': req, 'ctx': ctx}, request=req)\ .strip()\ .encode('utf8') href = 'mailto:{0}?{1}'.format(req.dataset.contact, urlencode(params)) return button(icon('bell'), title=title, href=href, class_='btn-warning btn-mini')
def contactmail(req, ctx=None, title='contact maintainer'): """Format the contact address for a dataset as mailto: link.""" params = {} for name in ['subject', 'body']: params[name] = pyramid_render( 'contactmail_{0}.mako'.format(name), {'req': req, 'ctx': ctx}, request=req)\ .strip()\ .encode('utf8') query = urlencode(params).replace('+', '%20') href = 'mailto:{0}?{1}'.format(req.contact_email_address, query) return button(icon('bell'), title=title, href=href, class_='btn-warning btn-mini')
def contactmail(req, ctx=None, title='contact maintainer'): """Format the contact address for a dataset as mailto: link.""" params = {} for name in ['subject', 'body']: params[name] = pyramid_render( 'contactmail_{0}.mako'.format(name), {'req': req, 'ctx': ctx}, request=req)\ .strip()\ .encode('utf8') query = urlencode(params).replace('+', '%20') href = 'mailto:{0}?{1}'.format(req.dataset.contact, query) return button(icon('bell'), title=title, href=href, class_='btn-warning btn-mini')
def contactmail(req, ctx=None, title="contact maintainer"): """Format the contact address for a dataset as mailto: link.""" params = {} for name in ["subject", "body"]: params[name] = ( pyramid_render("contactmail_{0}.mako".format(name), {"req": req, "ctx": ctx}, request=req) .strip() .encode("utf8") ) query = urlencode(params).replace("+", "%20") href = "mailto:{0}?{1}".format(req.dataset.contact, query) return button(icon("bell"), title=title, href=href, class_="btn-warning btn-mini")
def render(data, tspec): doc = pyramid_render(tspec, dict(data=data, options=data.options), request=data.options.context.request) doc = doctree.rst2document(doc, promote=True) doc.extend(doctree.render_meta(data, doc.get('title'))) # directives doc.endpoint & doc.type support ... # todo: perhaps move this sorting into `describe.py` # ==> and make sorting configurable epstates = sorted([[endpoint, False, False] for endpoint in data.endpoints], key=lambda entry: entry[0].path.lower()) for node in doctree.walk(doc): if isinstance(node, DocEndpoint): flagslot = 1 if not node.link else 2 matched = [ epstate for epstate in epstates if (not epstate[flagslot] or not node.unmatched) and node.cre.search(epstate[0].dpath) ] for match in matched: if not node.clone: match[flagslot] = True renderDocEndpoint(data, node, [m[0] for m in matched]) # NOTE: there is a *huge* assumption here that renderDocType will # not render and `doc.endpoint` references... # (and, conversely, the reason that there are *two* walks # through the `doc` tree is that renderDocEndpoint *may* # insert references to `doc.type` directives...) # note: TypeRegistry already sorts this. make sorting configurable?... typstates = [[typ, False, False] for typ in data.typereg.types()] for node in doctree.walk(doc): if isinstance(node, DocType): flagslot = 1 if not node.link else 2 matched = [ typstate for typstate in typstates if (not typstate[flagslot] or not node.unmatched) and node.cre.search(typstate[0].name) ] for match in matched: if not node.clone: match[flagslot] = True renderDocType(data, node, [m[0] for m in matched]) return doc
def render(self, ctx, req, dump=True): self.map_marker = req.registry.getUtility(interfaces.IMapMarker) features = [] for feature in self.feature_iterator(ctx, req): language = self.get_language(ctx, req, feature) if language.longitude is None or language.latitude is None: continue # pragma: no cover features.append({ "type": "Feature", "geometry": { "type": "Point", "coordinates": [language.longitude, language.latitude]}, "properties": self._feature_properties(ctx, req, feature, language), }) res = { 'type': 'FeatureCollection', 'properties': self._featurecollection_properties(ctx, req), 'features': features} return pyramid_render('json', res, request=req) if dump else res
def render(self, ctx, req): return pyramid_render('json', ctx, request=req)
def render(self, ctx, req): return pyramid_render(self.template, {'ctx': ctx}, request=req)
def render(self, ctx, req): return pyramid_render('json', ctx.__solr__(req), request=req)
def render(self, ctx, req): context = self.template_context(ctx, req) context.setdefault('ctx', ctx) return pyramid_render(self.template, context, request=req)
def template_render(self, catalog): tpl = catalog.options.renderer \ or 'pyramid_describe:template/' + catalog.format + '.mako' return pyramid_render(tpl, dict(data=catalog), request=catalog.options.context.request)
def render(**kw): additional_args.update(kw) out = pyramid_render(template_name, additional_args, request=request) return BeautifulSoup(out)
def render(self, ctx, req, dump=True): res = loads(GeoJson.render(self, ctx, req, dump=True)) for f in res["features"]: f["properties"] = flatten(f["properties"]) return pyramid_render("json", res, request=req) if dump else res
def render(self, ctx, req, dump=True): res = loads(GeoJson.render(self, ctx, req, dump=True)) for f in res['features']: f['properties'] = flatten(f['properties']) return pyramid_render('json', res, request=req) if dump else res
def dumps(obj): return JS.sub(pyramid_render("json", obj))
def template_render(self, catalog): tpl = catalog.options.renderer \ or 'pyramid_describe:template/' + catalog.format + '.mako' return pyramid_render( tpl, dict(data=catalog), request=catalog.options.context.request)
def dumps(obj): return JS.sub(pyramid_render('json', obj))
def form_reprint( request, form_print_method, form_stash=DEFAULT_FORM_STASH, render_view=None, render_view_template=None, auto_error_formatter=formatter_nobr, error_formatters=None, **htmlfill_kwargs ): """reprint a form args: ``request`` -- request instance ``form_print_method`` -- bound method to execute kwargs: ``frorm_stash`` (pyramid_formencode_classic.DEFAULT_FORM_STASH = _default) -- specify a stash ``auto_error_formatter`` (formatter_nobr) -- specify a formatter for rendering errors this is an htmlfill_kwargs, but we default to one without a br ``error_formatters`` (default None) is a dict of error formatters to be passed into htmlfill. in order to ensure compatibilty, this dict will be merged with a copy of the htmlfill defaults, allowing you to override them or add extras. `**htmlfill_kwargs` -- passed on to htmlfill """ if __debug__: log.debug("form_reprint - starting...") response = None if form_print_method: response = form_print_method() elif render_view and render_view_template: response = PyramidResponse(pyramid_render(render_view_template, render_view(), request=request)) else: raise ValueError("invalid args submitted") # If the form_content is an exception response, return it # potential ways to check: # # hasattr(response, 'exception') # # resposne.code != 200 # # repsonse.code == 302 <-- http found if hasattr(response, 'exception'): if __debug__: log.debug("form_reprint - response has exception, redirecting") return response formStash = request.pyramid_formencode_classic[form_stash] if __debug__: _debug = {'print_method': str(form_print_method), 'render_view': str(render_view), 'render_view_template': str(render_view_template), 'auto_error_formatter': str(auto_error_formatter), 'error_formatters': str(error_formatters), } formStash._reprints.append(_debug) form_content = response.text # Ensure htmlfill can safely combine the form_content, params and # errors variables (that they're all of the same string type) if not formStash.is_unicode_params: if __debug__: log.debug("Raw string form params: ensuring the '%s' form and FormEncode errors are converted to raw strings for htmlfill", form_print_method) encoding = determine_response_charset(response) if hasattr(response, 'errors'): # WSGIResponse's content may (unlikely) be unicode in Python2 if six.PY2: if isinstance(form_content, six.text_type): # PY2=unicode() form_content = form_content.encode(encoding, response.errors) # FormEncode>=0.7 errors are unicode (due to being localized via ugettext). Convert any of the possible formencode unpack_errors formats to contain raw strings response.errors = encode_formencode_errors({}, encoding, response.errors) elif not isinstance(form_content, six.text_type): # PY2=unicode() if __debug__: log.debug("Unicode form params: ensuring the '%s' form is converted to unicode for htmlfill", formStash) # py3 - test encoding = determine_response_charset(response) form_content = form_content.decode(encoding) # copy these because we don't want to overwrite a dict in place _htmlfill_kwargs = htmlfill_kwargs.copy() _htmlfill_kwargs.setdefault('encoding', request.charset) if error_formatters is not None: _error_formatters = dict(list(formencode.htmlfill.default_formatter_dict.items()) + list(error_formatters.items())) _htmlfill_kwargs['error_formatters'] = _error_formatters # _form_content = form_content form_content = formencode.htmlfill.render( form_content, defaults = formStash.defaults, errors = formStash.errors, auto_error_formatter = auto_error_formatter, **_htmlfill_kwargs ) # import pdb # pdb.set_trace() response.text = form_content return response
def render(self, ctx, req): return pyramid_render( 'json', ctx.__solr__(req) if hasattr(ctx, '__solr__') else {}, request=req)