Onegov Org API¶
Application¶
Contains the base application used by other applications.
-
class
onegov.org.app.
OrgApp
[source]¶ -
request_class
¶ alias of
onegov.org.request.OrgRequest
-
classmethod
homepage_widget
(*args, **kw)¶ org directives
-
classmethod
export
(*args, **kw)¶ Register an export.
-
classmethod
userlinks
(*args, **kw)¶ Registers a user link group.
-
classmethod
directory_search_widget
(*args, **kw)¶ Registers a directory search widget.
-
classmethod
settings_view
(*args, **kw)¶ Registers a settings view.
-
send_daily_ticket_statistics
= True¶ cronjob settings
-
is_allowed_application_id
(application_id)[source]¶ Stops onegov.server from ever passing the request to the org application, if the schema does not exist. This way we can host onegov.org in a way that allows all requests to *.example.org
If the schema for
newyork.example.org
exists, the request is handled. If the schema does not exist, the request is not handled.Here we basically decide if an org exists or not.
-
configure_application
(**cfg)[source]¶ Configures the application. This function calls all methods on the current class which start with
configure_
, passing the configuration as keyword arguments.The core itself supports the following parameters. Additional parameters are made available by extra
configure_
methods.- Dsn
The database connection to use. May be None.
See
onegov.core.orm.session_manager.setup()
- Base
The declarative base class used. By default,
onegov.core.orm.Base
is used.- Identity_secure
True if the identity cookie is only transmitted over https. Only set this to False during development!
- Identity_secret
A random string used to sign the identity. By default a random string is generated. The drawback of this is the fact that users will be logged out every time the application restarts.
So provide your own if you don’t want that, but be sure to have a really long, really random key that you will never share with anyone!
- Redis_url
The redis url used (default is ‘redis://localhost:6379/0’).
- File_storage
The file_storage module to use. See http://docs.pyfilesystem.org/en/latest/filesystems.html
- File_storage_options
A dictionary of options passed to the
__init__
method of the file_storage class.The file storage is expected to work as is. For example, if
fs.osfs.OSFS
is used, the root_path is expected exist.The file storage can be shared between different onegov.core applications. Each application automatically gets its own namespace inside this space.
- Always_compile_theme
If true, the theme is always compiled - no caching is employed.
- Allow_shift_f5_comple
If true, the theme is recompiled if shift+f5 is done on the browser (or shift + reload button click).
- Csrf_secret
A random string used to sign the csrf token. Make sure this differs from
identity_secret
! The algorithms behind identity_secret and the csrf protection differ. If the same secret is used we might leak information about said secret.By default a random string is generated. The drawback of this is the fact that users won’t be able to submit their forms if the app is restarted in the background.
So provide your own, but be sure to have a really long, really random string that you will never share with anyone!
- Csrf_time_limit
The csrf time limit in seconds. Basically the amount of time a user has to submit a form, from the time it’s rendered.
Defaults to 1’200s (20 minutes).
A dictionary keyed by e-mail category (i.e. ‘marketing’, ‘transactional’) with the following subkeys:
host: The mail server to send e-mails from.
port: The port used for the mail server.
force_tls: True if TLS should be forced.
username: The mail username
password: The mail password
sender: The mail sender
use_directory: True if a mail directory should be used
directory: Path to the directory that should be used
- Mail_use_directory
If true, mails are stored in the maildir defined through
mail_directory
. There, some other process is supposed to pick up the e-mails and send them.- Mail_directory
The directory (maildir) where mails are stored if if
mail_use_directory
is set to True.- Sql_query_report
Prints out a report sql queries for each request, unless False. Valid values are:
‘summary’ (only show the number of queries)
‘redundant’ (show summary and the actual redundant queries)
‘all’ (show summary and all executed queries)
Do not use in production!
- Profile
If true, profiles the request and stores the result in the profiles folder with the following format:
YYYY-MM-DD hh:mm:ss.profile
Do not use in production!
- Print_exceptions
If true, exceptions are printed to stderr. Note that you should usually configure logging through onegov.server. This is mainly used for certain unit tests where we use WSGI more directly.
-
send_email
(**kwargs)[source]¶ Wraps
onegov.core.framework.Framework.send_email()
, setting the reply_to address by using the reply address from the organisation settings.
-
property
theme_options
¶ Returns the application-bound theme options.
-
Commandline Interface¶
Provides commands used to initialize org websites.
Directives¶
-
class
onegov.org.directives.
HomepageWidgetAction
(tag)[source]¶ Register a cronjob.
-
identifier
(homepage_widget_registry)[source]¶ Returns an immutable that uniquely identifies this config.
Needs to be implemented by the
Action
subclass.Used for overrides and conflict detection.
If two actions in the same group have the same identifier in the same configurable, those two actions are in conflict and a
ConflictError
is raised duringcommit()
.If an action in an extending configurable has the same identifier as the configurable being extended, that action overrides the original one in the extending configurable.
- Parameters
**kw – a dictionary of configuration objects as specified by the
config
class attribute.- Returns
an immutable value uniquely identifying this action.
-
perform
(func, homepage_widget_registry)[source]¶ Do whatever configuration is needed for
obj
.Needs to be implemented by the
Action
subclass.Raise a
DirectiveError
to indicate that the action cannot be performed due to incorrect configuration.- Parameters
obj – the object that the action should be performed for. Typically a function or a class object.
**kw – a dictionary of configuration objects as specified by the
config
class attribute.
-
-
class
onegov.org.directives.
ExportAction
(id, **kwargs)[source]¶ Register an export.
-
identifier
(export_registry)[source]¶ Returns an immutable that uniquely identifies this config.
Needs to be implemented by the
Action
subclass.Used for overrides and conflict detection.
If two actions in the same group have the same identifier in the same configurable, those two actions are in conflict and a
ConflictError
is raised duringcommit()
.If an action in an extending configurable has the same identifier as the configurable being extended, that action overrides the original one in the extending configurable.
- Parameters
**kw – a dictionary of configuration objects as specified by the
config
class attribute.- Returns
an immutable value uniquely identifying this action.
-
perform
(cls, export_registry)[source]¶ Do whatever configuration is needed for
obj
.Needs to be implemented by the
Action
subclass.Raise a
DirectiveError
to indicate that the action cannot be performed due to incorrect configuration.- Parameters
obj – the object that the action should be performed for. Typically a function or a class object.
**kw – a dictionary of configuration objects as specified by the
config
class attribute.
-
-
class
onegov.org.directives.
UserlinkAction
[source]¶ Registers a user link group.
-
identifier
(linkgroup_registry)[source]¶ Returns an immutable that uniquely identifies this config.
Needs to be implemented by the
Action
subclass.Used for overrides and conflict detection.
If two actions in the same group have the same identifier in the same configurable, those two actions are in conflict and a
ConflictError
is raised duringcommit()
.If an action in an extending configurable has the same identifier as the configurable being extended, that action overrides the original one in the extending configurable.
- Parameters
**kw – a dictionary of configuration objects as specified by the
config
class attribute.- Returns
an immutable value uniquely identifying this action.
-
perform
(func, linkgroup_registry)[source]¶ Do whatever configuration is needed for
obj
.Needs to be implemented by the
Action
subclass.Raise a
DirectiveError
to indicate that the action cannot be performed due to incorrect configuration.- Parameters
obj – the object that the action should be performed for. Typically a function or a class object.
**kw – a dictionary of configuration objects as specified by the
config
class attribute.
-
-
class
onegov.org.directives.
DirectorySearchWidgetAction
(name)[source]¶ Registers a directory search widget.
-
identifier
(directory_search_widget_registry)[source]¶ Returns an immutable that uniquely identifies this config.
Needs to be implemented by the
Action
subclass.Used for overrides and conflict detection.
If two actions in the same group have the same identifier in the same configurable, those two actions are in conflict and a
ConflictError
is raised duringcommit()
.If an action in an extending configurable has the same identifier as the configurable being extended, that action overrides the original one in the extending configurable.
- Parameters
**kw – a dictionary of configuration objects as specified by the
config
class attribute.- Returns
an immutable value uniquely identifying this action.
-
perform
(cls, directory_search_widget_registry)[source]¶ Do whatever configuration is needed for
obj
.Needs to be implemented by the
Action
subclass.Raise a
DirectiveError
to indicate that the action cannot be performed due to incorrect configuration.- Parameters
obj – the object that the action should be performed for. Typically a function or a class object.
**kw – a dictionary of configuration objects as specified by the
config
class attribute.
-
-
class
onegov.org.directives.
SettingsView
(name, title, order=0, icon='fa-cogs')[source]¶ Registers a settings view.
-
identifier
(settings_view_registry)[source]¶ Returns an immutable that uniquely identifies this config.
Needs to be implemented by the
Action
subclass.Used for overrides and conflict detection.
If two actions in the same group have the same identifier in the same configurable, those two actions are in conflict and a
ConflictError
is raised duringcommit()
.If an action in an extending configurable has the same identifier as the configurable being extended, that action overrides the original one in the extending configurable.
- Parameters
**kw – a dictionary of configuration objects as specified by the
config
class attribute.- Returns
an immutable value uniquely identifying this action.
-
perform
(func, settings_view_registry)[source]¶ Do whatever configuration is needed for
obj
.Needs to be implemented by the
Action
subclass.Raise a
DirectiveError
to indicate that the action cannot be performed due to incorrect configuration.- Parameters
obj – the object that the action should be performed for. Typically a function or a class object.
**kw – a dictionary of configuration objects as specified by the
config
class attribute.
-
Homepage Widgets¶
-
onegov.org.homepage_widgets.core.
parse_structure
(widgets, structure)[source]¶ Takes the XML homepage structure and returns the parsed etree xml.
Raises a wtforms.ValidationError if there’s an element which is not supported.
We could do this with DTDs but we don’t actually need to, since we only care to not include any unknown tags.
Note that we try to make sure that this is no vector for remote code execution, but we ultimately do not guarantee it can’t happen.
This xml structure is meant to be static or possibly changeable by admins. Ordinary users should not be able to influence this structure.
Layout¶
-
class
onegov.org.layout.
Layout
(*args, **kwargs)[source]¶ Contains methods to render a page inheriting from layout.pt.
All pages inheriting from layout.pt rely on this class being present as ‘layout’ variable:
@OrgApp.html(model=Example, template='example.pt', permission=Public) def view_example(self, request): return { 'layout': DefaultLayout(self, request) }
It is meant to be extended for different parts of the site. For example, the
DefaultLayout
includes the top navigation defined by onegov.page.It’s possible though to have a different part of the website use a completely different top navigation. For that, a new Layout class inheriting from this one should be added.
-
property
name
¶ Takes the class name of the layout and generates a name which can be used as a class.
-
property
org
¶ An alias for self.request.app.org.
-
page_id
¶ Returns the unique page id of the rendered page. Used to have a useful id in the body element for CSS/JS.
-
body_classes
¶ Yields a list of body classes used on the body.
Returns a list of
onegov.org.elements.Link
objects. Those links are used for the top navigation.If nothing is returned, no top navigation is displayed.
Returns a list of
onegov.org.elements.Link
objects. Those links are used for the breadcrumbs.If nothing is returned, no top breadcrumbs are displayed.
A list of links shown in the sidebar, used for navigation.
-
editbar_links
¶ A of
onegov.org.elements.LinkGroup
classes. Each of them will be shown in the top editbar, with the group title being the dropdown title.
-
file_upload_url
¶ Returns the url to the file upload action.
-
file_upload_json_url
¶ Adds the json url for file uploads.
-
file_list_url
¶ Adds the json url for file lists.
-
image_upload_url
¶ Returns the url to the image upload action.
-
image_upload_json_url
¶ Adds the json url for image uploads.
-
image_list_url
¶ Adds the json url for image lists.
-
sitecollection_url
¶ Adds the json url for internal links lists.
-
homepage_url
¶ Returns the url to the main page.
-
search_url
¶ Returns the url to the search page.
-
suggestions_url
¶ Returns the url to the suggestions json view.
-
property
-
class
onegov.org.layout.
DefaultLayout
(model, request)[source]¶ The defaut layout meant for the public facing parts of the site.
-
hide_from_robots
()[source]¶ Returns a X-Robots-Tag:noindex header on secret pages.
This is probably not where you would expect this to happen, but it ensures that this works on all pages without having to jump through hoops.
Returns the breadcrumbs for the current page.
-
-
class
onegov.org.layout.
DefaultMailLayout
(*args, **kwargs)[source]¶ A special layout for creating HTML E-Mails.
-
contact_html
¶ Returns the contacts html, but instead of breaking it into multiple lines (like on the site footer), this version puts it all on one line.
-
-
class
onegov.org.layout.
AdjacencyListLayout
(model, request)[source]¶ Provides layouts for for models inheriting from
onegov.core.orm.abstract.AdjacencyList
Yields the breadcrumbs for the given adjacency list item.
Yields the sidebar for the given adjacency list item.
-
class
onegov.org.layout.
AllocationEditFormLayout
(model, request)[source]¶ Same as the resource layout, but with different editbar links, because there’s not really an allocation view, but there are allocation forms.
Models¶
-
class
onegov.org.models.clipboard.
Clipboard
(request, token)[source]¶ The clipboard holds a url that should be copied and then pasted. The url is expected to be stored in a token that has been created by
onegov.core.request.CoreRequest.new_url_safe_token()
.The reason behind this is that the url is used to fetch the object behind the url in an unrestricted fashion.
Contains the model describing the page editor.
-
class
onegov.org.models.editor.
Editor
(action, page, trait=None)[source]¶ Defines the model for the page editor. Required because pages need to be edited outside their url structure, since their urls are absorbed completely and turned into SQL queries.
-
property
page_id
¶ Returns the page id so morepath can create a link to this.
-
property
-
class
onegov.org.models.extensions.
ContentExtension
[source]¶ Extends classes based on
onegov.core.orm.mixins.ContentMixin
with custom data that is stored in either ‘meta’ or ‘content’.-
property
content_extensions
¶ Returns all base classes of the current class which themselves have
ContentExtension
as baseclass.
-
property
-
class
onegov.org.models.extensions.
AccessExtension
[source]¶ Extends any class that has a meta dictionary field with the ability to set one of the following access levels:
‘public’ - The default, the model is listed and accessible.
‘private’ - Neither listed nor accessible.
‘secret’ - Not listed, but available for anyone that knows the URL.
see
onegov.core.security.rules.has_permission_not_logged_in()
-
class
onegov.org.models.extensions.
CoordinatesExtension
[source]¶ Extends any class that has a data dictionary field with the ability to add coordinates to it.
-
class
onegov.org.models.extensions.
VisibleOnHomepageExtension
[source]¶ Extends any class that has a meta dictionary field with the ability to a boolean indicating if the page should be shown on the homepage or not.
-
class
onegov.org.models.extensions.
ContactExtension
[source]¶ Extends any class that has a content dictionary field with a simple contacts field.
-
class
onegov.org.models.extensions.
PersonLinkExtension
[source]¶ Extends any class that has a content dictionary field with the ability to reference people from
onegov.people.PersonCollection
.-
property
people
¶ Returns the people linked to this content or None.
The context specific function is temporarily stored on the
context_specific_function
attribute on each object in the resulting list.
-
property
Contains the models describing files and images.
-
class
onegov.org.models.file.
DateInterval
(name, start, end)¶ -
end
¶ Alias for field number 2
-
name
¶ Alias for field number 0
-
start
¶ Alias for field number 1
-
-
class
onegov.org.models.file.
GeneralFile
(**kwargs)[source]¶ -
property
es_public
¶ Returns True if the model is available to be found by the public. If false, only editors/admins will see this object in the search results.
-
property
-
class
onegov.org.models.file.
ImageSet
(**kwargs)[source]¶ -
property
es_public
¶ Returns True if the model is available to be found by the public. If false, only editors/admins will see this object in the search results.
-
property
Contains the legacy models of files for url redirect support. Going forward, onegov.file and onegov.org.models.file is used.
-
class
onegov.org.models.legacy_file.
LegacyFile
(filename, info=None)[source]¶ A filestorage file that points to an uploaded image or file.
-
class
onegov.org.models.legacy_file.
LegacyImage
(filename, info=None)[source]¶ A filestorage file that points to a full image (not a thumbnail).
-
class
onegov.org.models.page.
Topic
(title, parent=None, **kwargs)[source]¶ -
property
es_skip
¶ Returns True if the indexing of this specific model instance should be skipped.
-
property
deletable
¶ Returns true if this page may be deleted.
-
property
paste_target
¶ Returns the page that should be used as parent for the content pasting if paste is called on the current page (self).
This is usually just self. If the paste action should put the content alongside the current page, it would be the parent.
-
property
allowed_subtraits
¶ Returns a list of traits that this page may contain.
-
property
-
class
onegov.org.models.page.
News
(title, parent=None, **kwargs)[source]¶ -
property
absorb
¶ Alias for
path
. This is a convenience feature for Morepath if a path is absorbed.See http://morepath.readthedocs.org/en/latest/paths_and_linking.html?highlight=absorb#absorbing
-
property
paste_target
¶ Returns the page that should be used as parent for the content pasting if paste is called on the current page (self).
This is usually just self. If the paste action should put the content alongside the current page, it would be the parent.
-
property
allowed_subtraits
¶ Returns a list of traits that this page may contain.
-
property
-
class
onegov.org.models.page_move.
AdjacencyListMove
(session, subject, target, direction)[source]¶ Represents a single move of an adjacency list item.
-
class
onegov.org.models.person_move.
PersonMove
(session, obj, subject, target, direction)[source]¶ Represents a single move of a linked person.
-
class
onegov.org.models.person_move.
PagePersonMove
(session, obj, subject, target, direction)[source]¶ Represents a single move of a linked person on a page.
-
class
onegov.org.models.person_move.
FormPersonMove
(session, obj, subject, target, direction)[source]¶ Represents a single move of a linked person on a form definition.
-
class
onegov.org.models.person_move.
ResourcePersonMove
(session, obj, subject, target, direction)[source]¶ Represents a single move of a linked person on a form definition.
-
class
onegov.org.models.search.
Search
(request, query, page)[source]¶ -
subset
()[source]¶ Returns an SQLAlchemy query containing all records that should be considered for pagination.
-
property
page_index
¶ Returns the current page index (starting at 0).
-
-
class
onegov.org.models.ticket.
OrgTicketMixin
[source]¶ Adds additional methods to the ticket, needed by the organisations implementation of it. Strictly limited to things that do not belong into onegov.ticket.
-
reference
(request)[source]¶ Returns the reference which should be used wherever we talk about a ticket, but do not show it (say in an e-mail subject).
This reference should not be changed so it stays consistent.
If you want, you can override the content of the reference group, shown in brackets (see
reference_group()
).
-
-
class
onegov.org.models.ticket.
FormSubmissionHandler
(ticket, handler_id, handler_data)[source]¶ -
property
deleted
¶ Returns true if the underlying model was deleted. It is best to never let that happen, as we want tickets to stay around forever.
However, this can make sense in certain scenarios. Note that if you do delete your underlying model, make sure to call
onegov.ticket.models.Ticket.create_snapshot()
beforehand!
-
property
email
¶ Returns the email address behind the ticket request.
-
property
title
¶ Returns the title of the ticket. If this title may change over time, the handler must call
self.refresh()
when there’s a change.
-
property
group
¶ Returns the group of the ticket. If this group may change over time, the handler must call
self.refresh()
when there’s a change.
-
property
payment
¶ An optional link to a onegov.pay payment record.
-
property
extra_data
¶ An array of string values which are indexed in elasticsearch when the ticket is stored there.
-
property
undecided
¶ Returns true if there has been no decision about the subject of this handler.
For example, if a reservation ticket has been accepted, but the reservation has been neither confirmed nor cancelled, the ticket can be seen as undecided.
This is an optional flag that may be implemented by handlers. If a ticket is undecided, the UI might show a special icon and it might warn the user if he closes the ticket without making a decision.
By default, the ticket is assumed to be decided for backwards compatibility and for tickets where this does not make sense (a simple form submission may not have any way of knowing if there has been a decision or not).
-
property
-
class
onegov.org.models.ticket.
ReservationHandler
(ticket, handler_id, handler_data)[source]¶ -
property
payment
¶ An optional link to a onegov.pay payment record.
-
property
deleted
¶ Returns true if the underlying model was deleted. It is best to never let that happen, as we want tickets to stay around forever.
However, this can make sense in certain scenarios. Note that if you do delete your underlying model, make sure to call
onegov.ticket.models.Ticket.create_snapshot()
beforehand!
-
property
extra_data
¶ An array of string values which are indexed in elasticsearch when the ticket is stored there.
-
property
email
¶ Returns the email address behind the ticket request.
-
property
undecided
¶ Returns true if there has been no decision about the subject of this handler.
For example, if a reservation ticket has been accepted, but the reservation has been neither confirmed nor cancelled, the ticket can be seen as undecided.
This is an optional flag that may be implemented by handlers. If a ticket is undecided, the UI might show a special icon and it might warn the user if he closes the ticket without making a decision.
By default, the ticket is assumed to be decided for backwards compatibility and for tickets where this does not make sense (a simple form submission may not have any way of knowing if there has been a decision or not).
-
property
title
¶ Returns the title of the ticket. If this title may change over time, the handler must call
self.refresh()
when there’s a change.
-
property
group
¶ Returns the group of the ticket. If this group may change over time, the handler must call
self.refresh()
when there’s a change.
-
classmethod
handle_extra_parameters
(session, query, extra_parameters)[source]¶ Takes a dictionary of extra parameters and uses it to optionally modifiy the query used for the collection.
Use this to add handler-defined custom filters with extra query parameters. Only called if the collection is already limited to the given handler. If all handlers are shown in the collection, this method is not called.
If no extra paramaters were given, this method is not called.
Returns the modified or unmodified query.
-
property
-
class
onegov.org.models.ticket.
EventSubmissionHandler
(ticket, handler_id, handler_data)[source]¶ -
property
deleted
¶ Returns true if the underlying model was deleted. It is best to never let that happen, as we want tickets to stay around forever.
However, this can make sense in certain scenarios. Note that if you do delete your underlying model, make sure to call
onegov.ticket.models.Ticket.create_snapshot()
beforehand!
-
property
title
¶ Returns the title of the ticket. If this title may change over time, the handler must call
self.refresh()
when there’s a change.
-
property
extra_data
¶ An array of string values which are indexed in elasticsearch when the ticket is stored there.
-
property
undecided
¶ Returns true if there has been no decision about the subject of this handler.
For example, if a reservation ticket has been accepted, but the reservation has been neither confirmed nor cancelled, the ticket can be seen as undecided.
This is an optional flag that may be implemented by handlers. If a ticket is undecided, the UI might show a special icon and it might warn the user if he closes the ticket without making a decision.
By default, the ticket is assumed to be decided for backwards compatibility and for tickets where this does not make sense (a simple form submission may not have any way of knowing if there has been a decision or not).
-
property
-
class
onegov.org.models.ticket.
DirectoryEntryHandler
(ticket, handler_id, handler_data)[source]¶ -
property
deleted
¶ Returns true if the underlying model was deleted. It is best to never let that happen, as we want tickets to stay around forever.
However, this can make sense in certain scenarios. Note that if you do delete your underlying model, make sure to call
onegov.ticket.models.Ticket.create_snapshot()
beforehand!
-
property
email
¶ Returns the email address behind the ticket request.
-
property
title
¶ Returns the title of the ticket. If this title may change over time, the handler must call
self.refresh()
when there’s a change.
-
property
group
¶ Returns the group of the ticket. If this group may change over time, the handler must call
self.refresh()
when there’s a change.
-
property
payment
¶ An optional link to a onegov.pay payment record.
-
property
extra_data
¶ An array of string values which are indexed in elasticsearch when the ticket is stored there.
-
property
undecided
¶ Returns true if there has been no decision about the subject of this handler.
For example, if a reservation ticket has been accepted, but the reservation has been neither confirmed nor cancelled, the ticket can be seen as undecided.
This is an optional flag that may be implemented by handlers. If a ticket is undecided, the UI might show a special icon and it might warn the user if he closes the ticket without making a decision.
By default, the ticket is assumed to be decided for backwards compatibility and for tickets where this does not make sense (a simple form submission may not have any way of knowing if there has been a decision or not).
-
property
Contains the model describing the organisation proper.
-
class
onegov.org.models.organisation.
Organisation
(**kwargs)[source]¶ Defines the basic information associated with an organisation.
It is assumed that there’s only one organisation record in the schema!
-
id
¶ the id of the organisation, an automatically generated uuid
-
name
¶ the name of the organisation
-
logo_url
¶ the logo of the organisation
-
theme_options
¶ the theme options of the organisation
-
meta
¶ additional data associated with the organisation
-
property
public_identity
¶ The public identity is a globally unique SHA 256 hash of the current organisation.
Basically, this is the database record of the database, but mangled for security and because it is cooler 😎.
This value can be accessed through /identity.
-
property
holidays
¶ Returns a SwissHolidays instance, as configured by the holiday_settings on the UI.
-
-
onegov.org.models.traitinfo.
TRAIT_MESSAGES
= {'link': {'delete_button': 'Delete link', 'delete_message': 'The link was deleted', 'delete_question': 'Do you really want to delete the link "${title}"?', 'edit_page_title': 'Edit Link', 'name': 'Link', 'new_page_added': 'Added a new link', 'new_page_title': 'New Link'}, 'news': {'delete_button': 'Delete news', 'delete_message': 'The news was deleted', 'delete_question': 'Do you really want to delete the news "${title}"?', 'edit_page_title': 'Edit News', 'name': 'News', 'new_page_added': 'Added news', 'new_page_title': 'Add News'}, 'page': {'delete_button': 'Delete topic', 'delete_message': 'The topic was deleted', 'delete_question': 'Do you really want to delete the topic "${title}"?', 'edit_page_title': 'Edit Topic', 'name': 'Topic', 'new_page_added': 'Added a new topic', 'new_page_title': 'New Topic'}}¶ Contains the messages that differ for each trait (the handling of all traits is the same). New traits need to adapt the same messages as the others.
-
class
onegov.org.models.traitinfo.
TraitInfo
[source]¶ ” Typically used as a mixin for adjacency list based models, this class provides access to the trait related methods.
Traits are like subtypes of models. For example, the Page model has a page trait and a link trait. Both are managed under the same tree as the same type (Page), but one is rendered as a redirect, the other as a normal page.
-
property
trait
¶ Gets the trait of the page.
-
property
trait_messages
¶ Returns all trait_messages.
-
property
allowed_subtraits
¶ Returns a list of traits that this page may contain.
-
property
paste_target
¶ Returns the page that should be used as parent for the content pasting if paste is called on the current page (self).
This is usually just self. If the paste action should put the content alongside the current page, it would be the parent.
-
property
Paths¶
Contains the paths to the different models served by onegov.org.
-
onegov.org.path.
get_file_for_org
(request, app, id)[source]¶ Some files are kept private and out of any caches.
This approach is not all that morepath-y, as we could override the views instead to change the required permissions, but this approach has the advantage that we don’t need to overwrite multiple views and we do not have to care for additional views added in the future.
Form Models¶
-
class
onegov.org.forms.allocation.
AllocationRuleForm
(*args, **kwargs)[source]¶ Base form form allocation rules.
-
class
onegov.org.forms.allocation.
AllocationForm
(*args, **kwargs)[source]¶ Baseform for all allocation forms. Allocation forms are expected to implement the methods above (which contain a NotImplementedException).
Have a look at
libres.db.scheduler.Scheduler.allocate()
to find out more about those values.-
property
weekdays
¶ The rrule weekdays derived from the except_for field.
-
property
dates
¶ Passed to
libres.db.scheduler.Scheduler.allocate()
.
-
property
whole_day
¶ Passed to
libres.db.scheduler.Scheduler.allocate()
.
-
property
partly_available
¶ Passed to
libres.db.scheduler.Scheduler.allocate()
.
-
property
quota
¶ Passed to
libres.db.scheduler.Scheduler.allocate()
.
-
property
quota_limit
¶ Passed to
libres.db.scheduler.Scheduler.allocate()
.
-
property
data
¶ Passed to
libres.db.scheduler.Scheduler.allocate()
.
-
property
-
class
onegov.org.forms.allocation.
AllocationEditForm
(*args, **kwargs)[source]¶ Baseform for edit forms. Edit forms differ from the base allocation form somewhat, since they don’t offer a way to generate more than one allocation at a time.
The dates property is therefore expected to return a single start, end dates tuple.
-
class
onegov.org.forms.allocation.
DaypassAllocationForm
(*args, **kwargs)[source]¶ -
property
quota
¶ Passed to
libres.db.scheduler.Scheduler.allocate()
.
-
property
quota_limit
¶ Passed to
libres.db.scheduler.Scheduler.allocate()
.
-
property
dates
¶ Passed to
libres.db.scheduler.Scheduler.allocate()
.
-
property
-
class
onegov.org.forms.allocation.
RoomAllocationForm
(*args, **kwargs)[source]¶ -
property
whole_day
¶ Passed to
libres.db.scheduler.Scheduler.allocate()
.
-
property
partly_available
¶ Passed to
libres.db.scheduler.Scheduler.allocate()
.
-
property
dates
¶ Passed to
libres.db.scheduler.Scheduler.allocate()
.
-
property
-
class
onegov.org.forms.event.
EventForm
(*args, **kwargs)[source]¶ Defines the form for all events.
-
validate
()[source]¶ Make sure a valid RRULE can be generated with the given fields.
Might be better to group weekly and end_date in an enclosure, see See http://wtforms.readthedocs.org/en/latest/fields.html #field-enclosures.
-
-
class
onegov.org.forms.form_definition.
FormDefinitionBaseForm
(*args, **kwargs)[source]¶ Form to edit defined forms.
-
class
onegov.org.forms.page.
PageBaseForm
(*args, **kwargs)[source]¶ Defines the base form for all pages.
-
class
onegov.org.forms.page.
LinkForm
(*args, **kwargs)[source]¶ Defines the form for pages with the ‘link’ trait.
-
class
onegov.org.forms.page.
PageForm
(*args, **kwargs)[source]¶ Defines the form for pages with the ‘page’ trait.
-
class
onegov.org.forms.resource.
ResourceBaseForm
(*args, **kwargs)[source]¶ Defines the form for all resources.
-
class
onegov.org.forms.resource.
ResourceCleanupForm
(*args, **kwargs)[source]¶ Defines the form to remove multiple allocations.
-
class
onegov.org.forms.resource.
ResourceExportForm
(*args, **kwargs)[source]¶ Resource export form with start/end date.
-
class
onegov.org.forms.settings.
GeneralSettingsForm
(*args, **kwargs)[source]¶ Defines the settings form for onegov org.
-
class
onegov.org.forms.settings.
HomepageSettingsForm
(*args, **kwargs)[source]¶
-
class
onegov.org.forms.settings.
HolidaySettingsForm
(*args, **kwargs)[source]¶
-
class
onegov.org.forms.userprofile.
UserProfileForm
(*args, **kwargs)[source]¶ Defines the settings form for user profiles.
Views¶
-
onegov.org.views.allocation.
view_allocations_json
(self, request)[source]¶ Returns the allocations in a fullcalendar compatible events feed.
See http://fullcalendar.io/docs/event_data/events_json_feed/ for more information.
-
onegov.org.views.allocation.
process_rules
(self, request)[source]¶ Manually runs the rules processing cronjobs for testing.
Not really dangerous, though it should be replaced with something proper instead, cronjobs currently do not run in most tests and that should be remedied.
-
onegov.org.views.allocation.
get_new_allocation_form_class
(resource, request)[source]¶ Returns the form class for new allocations (different resources have different allocation forms).
-
onegov.org.views.allocation.
get_edit_allocation_form_class
(allocation, request)[source]¶ Returns the form class for existing allocations (different resources have different allocation forms).
-
onegov.org.views.allocation.
get_allocation_rule_form_class
(resource, request)[source]¶ Returns the form class for allocation rules.
-
onegov.org.views.allocation.
handle_new_allocation
(self, request, form)[source]¶ Handles new allocations for differing form classes.
-
onegov.org.views.allocation.
handle_edit_allocation
(self, request, form)[source]¶ Handles edit allocation for differing form classes.
-
onegov.org.views.allocation.
handle_delete_allocation
(self, request)[source]¶ Deletes the given resource (throwing an error if there are existing reservations associated with it).
-
onegov.org.views.allocation.
rule_id_from_request
(request)[source]¶ Returns the rule_id from the request params, ensuring that an actual uuid is returned.
-
onegov.org.views.allocation.
handle_rules_cronjob
(resource, request)[source]¶ Handles all cronjob duties of the rules stored on the given resource.
-
onegov.org.views.allocation.
delete_rule
(resource, rule_id)[source]¶ Removes the given rule from the resource.
The authentication views.
-
onegov.org.views.auth.
handle_registration
(self, request, form)[source]¶ Handles the user registration.
-
onegov.org.views.auth.
handle_password_reset_request
(self, request, form)[source]¶ Handles the GET and POST password reset requests.
Implements the adding/editing/removing of pages.
The onegov org collection of images uploaded to the site.
-
onegov.org.views.event.
assert_anonymous_access_only_temporary
(request, event)[source]¶ Raises exceptions if the current user is anonymous and no longer should be given access to the event.
This could probably be done using morepath’s security system, but it would not be quite as straight-forward. This approach is, though we have to manually add this function to all public views the anonymous user should be able to access when creating a new event, but not anymore after that.
-
onegov.org.views.event.
handle_new_event
(self, request, form)[source]¶ Add a new event.
The event is created and the user is redirected to a view where he can review his submission and submit it finally.
-
onegov.org.views.event.
view_event
(self, request)[source]¶ View an event.
If the event is not already submitted, the submit form is displayed.
A logged-in user can view all events and might edit them, an anonymous user will be redirected.
-
onegov.org.views.event.
handle_edit_event
(self, request, form)[source]¶ Edit an event.
An anonymous user might edit an initiated event, a logged in user can also edit all events.
-
onegov.org.views.event.
ical_export_event
(self, request)[source]¶ Returns the event with all occurrences as ics.
-
onegov.org.views.event.
view_latest_event
(self, request)[source]¶ Redirects to the latest occurrence of an event that is, either the next future event or the last event in the past if there are no more future events.
-
onegov.org.views.exceptionviews.
handle_forbidden
(self, request)[source]¶ If a view is forbidden, the request is redirected to the login view. There, the user may login to the site and be redirected back to the originally forbidden view.
The onegov org collection of files uploaded to the site.
-
class
onegov.org.views.files.
Img
(src, alt=None, title=None, url=None, extra=None, width=None, height=None)[source]¶ Represents an img element.
-
src
¶ The src of the image
-
alt
¶ The text for people that can’t or won’t look at the picture
-
title
¶ The title of the image
-
url
¶ The target of this image
-
width
¶ The width of the image in pixel
-
height
¶ The height of the image in pixel
-
extra
¶ Extra parameters
-
-
onegov.org.views.files.
handle_file_upload
(self, request)[source]¶ Stores the file given with the request and returns the new file object.
-
onegov.org.views.files.
view_old_files_redirect
(self, request)[source]¶ Redirects to the migrated depot file if possible. As a result, old image urls are preserved and will continue to function.
Lists the custom forms.
Renders and handles defined forms, turning them into submissions.
-
onegov.org.views.form_submission.
handle_defined_form
(self, request, form)[source]¶ Renders the empty form and takes input, even if it’s not valid, stores it as a pending submission and redirects the user to the view that handles pending submissions.
-
onegov.org.views.form_submission.
handle_pending_submission
(self, request)[source]¶ Renders a pending submission, takes it’s input and allows the user to turn the submission into a complete submission, once all data is valid.
This view has two states, a completeable state where the form values are displayed without a form and an edit state, where a form is rendered to change the values.
Takes the following query parameters for customization:
* ``edit`` render the view in the edit state * ``return-to`` the view redirects to this url once complete * ``title`` a custom title (required if external submission) * ``quiet`` no success messages are rendered if present
The onegov organisation homepage.
The newsletter view.
The onegov org collection of images uploaded to the site.
-
onegov.org.views.occurrence.
view_occurrences
(self, request)[source]¶ View all occurrences of all events.
-
onegov.org.views.occurrence.
view_occurrence
(self, request)[source]¶ View a single occurrence of an event.
-
onegov.org.views.occurrence.
ical_export_occurence
(self, request)[source]¶ Returns the occurrence as ics.
-
onegov.org.views.occurrence.
ical_export_occurences
(self, request)[source]¶ Returns the occurrences as ics.
-
onegov.org.views.occurrence.
export_occurrences
(self, request, form)[source]¶ Export the occurrences in various formats.
-
onegov.org.views.occurrence.
json_export_occurences
(self, request)[source]¶ Returns the occurrences as JSON.
This is used for the senantis.dir.eventsportlet.
Renders a onegov.page.
-
onegov.org.views.reservation.
assert_anonymous_access_only_temporary
(resource, reservation, request)[source]¶ Raises exceptions if the current user is anonymous and no longer should be given access to the reservation models.
This could probably be done using morepath’s security system, but it would not be quite as straight-forward. This approach is, though we have to manually add this function to all reservation views the anonymous user should be able to access when creating a new reservatin, but not anymore after that.
-
onegov.org.views.reservation.
assert_access_only_if_there_are_reservations
(reservations)[source]¶ Raises an exception if no reservations are available.
-
onegov.org.views.reservation.
reserve_allocation
(self, request)[source]¶ Adds a single reservation to the list of reservations bound to the current browser session.
Does not actually reserve anything, just keeps a list of things to reserve later. Though it will still check if the reservation is feasable.
-
onegov.org.views.reservation.
handle_reservation_form
(self, request, form)[source]¶ Asks the user for the form data required to complete one or many reservations on a resource.
-
onegov.org.views.reservation.
blocked_by_zipcode
(request, resource, form, reservations)[source]¶ Returns a dict of reservation ids that are blocked by zipcode, with the value set to the date it will be available.
-
onegov.org.views.resource.
handle_cleanup_allocations
(self, request, form)[source]¶ Removes all unused allocations between the given dates.
The settings view, defining things like the logo or color of the org.
-
onegov.org.views.sitecollection.
get_site_collection
(self, request)[source]¶ Returns a list of internal links to be used by the redactor.
The settings of the logged in user.
-
onegov.org.views.userprofile.
handle_user_profile
(self, request, form)[source]¶ Handles the GET and POST login requests.
-
onegov.org.views.userprofile.
handle_unsubscribe
(self, request)[source]¶ Unsubscribes a user from all regular e-mails.
To be able to use this method, an url has to be created like this:
'{}?token={}'.format(( request.link(org, name='unsubscribe'), request.new_url_safe_token( {'user': 'user@example.org'}, 'unsubscribe' ) ))
Elements¶
Contains small helper classes used as abstraction for various templating macros.
-
class
onegov.org.elements.
Link
(text, url, classes=None, request_method='GET', attributes={}, active=False, model=None, subtitle=None)[source]¶ Represents a link rendered in a template.
-
text
¶ The text of the link
-
url
¶ The fully qualified url of the link
-
classes
¶ Classes included in the link
-
request_method
¶ The link method, defaults to ‘GET’. Also supported is ‘DELETE’, which will lead to the use of XHR
-
attributes
¶ HTML attributes (may override other attributes set by this class). Attributes which are translatable, are transalted before rendering.
-
active
¶ Indicate if this link is active or not (not used for rendering)
-
model
¶ The model that underlies this link (to check if the link is visible)
-
subtitle
¶ Shown as a subtitle below certain links (not automatically rendered)
-
-
class
onegov.org.elements.
DeleteLink
(text, url, confirm, yes_button_text=None, no_button_text=None, extra_information=None, redirect_after=None, request_method='DELETE', classes=('confirm', 'delete-link'), target=None)[source]¶
Initial Content¶
Cronjobs¶
Utils¶
-
onegov.org.utils.
djb2_hash
(text, size)[source]¶ Implementation of the djb2 hash, a simple hash function with a configurable table size.
** Do NOT use for cryptography! **
-
onegov.org.utils.
get_random_color
(seed, lightness, saturation)[source]¶ Gets a random color using the given seed (a text value).
Since the colorspace is very limited there are lots of collisions.
-
onegov.org.utils.
get_user_color
[source]¶ Gets a user color for each username which is used for the user-initials-* elements. Each username is mapped to a color.
- Returns
The user color in an css rgb string.
-
onegov.org.utils.
get_extension_color
[source]¶ Gets an extension color for each file extension. This is similar to
get_user_color()
, but returns a darker color (text is white).
-
onegov.org.utils.
add_class_to_node
(node, classname)[source]¶ Adds the given classname to the given lxml node’s class list.
-
onegov.org.utils.
annotate_html
(html, request=None)[source]¶ Takes the given html and annotates the following elements for some advanced styling:
Every paragraph containing an img element will be marked with the has-img class.
If a link is found which points to a youtube or a vimeo video, the link itself as well as the surrounding paragraph is marked with the has-video class
If a hashtag is found, the paragraph gets the ‘has-hashtag’ class.
-
onegov.org.utils.
parse_fullcalendar_request
(request, timezone)[source]¶ Parses start and end from the given fullcalendar request. It is expected that no timezone is passed (the default).
See http://fullcalendar.io/docs/timezone/timezone/
- Returns
A tuple of timezone-aware datetime objects or (None, None).
-
onegov.org.utils.
show_libres_error
(e, request)[source]¶ Shows a human readable error message for the given libres exception, using request.alert.
-
onegov.org.utils.
predict_next_daterange
(dateranges, min_probability=0.8)[source]¶ Takes a list of dateranges (start, end) and tries to predict the next daterange in the list.
See
predict_next_value()
for more information.
-
onegov.org.utils.
predict_next_value
(values, min_probability=0.8, compute_delta=<function <lambda>>, add_delta=<function <lambda>>)[source]¶ Takes a list of values and tries to predict the next value in the series.
Meant to work on a small set of ranges (with first predictions appearing with only three values), this algorithm will look at all possible deltas between the values and keep track of the probability of delta y following delta x.
If the delta between the second last and last value has a high probability of being followed by some delta p, then delta p is used to predict the next range.
If the probability is too low (signified by min_probability), then None is returned.
For large ranges better statistical models should be used. Here we are concerned with small series of data to answer the question “if a user selected three values, what will his fourth be?”
If we for example know that the user selected 1, 2 and 3, then 4 is the next probable value in the series.
-
onegov.org.utils.
group_by_column
(request, query, group_column, sort_column, default_group=None, transform=None)[source]¶ Groups the given query by the given group.
- Parameters
request – The current request used for translation and to exclude invisible records.
query – The query that should be grouped
group_column – The column by which the grouping should happen.
sort_column – The column by which the records should be sorted.
default_group – The group in use if the found group is empty (optional).
transform – Called with each record to transform the result (optional).
Mail¶
Translations¶
Contains a list of manual translations. Those are usually messages that exist in external packages which provide no translations.
Upgrade¶
Contains upgrade tasks that are executed when the application is being
upgraded on the server. See onegov.core.upgrade.upgrade_task
.