feat(export): add date of participant creation in participant exports
Closes #1343 Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
8617382af2
commit
fef60ed0f9
@ -3,6 +3,8 @@ defmodule Mobilizon.Service.DateTime do
|
|||||||
Module to represent a datetime in a given locale
|
Module to represent a datetime in a given locale
|
||||||
"""
|
"""
|
||||||
alias Cldr.DateTime.Relative
|
alias Cldr.DateTime.Relative
|
||||||
|
alias Mobilizon.Cldr, as: MobilizonCldr
|
||||||
|
import Mobilizon.Cldr, only: [locale_or_default: 1]
|
||||||
|
|
||||||
@typep to_string_format :: :short | :medium | :long | :full
|
@typep to_string_format :: :short | :medium | :long | :full
|
||||||
|
|
||||||
@ -10,25 +12,25 @@ defmodule Mobilizon.Service.DateTime do
|
|||||||
|
|
||||||
@spec datetime_to_string(DateTime.t(), String.t(), to_string_format()) :: String.t()
|
@spec datetime_to_string(DateTime.t(), String.t(), to_string_format()) :: String.t()
|
||||||
def datetime_to_string(%DateTime{} = datetime, locale \\ "en", format \\ :medium) do
|
def datetime_to_string(%DateTime{} = datetime, locale \\ "en", format \\ :medium) do
|
||||||
Mobilizon.Cldr.DateTime.to_string!(datetime,
|
MobilizonCldr.DateTime.to_string!(datetime,
|
||||||
format: format,
|
format: format,
|
||||||
locale: Mobilizon.Cldr.locale_or_default(locale)
|
locale: locale_or_default(locale)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec datetime_to_time_string(DateTime.t(), String.t(), to_string_format()) :: String.t()
|
@spec datetime_to_time_string(DateTime.t(), String.t(), to_string_format()) :: String.t()
|
||||||
def datetime_to_time_string(%DateTime{} = datetime, locale \\ "en", format \\ :short) do
|
def datetime_to_time_string(%DateTime{} = datetime, locale \\ "en", format \\ :short) do
|
||||||
Mobilizon.Cldr.Time.to_string!(datetime,
|
MobilizonCldr.Time.to_string!(datetime,
|
||||||
format: format,
|
format: format,
|
||||||
locale: Mobilizon.Cldr.locale_or_default(locale)
|
locale: locale_or_default(locale)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec datetime_to_date_string(DateTime.t(), String.t(), to_string_format()) :: String.t()
|
@spec datetime_to_date_string(DateTime.t(), String.t(), to_string_format()) :: String.t()
|
||||||
def datetime_to_date_string(%DateTime{} = datetime, locale \\ "en", format \\ :short) do
|
def datetime_to_date_string(%DateTime{} = datetime, locale \\ "en", format \\ :short) do
|
||||||
Mobilizon.Cldr.Date.to_string!(datetime,
|
MobilizonCldr.Date.to_string!(datetime,
|
||||||
format: format,
|
format: format,
|
||||||
locale: Mobilizon.Cldr.locale_or_default(locale)
|
locale: locale_or_default(locale)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -47,9 +49,9 @@ defmodule Mobilizon.Service.DateTime do
|
|||||||
|
|
||||||
@spec datetime_relative(DateTime.t(), String.t()) :: String.t()
|
@spec datetime_relative(DateTime.t(), String.t()) :: String.t()
|
||||||
def datetime_relative(%DateTime{} = datetime, locale \\ "en") do
|
def datetime_relative(%DateTime{} = datetime, locale \\ "en") do
|
||||||
Relative.to_string!(datetime, Mobilizon.Cldr,
|
Relative.to_string!(datetime, MobilizonCldr,
|
||||||
relative_to: DateTime.utc_now(),
|
relative_to: DateTime.utc_now(),
|
||||||
locale: Mobilizon.Cldr.locale_or_default(locale)
|
locale: locale_or_default(locale)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ defmodule Mobilizon.Service.Export.Participants.Common do
|
|||||||
alias Mobilizon.Events.Participant.Metadata
|
alias Mobilizon.Events.Participant.Metadata
|
||||||
alias Mobilizon.Storage.Repo
|
alias Mobilizon.Storage.Repo
|
||||||
import Mobilizon.Web.Gettext, only: [gettext: 1]
|
import Mobilizon.Web.Gettext, only: [gettext: 1]
|
||||||
|
import Mobilizon.Service.DateTime, only: [datetime_to_string: 2]
|
||||||
|
|
||||||
@spec save_upload(String.t(), String.t(), String.t(), String.t(), String.t()) ::
|
@spec save_upload(String.t(), String.t(), String.t(), String.t(), String.t()) ::
|
||||||
{:ok, Export.t()} | {:error, atom() | Ecto.Changeset.t()}
|
{:ok, Export.t()} | {:error, atom() | Ecto.Changeset.t()}
|
||||||
@ -58,7 +59,12 @@ defmodule Mobilizon.Service.Export.Participants.Common do
|
|||||||
|
|
||||||
@spec columns :: list(String.t())
|
@spec columns :: list(String.t())
|
||||||
def columns do
|
def columns do
|
||||||
[gettext("Participant name"), gettext("Participant status"), gettext("Participant message")]
|
[
|
||||||
|
gettext("Participant name"),
|
||||||
|
gettext("Participant status"),
|
||||||
|
gettext("Participant registration date"),
|
||||||
|
gettext("Participant message")
|
||||||
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
# One hour
|
# One hour
|
||||||
@ -82,14 +88,26 @@ defmodule Mobilizon.Service.Export.Participants.Common do
|
|||||||
|
|
||||||
@spec to_list({Participant.t(), Actor.t()}) :: list(String.t())
|
@spec to_list({Participant.t(), Actor.t()}) :: list(String.t())
|
||||||
def to_list(
|
def to_list(
|
||||||
{%Participant{role: role, metadata: metadata},
|
{%Participant{role: role, metadata: metadata, inserted_at: inserted_at},
|
||||||
%Actor{domain: nil, preferred_username: "anonymous"}}
|
%Actor{domain: nil, preferred_username: "anonymous"}}
|
||||||
) do
|
) do
|
||||||
[gettext("Anonymous participant"), translate_role(role), convert_metadata(metadata)]
|
[
|
||||||
|
gettext("Anonymous participant"),
|
||||||
|
translate_role(role),
|
||||||
|
datetime_to_string(inserted_at, Gettext.get_locale()),
|
||||||
|
convert_metadata(metadata)
|
||||||
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_list({%Participant{role: role, metadata: metadata}, %Actor{} = actor}) do
|
def to_list(
|
||||||
[Actor.display_name_and_username(actor), translate_role(role), convert_metadata(metadata)]
|
{%Participant{role: role, metadata: metadata, inserted_at: inserted_at}, %Actor{} = actor}
|
||||||
|
) do
|
||||||
|
[
|
||||||
|
Actor.display_name_and_username(actor),
|
||||||
|
translate_role(role),
|
||||||
|
datetime_to_string(inserted_at, Gettext.get_locale()),
|
||||||
|
convert_metadata(metadata)
|
||||||
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec convert_metadata(Metadata.t() | nil) :: String.t()
|
@spec convert_metadata(Metadata.t() | nil) :: String.t()
|
||||||
|
@ -5,24 +5,28 @@ defmodule Mobilizon.Service.Export.Participants.CommonTest do
|
|||||||
|
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Service.Export.Participants.Common
|
alias Mobilizon.Service.Export.Participants.Common
|
||||||
|
import Mobilizon.Service.DateTime, only: [datetime_to_string: 1]
|
||||||
|
|
||||||
test "convert participants to list items" do
|
test "convert participants to list items" do
|
||||||
participant = insert(:participant)
|
participant = insert(:participant)
|
||||||
actor = insert(:actor)
|
actor = insert(:actor)
|
||||||
name = Actor.display_name_and_username(actor)
|
name = Actor.display_name_and_username(actor)
|
||||||
assert [^name, _, ""] = Common.to_list({participant, actor})
|
date = datetime_to_string(participant.inserted_at)
|
||||||
|
assert [^name, _, ^date, ""] = Common.to_list({participant, actor})
|
||||||
end
|
end
|
||||||
|
|
||||||
test "convert participants with metadata to list items" do
|
test "convert participants with metadata to list items" do
|
||||||
participant = insert(:participant, metadata: %{message: "a message"})
|
participant = insert(:participant, metadata: %{message: "a message"})
|
||||||
actor = insert(:actor)
|
actor = insert(:actor)
|
||||||
name = Actor.display_name_and_username(actor)
|
name = Actor.display_name_and_username(actor)
|
||||||
assert [^name, _, "a message"] = Common.to_list({participant, actor})
|
date = datetime_to_string(participant.inserted_at)
|
||||||
|
assert [^name, _, ^date, "a message"] = Common.to_list({participant, actor})
|
||||||
end
|
end
|
||||||
|
|
||||||
test "convert anonymous participants to list items" do
|
test "convert anonymous participants to list items" do
|
||||||
participant = insert(:participant)
|
participant = insert(:participant)
|
||||||
actor = insert(:actor, domain: nil, preferred_username: "anonymous")
|
actor = insert(:actor, domain: nil, preferred_username: "anonymous")
|
||||||
assert ["Anonymous participant", _, ""] = Common.to_list({participant, actor})
|
date = datetime_to_string(participant.inserted_at)
|
||||||
|
assert ["Anonymous participant", _, ^date, ""] = Common.to_list({participant, actor})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user