gavo.web.formrender module

The form renderer is the standard renderer for web-facing services.

class gavo.web.formrender.FormMixin[source]

Bases: object

A mixin to produce input forms for services and display errors within these forms.

data_inputRec(request, tag)[source]
data_resultmeta(request, tag)[source]
data_table(request, tag)[source]
data_tableWithRole(role)[source]

returns the table with role.

If no such table is available, this will return an empty string.

form_genForm(request=None, data=None)[source]
parameterStyle = 'form'
submitAction(request, form, data)[source]

executes the service.

This is a callback for the formal form.

class gavo.web.formrender.FormRenderer(request, service)[source]

Bases: ResourceWithForm, FormMixin, CustomTemplateMixin, HTMLResultRenderMixin, ServiceBasedPage

The “normal” renderer within DaCHS for web-facing services.

It will display a form and allow outputs in various formats.

It also does error reporting as long as that is possible within the form.

compute = True
crash(failure, request)[source]
defaultLoader = <XMLFile of '/home/msdemlei/gavo/trunk/gavo/resources/templates/defaultresponse.html'>
defaultOutputFormat = 'HTML'
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}.

handleError(failure, request)
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.

name = 'form'
processOnGET = True
render(request)[source]

Render a given resource. See L{IResource}’s render method.

I delegate to methods of self with the form ‘render_METHOD’ where METHOD is the HTTP that was used to make the request. Examples: render_GET, render_HEAD, render_POST, and so on. Generally you should implement those methods instead of overriding this one.

render_METHOD methods are expected to return a byte string which will be the rendered page, unless the return value is C{server.NOT_DONE_YET}, in which case it is this class’s responsibility to write the results using C{request.write(data)} and then call C{request.finish()}.

Old code that overrides render() directly is likewise expected to return a byte string or NOT_DONE_YET.

@see: L{IResource.render}

runOnEmptyInputs = False
class gavo.web.formrender.MultiField(name, label=None, description=None, cssClass=None, form=None)[source]

Bases: Group, Element

A “widget” containing multiple InputKeys (i.e., formal Fields) in a single line.

childFields(request, tag)[source]
loader: Optional[ITemplateLoader] = <twisted.web._template_util.TagLoader object>
multifield(request, tag)[source]
class gavo.web.formrender.ToFormalConverter[source]

Bases: FromSQLConverter

is a converter from SQL types to Formal type specifications.

The result of the conversion is a tuple of formal type and widget factory.

convert(type, xtype=None)[source]
mapComplex(type, length)[source]
simpleMap = {'bigint': (<class 'gavo.formal.types.Integer'>, <class 'gavo.formal.widget.TextInput'>), 'boolean': (<class 'gavo.formal.types.Boolean'>, <class 'gavo.formal.widget.Checkbox'>), 'char': (<class 'gavo.formal.types.String'>, <class 'gavo.formal.widget.TextInput'>), 'date': (<class 'gavo.formal.types.Date'>, <function widgetFactory.<locals>._>), 'double': (<class 'gavo.formal.types.Float'>, <class 'gavo.formal.widget.TextInput'>), 'double precision': (<class 'gavo.formal.types.Float'>, <class 'gavo.formal.widget.TextInput'>), 'file': (<class 'gavo.formal.types.File'>, None), 'float': (<class 'gavo.formal.types.Float'>, <class 'gavo.formal.widget.TextInput'>), 'int': (<class 'gavo.formal.types.Integer'>, <class 'gavo.formal.widget.TextInput'>), 'integer': (<class 'gavo.formal.types.Integer'>, <class 'gavo.formal.widget.TextInput'>), 'pql-date': (<class 'gavo.formal.types.String'>, <class 'gavo.formal.widget.TextInput'>), 'pql-float': (<class 'gavo.formal.types.String'>, <class 'gavo.formal.widget.TextInput'>), 'pql-int': (<class 'gavo.formal.types.String'>, <class 'gavo.formal.widget.TextInput'>), 'pql-string': (<class 'gavo.formal.types.String'>, <class 'gavo.formal.widget.TextInput'>), 'raw': (<class 'gavo.formal.types.String'>, <class 'gavo.formal.widget.TextInput'>), 'real': (<class 'gavo.formal.types.Float'>, <class 'gavo.formal.widget.TextInput'>), 'smallint': (<class 'gavo.formal.types.Integer'>, <class 'gavo.formal.widget.TextInput'>), 'text': (<class 'gavo.formal.types.String'>, <class 'gavo.formal.widget.TextInput'>), 'time': (<class 'gavo.formal.types.Time'>, <class 'gavo.formal.widget.TextInput'>), 'timestamp': (<class 'gavo.formal.types.Date'>, <function widgetFactory.<locals>._>), 'unicode': (<class 'gavo.formal.types.String'>, <class 'gavo.formal.widget.TextInput'>), 'vexpr-date': (<class 'gavo.formal.types.String'>, <class 'gavo.svcs.customwidgets.DateExpressionField'>), 'vexpr-float': (<class 'gavo.formal.types.String'>, <class 'gavo.svcs.customwidgets.NumericExpressionField'>), 'vexpr-mjd': (<class 'gavo.formal.types.String'>, <class 'gavo.svcs.customwidgets.DateExpressionField'>), 'vexpr-string': (<class 'gavo.formal.types.String'>, <class 'gavo.svcs.customwidgets.StringExpressionField'>)}
typeSystem = 'Formal'
gavo.web.formrender.getFieldArgsForInputKey(inputKey)[source]

returns a dictionary of keyword arguments for gavo.formal addField from a DaCHS InputKey.

gavo.web.formrender.sqltypeToFormal(type, xtype=None)