Export participants to different formats

* CSV
* PDF (requires Python dependency `weasyprint`)
* ODS (requires Python dependency `pyexcel_ods3`)

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2021-10-04 18:59:41 +02:00
parent 5dd24e1c9e
commit 0c667b13ae
121 changed files with 10817 additions and 6872 deletions

View File

@@ -796,7 +796,7 @@ defmodule Mobilizon.Events do
end
end
@spec get_participant_by_confirmation_token(String.t()) :: Participant.t()
@spec get_participant_by_confirmation_token(String.t()) :: Participant.t() | nil
def get_participant_by_confirmation_token(confirmation_token) do
Participant
|> where([p], fragment("? ->>'confirmation_token' = ?", p.metadata, ^confirmation_token))
@@ -857,9 +857,8 @@ defmodule Mobilizon.Events do
limit \\ nil
) do
id
|> list_participants_for_event_query()
|> filter_role(roles)
|> order_by(asc: :role)
|> participants_for_event_query(roles)
|> preload([:actor, :event])
|> Page.build_page(page, limit)
end
@@ -1604,11 +1603,8 @@ defmodule Mobilizon.Events do
@spec list_participants_for_event_query(String.t()) :: Ecto.Query.t()
defp list_participants_for_event_query(event_id) do
from(
p in Participant,
where: p.event_id == ^event_id,
preload: [:actor, :event]
)
Participant
|> where([p], p.event_id == ^event_id)
end
@spec list_participant_actors_for_event_query(String.t()) :: Ecto.Query.t()
@@ -1621,6 +1617,21 @@ defmodule Mobilizon.Events do
)
end
@spec participants_for_event_query(String.t(), list(atom())) :: Ecto.Query.t()
def participants_for_event_query(id, roles \\ []) do
id
|> list_participants_for_event_query()
|> filter_role(roles)
|> order_by(asc: :role)
end
def participant_for_event_export_query(id, roles) do
id
|> participants_for_event_query(roles)
|> join(:inner, [p], a in Actor, on: p.actor_id == a.id)
|> select([p, a], {p, a})
end
@doc """
List emails for local users (including anonymous ones) participating to an event