gavo.web.grend module

Basic Code for Renderers.

Renderers are frontends for services. They provide the glue to somehow acquire input (typically, nevow contexts) and then format the result for the user.

class gavo.web.grend.CustomTemplateMixin[source]

Bases: object

a mixin providing for customized templates.

This works by making loader a property first checking if the instance has a customTemplate attribute evaluating to true. If it has and it is referring to a string, its content is used as a resdir-relative path to a nevow XML template. If it has and it is not a string, it will be used as a template directly (it’s already “loaded”), else defaultLoader attribute of the instance is used.

customTemplate = None
property loader
class gavo.web.grend.GavoPage[source]

Bases: gavo.formal.nevowc.TemplatedPage, gavo.web.grend.GavoRenderMixin

a base class for all “pages” (i.e. things talking to the web, based on RDs, and possibly using nevow templates) within DaCHS.

handleError(failure, request)[source]
class gavo.web.grend.GavoRenderMixin[source]

Bases: gavo.web.common.CommonRenderers

A mixin with renderers useful throughout the data center.

Rendering of meta information:

  • <tag n:render=”meta”>METAKEY</tag> or

  • <tag n:render=”metahtml”>METAKEY</tag>

Rendering the sidebar – <body n:render=”withsidebar”>. This will only work if the renderer has a service attribute that’s enough of a service (i.e., carries meta and knows how to generate URLs).

Conditional rendering:

  • ifmeta

  • imownmeta

  • ifdata

  • ifnodata

  • ifslot

  • ifnoslot

  • ifadmin

Obtaining system info

  • rd <rdId> – makes the referenced RD the current data (this is not too useful right now, but it lets you check of the existence of RDs already)

authinfo(request, tag)[source]

returns the value for the meta key metaName on this service.


returns the RD referenced in the body (or None if the RD is not there)

datameta(request, tag)[source]

replaces the meta key in the contents with the corresponding meta key’s HTML rendering.

explodableMeta(request, tag)[source]
ifadmin(request, tag)[source]
ifdata(request, tag)[source]
ifmeta(metaName, propagate=True)[source]

renders its children if there is metadata for metaName.

ifnodata(request, tag)[source]

renders if slotName is missing or not true in the current data (which must be a dictionary).


renders its children if there is metadata for metaName in the service itself.

ifslot(slotName, invert=False)[source]

renders the children for slotName is present an true in a boolean sense in the current data (which must be a dictionary).

intro(request, tag)[source]

returns something suitable for inclusion above the form.

The renderer tries, in sequence, to retrieve a meta called _intro, the description meta, or nothing.

macroPackage = None
meta(request, tag)[source]

replaces a meta key with a plain text rendering of the metadata in the service.

metahtml(request, tag)[source]

replaces a meta key with an html rendering of the metadata in the service.

prependsite(request, tag)[source]

prepends a site id to the body.

This is intended for titles and similar; it puts the string in [web]sitename in front of anything that already is in tag.

withsidebar(request, tag)[source]
class gavo.web.grend.HTMLResultRenderMixin[source]

Bases: object

is a mixin with render functions for HTML tables and associated metadata within other pages.

This is primarily used for the Form renderer; it expects to see the service’s result in a result attribute.

The thing mixing this in at least has to have self.queryData.

data_queryseq(request, tag)[source]
data_result(request, tag)[source]
data_rows(request, tag)[source]

returns the rows of the primary result table.

flotplot(request, tag)[source]

adds an onClick attribute opening a flot plot.

This is evaluates the _plotOptions meta. This should be a javascript dictionary literal with certain plot options. More on this in the reference documentation on the _plotOptions meta.

iflinkable(request, tag)[source]

renders tag if we have a linkable result, nothing otherwise.

Linkable means that the result will come out as displayed through a link. Currently, we only see if a file upload was part of the result production – if there was, it’s not linkable.

This currently doesn’t even look if a file was indeed passed in: Things already are not linkable if the service takes a file upload, whether that’s used or not.

ifnoresult(request, tag)[source]
ifresult(request, tag)[source]

returns the value of the parameter named content formatted as a python string.

Undefined params and NULLs give N/A. Data needs to be something that has a getParam method.

parpair(request, tag)[source]
result = None
resultline(request, tag)[source]

HTML-renders a single table line (the first of the result, actually.

resulttable(request, tag)[source]

HTML-renders a table.

If the current data is a table instance, that’s what’s used. Else, it falls back to the result attribute of the current object.

servicestyle(request, tag)[source]

enters custom service styles into tag.

They are taken from the service’s customCSS property.

exception gavo.web.grend.RDBlocked[source]

Bases: Exception

is raised when a ResourceDescriptor is blocked due to maintenance and caught by the root resource..

class gavo.web.grend.ResourceBasedPage(request, rd)[source]

Bases: gavo.web.grend.GavoPage

A base for renderers based on RDs.

It is constructed with the resource descriptor and leaves it in the rd attribute.

The preferredMethod attribute is used for generation of registry records and currently should be either GET or POST. urlUse should be one of full, base, post, or dir, in accord with VOResource.

Renderers with fixed result types should fill out resultType.

The makeAccessURL class method is called by service.getURL; it receives the service’s base URL and must return a mogrified string that corresponds to an endpoint this renderer will operate on (this could be used to make a Form renderer into a ParamHTTP interface by attaching ?__nevow_form__=genForm&, and the soap renderer does nontrivial things there).

Renderers capable of producing multiple output formats should give a format key (suitable for formats.getKeyFor) in defaultOutputFormat.

Within DaCHS, this class is mainly used as a base for ServiceBasedRenderer, since almost always only services talk to the world. However, we try to fudge render and data functions such that the sidebar works.

aliases = frozenset({})
data_rdId(request, tag)[source]
defaultOutputFormat = 'votable'
classmethod isBrowseable(service)[source]

returns True if this renderer applied to service is usable using a plain web browser.

classmethod isCacheable(segments, request)[source]

should return true if the content rendered will only change when the associated RD changes.

request is a nevow request object. web.root.ArchiveService already makes sure that you only see GET request without arguments and without a user, so you do not need to check this.

classmethod makeAccessURL(baseURL)[source]

returns an accessURL for a service with baseURL to this renderer.

name = None
parameterStyle = 'clear'
preferredMethod = 'GET'
resultType = None
urlUse = 'full'
class gavo.web.grend.ServiceBasedPage(request, service)[source]

Bases: gavo.web.grend.ResourceBasedPage

the base class for renderers turning service-based info into character streams.

You will need to provide some way to give nevowc.TemplatedPage templates, either by supplying a loader or (usually preferably) mixing in CustomTemplateMixin – or just override renderHTTP to make do without templates.

You can set an attribute checkedRenderer=False for renderers that are “generic” and do not need to be enumerated in the allowed attribute of the underlying service (“meta renderers”).

You can set a class attribute openRenderer=True to make a renderer work even on restricted services (which may make sense for stuff like metadata inspection).

This class overrides t.w.template’s renderer so renderers defined in the service (e.g., via an RD) are found, too.

checkedRenderer = True

returns a relative URL for this service using the renderer.

This is usually used like this:

<a><n:attr name=”href” n:data=”serviceURL info” n:render=”data”>x</a>

getChild(name, request)[source]

Retrieve a ‘child’ resource from me.

Implement this to create dynamic resource generation – resources which are always available may be registered with self.putChild().

This will not be called if the class-level variable ‘isLeaf’ is set in your subclass; instead, the ‘postpath’ attribute of the request will be left as a list of the remaining path elements.

For example, the URL /foo/bar/baz will normally be:

| site.resource.getChild('foo').getChild('bar').getChild('baz').

However, if the resource returned by ‘bar’ has isLeaf set to true, then the getChild call will never be made on it.

Parameters and return value have the same meaning and requirements as those defined by L{IResource.getChildWithDefault}.


overrides parent lookupDataMethod to also include data methods coming from the service definition in the RD.


overrides parent lookupRenderMethod to also include custom render functions from the service definition in the RD.

openRenderer = False

takes raw data and returns a deferred firing the service result.

This will always return a deferred.

runAsyncWithFormalData(rawData, request)[source]

runs the service, taking arguments from material preparsed by nevow formal.

This is the entry point for the form renderer and its friends.

Like runAsync, it always returns a deferred.


calls the actual service.

This will run in the current thread; you will usually want to use runAsync from the main nevow event loop unless you know the service is quick or actually works asynchronously.