Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default language in settings tab if not present #336

Merged
merged 7 commits into from
Jan 21, 2025
8 changes: 7 additions & 1 deletion osm_fieldwork/form_components/mandatory_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,13 @@ def get_mandatory_fields(new_geom_type: DbGeomType):
},
{"notes": "Fields essential to FMTM"},
{"type": "start-geopoint", "name": "warmup", "notes": "collects location on form start"},
{"type": "select_one_from_file features.csv", "name": "feature", "label::english(en)": "Geometry", "appearance": "map"},
{
"type": "select_one_from_file features.csv",
"name": "feature",
"label::english(en)": "Geometry",
"label::portuguese(pt-br)": "geometria",
"appearance": "map",
},
{
"type": geom_field,
"name": "new_feature",
Expand Down
22 changes: 12 additions & 10 deletions osm_fieldwork/update_xlsform.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

from osm_fieldwork.form_components.choice_fields import choices_df, digitisation_choices_df
from osm_fieldwork.form_components.digitisation_fields import digitisation_df
from osm_fieldwork.form_components.mandatory_fields import DbGeomType, create_survey_df, entities_df, meta_df, settings_df
from osm_fieldwork.form_components.mandatory_fields import DbGeomType, create_survey_df, entities_df, meta_df

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -116,7 +116,7 @@ def standardize_language_columns(df):
standardized_col = col
for base_col in base_columns:
if col.startswith(f"{base_col}::"):
match = re.match(rf"{base_col}::(\w+)", col)
match = re.match(rf"{base_col}::\s*(\w+)", col)
if match:
lang_name = match.group(1)
if lang_name in DEFAULT_LANGUAGES:
Expand Down Expand Up @@ -154,16 +154,17 @@ def filter_df_empty_rows(df: pd.DataFrame, column: str = NAME_COLUMN):
return xlsform


def create_survey_group(name: str) -> dict[str, pd.DataFrame]:
def create_survey_group() -> dict[str, pd.DataFrame]:
"""Helper function to create a begin and end group for XLSForm."""
begin_group = pd.DataFrame(
{
"type": ["begin group"],
"name": [name],
"label::english(en)": [name],
"label::swahili(sw)": [name],
"label::french(fr)": [name],
"label::spanish(es)": [name],
"name": ["survery_questions"],
"label::english(en)": ["survery_questions"],
"label::swahili(sw)": ["maswali_ya_utafiti"],
"label::french(fr)": ["questions_enquête"],
"label::spanish(es)": ["preguntas_de_encuesta"],
"label::portuguese(pt-br)": ["perguntas_de_pesquisa"],
"relevant": "(${new_feature} != '') or (${building_exists} = 'yes')",
}
)
Expand Down Expand Up @@ -214,7 +215,7 @@ def merge_dataframes(mandatory_df: pd.DataFrame, user_question_df: pd.DataFrame,
]

# Create survey group wrapper
survey_group = create_survey_group(SURVEY_GROUP_NAME)
survey_group = create_survey_group()

# Concatenate dataframes in the desired order
return pd.concat(
Expand Down Expand Up @@ -324,7 +325,6 @@ async def append_mandatory_fields(
# Append or overwrite 'entities' and 'settings' sheets
log.debug("Overwriting entities and settings XLSForm sheets")
custom_sheets["entities"] = entities_df
custom_sheets["settings"] = settings_df
if "entities" not in custom_sheets:
msg = "Entities sheet is required in XLSForm!"
log.error(msg)
Expand All @@ -341,6 +341,8 @@ async def append_mandatory_fields(
custom_sheets["settings"]["version"] = current_datetime
custom_sheets["settings"]["form_id"] = xform_id
custom_sheets["settings"]["form_title"] = form_category
if "default_language" not in custom_sheets["settings"]:
custom_sheets["settings"]["default_language"] = "en"

# Append select_one_from_file for additional entities
if additional_entities:
Expand Down
Loading