core.directives
Classes
Register Form view. |
|
Register a cronjob. |
|
Register an analytics provider. |
|
Registers a static files directory. |
|
Registers a set of global template variables for chameleon templates. |
|
Register application setting in a section. |
|
A setting action that takes precedence over a replaced section. |
|
Registers a layout for a model. This is used to show breadcrumbs |
|
Extends the morepath json directive with an |
Functions
|
Given the form_class defined with the form action, together with |
|
Queries the app configuration for the form class associated with |
|
Wraps a view handler with generic form handling. |
|
Like |
Module Contents
- class core.directives.HtmlHandleFormAction(model: type, form: type[wtforms.Form] | collections.abc.Callable[[Any, RequestT], type[wtforms.Form]], render: collections.abc.Callable[[Any, RequestT], webob.Response] | None = None, template: str | None = None, load: collections.abc.Callable[[RequestT], Any] | None = None, permission: object | None = None, internal: bool = False, pass_model: bool = False, **predicates: Any)[source]
Bases:
morepath.directive.HtmlActionRegister Form view.
Basically wraps the Morepath’s
htmldirective, registering both POST and GET (if no specific request method is given) and wrapping the view handler withwrap_with_generic_form_handler().The form is either a class or a function. If it’s a function, it is expected to return a form class when given an instance of the model.
The form may also be None, which is useful under special circumstances. Generally you don’t want that though.
Example:
@App.form(model=Root, template='form.pt', permission=Public, form=LoginForm) def handle_form(self, request, form): if form.submitted(): # do something if the form was submitted with valid data else: # do something if the form was not submitted or not # submitted correctly return {} # template variables
- core.directives.fetch_form_class[FormT: wtforms.Form, RequestT: onegov.core.request.CoreRequest](form_class: type[FormT] | collections.abc.Callable[[Any, RequestT], type[FormT]], model: object, request: RequestT) type[FormT][source]
Given the form_class defined with the form action, together with model and request, this function returns the actual class to be used.
- core.directives.query_form_class(request: onegov.core.request.CoreRequest, model: object, name: str | None = None) type[wtforms.Form] | None[source]
Queries the app configuration for the form class associated with the given model and name. Take this configuration for example:
@App.form(model=Model, form_class=Form, name='foobar') ...
The form class defined here can be retrieved as follows:
query_form_class(request, model=Model, name=’foobar’)
- core.directives.wrap_with_generic_form_handler[T, RequestT: onegov.core.request.CoreRequest, FormT: wtforms.Form](obj: collections.abc.Callable[[T, RequestT, FormT], Any], form_class: type[FormT] | collections.abc.Callable[[T, RequestT], type[FormT]], pass_model: bool) collections.abc.Callable[[T, RequestT], Any][source]
Wraps a view handler with generic form handling.
This includes instantiating the form with translations/csrf protection and setting the correct action.
- class core.directives.CronjobAction(hour: int | str, minute: int | str, timezone: str, once: bool = False)[source]
Bases:
dectate.ActionRegister a cronjob.
- class core.directives.AnalyticsProviderAction(name: str, title: str)[source]
Bases:
dectate.ActionRegister an analytics provider.
- identifier(analytics_provider_registry: dict[str, core.analytics.AnalyticsProvider]) str[source]
- perform(func: type[core.analytics.AnalyticsProvider], analytics_provider_registry: dict[str, type[core.analytics.AnalyticsProvider]]) None[source]
- class core.directives.StaticDirectoryAction[source]
Bases:
dectate.ActionRegisters a static files directory.
- class core.directives.TemplateVariablesAction[source]
Bases:
dectate.ActionRegisters a set of global template variables for chameleon templates.
Only exists once per application. Template variables defined in child applications completely replace the variables defined by the parent application.
Example:
@App.template_variables() def get_template_variables(request): return { 'foo': 'bar' }
- class core.directives.ReplaceSettingSectionAction(section: str)[source]
Bases:
dectate.ActionRegister application setting in a section.
In contrast to the regular SettingSectionAction this completely replaces the existing section.
- class core.directives.ReplaceSettingAction[source]
Bases:
morepath.directive.SettingActionA setting action that takes precedence over a replaced section.
So we can override single settings without overriding the whole section.
- class core.directives.Layout(model: type)[source]
Bases:
dectate.ActionRegisters a layout for a model. This is used to show breadcrumbs for search results.
- core.directives.render_json_open_data(content: object, request: morepath.Request) webob.Response[source]
Like
morepath.render_json(), but adds anAccess-Control-Allow-Origin: *header to GET and HEAD responses, making the endpoint accessible from browser scripts on any origin.
- class core.directives.ExtendedJsonAction(model: type, render: collections.abc.Callable[[Any, Any], webob.Response] | None = None, template: str | None = None, load: collections.abc.Callable[[Any], Any] | None = None, permission: object = None, internal: bool = False, open_data: bool = False, **predicates: Any)[source]
Bases:
morepath.directive.JsonActionExtends the morepath json directive with an
open_dataparameter.When
open_data=False(the default), the views should not be publicly accessible cross-origin.When
open_data=True, the view’s GET and HEAD responses will include anAccess-Control-Allow-Origin: *header, making it usable from browser scripts on any origin.