Elections
The Elections component can be embedded in participatory spaces. To enable it, ensure it is included in your Gemfile by adding or uncommenting the following line:
gem "decidim-elections", DECIDIM_VERSION
The Elections component provides a way to organize voting based on a census. Depending on the type of census, users may be required to register before voting. Since the method for verifying a person against a census can vary, censuses are implemented using a manifest. Any Decidim application or plugin can implement its own type of census just by defining the corresponding manifest.
Registering a Census Manifest
Census types use the same manifests-registry pattern used in other places around Decidim. Here is how to register them:
Decidim::Elections.census_registry.register(:my_census_type) do |manifest|
# Define your census manifest here
# Example:
manifest.admin_form = "Decidim::MyCensuses::MyCensusForm"
manifest.admin_form_partial = "decidim/my_censuses/my_census_form"
# Add additional configuration as needed
end
Note that census types need to be registered from an initializer. If you are adding a census type from a module, use this in the engine.rb file of your module:
module Decidim::MyModule::Engine < ::Rails::Engine
# ...
initializer "decidim_my_module.election_census" do
Decidim::Elections.census_registry.register(:my_census_type) do |manifest|
# ...
end
end
# ...
end
Options for the census manifest
The manifest is defined in the class Decidim::Elections::CensusManifest, possible attributes are:
| Attribute | Type | Description |
|---|---|---|
admin_form |
String |
Name of the form class used in the admin interface for configuring the census. Optional.
If not defined, the admin interface will not show any additional form for configuring the census.
Note that, if you need to save different settings as a result of this form, the class needs to implement the method |
admin_form_partial |
String |
Path to the partial rendered for the form in the admin interface. Required if admin_form is set. |
after_update_command |
String |
Command called after the census is updated in the admin interface. Receives the form and the election. Optional.
If not defined, there will be no post-processing after saving the census.
Note that you can use this command to upload a fixed list of voters in the generic model |
user_presenter |
String |
Name of the presenter class for users in the census. Defaults to |
user_query |
Proc |
Block returning an |
user_validator |
Proc |
Block for custom user validation. Receives the election and user data. This is used to check if a user is in a census, must return a "truthy" value if ok.
Note that, if the |
census_ready_validator |
Proc |
Block for custom census readiness validation. Receives the election. Must return a "truthy" value if the census is ready (for instance a census might require you to upload a file in order to be ready).
Note that, if the |
census_counter |
Proc |
Block for custom census user counting. Receives the election. Must return an integer of the number of users in the census. This does not mean necessarily that only that amount of users will be able to vote.
Dynamic censuses can grow/shrink while the election.
Note that, if the |
user_iterator |
Proc |
Block for custom user iteration. Receives the election and offset. This is currently used only to show a preview of the census in the admin (so the offset is always zero, this might change in the future). If not defined and there is a |