Add reusable people list import and export
This commit is contained in:
@@ -18,6 +18,11 @@ from mka.application.meeting_service import (
|
||||
ProcessingOptions,
|
||||
stable_id,
|
||||
)
|
||||
from mka.application.people_yaml import (
|
||||
PeopleYamlError,
|
||||
export_people_yaml,
|
||||
import_people_yaml,
|
||||
)
|
||||
from mka.integrations.meeting_lab import (
|
||||
MeetingLabGateway,
|
||||
MeetingLabUnavailableError,
|
||||
@@ -48,9 +53,41 @@ def _initialize_state() -> None:
|
||||
st.session_state.setdefault("edited_protocol", "")
|
||||
|
||||
|
||||
def _people_to_rows(people: list[ParticipantInput]) -> list[dict[str, str]]:
|
||||
"""Create fresh widget rows while preserving reusable person IDs."""
|
||||
return [
|
||||
{
|
||||
"row_id": uuid4().hex,
|
||||
"participant_id": person.participant_id,
|
||||
"display_name": person.display_name,
|
||||
"role": person.role,
|
||||
"organization": person.organization,
|
||||
"attendance_status": person.attendance_status,
|
||||
}
|
||||
for person in people
|
||||
]
|
||||
|
||||
|
||||
def _render_participants() -> list[ParticipantInput]:
|
||||
st.subheader("People")
|
||||
st.caption("Record whether each relevant person attended or was only mentioned.")
|
||||
imported_file = st.file_uploader(
|
||||
"Import people",
|
||||
type=["yaml", "yml"],
|
||||
help="Replace the current People list from a versioned YAML export.",
|
||||
)
|
||||
if st.button("Import people list", disabled=imported_file is None):
|
||||
try:
|
||||
imported_people = import_people_yaml(imported_file.getvalue())
|
||||
except PeopleYamlError as exc:
|
||||
st.error(str(exc))
|
||||
else:
|
||||
st.session_state.participants = _people_to_rows(imported_people)
|
||||
st.session_state.people_import_message = f"Imported {len(imported_people)} people."
|
||||
st.rerun()
|
||||
if message := st.session_state.pop("people_import_message", None):
|
||||
st.success(message)
|
||||
|
||||
rows = st.session_state.participants
|
||||
remove_index: int | None = None
|
||||
for index, row in enumerate(rows):
|
||||
@@ -84,10 +121,11 @@ def _render_participants() -> list[ParticipantInput]:
|
||||
if remove_index is not None:
|
||||
rows.pop(remove_index)
|
||||
st.rerun()
|
||||
if st.button("Add person"):
|
||||
action_columns = st.columns(2)
|
||||
if action_columns[0].button("Add person"):
|
||||
rows.append(_new_participant())
|
||||
st.rerun()
|
||||
return [
|
||||
people = [
|
||||
ParticipantInput(
|
||||
participant_id=row["participant_id"],
|
||||
display_name=row["display_name"],
|
||||
@@ -97,6 +135,14 @@ def _render_participants() -> list[ParticipantInput]:
|
||||
)
|
||||
for row in rows
|
||||
]
|
||||
exported_yaml = export_people_yaml(people).encode("utf-8")
|
||||
action_columns[1].download_button(
|
||||
"Export people",
|
||||
data=exported_yaml,
|
||||
file_name="people.yaml",
|
||||
mime="application/yaml",
|
||||
)
|
||||
return people
|
||||
|
||||
|
||||
def _progress_callback(
|
||||
|
||||
Reference in New Issue
Block a user