Skip to content

Commit

Permalink
add info to debug
Browse files Browse the repository at this point in the history
  • Loading branch information
jmargutt committed Nov 19, 2024
1 parent 4b81c6e commit 3f5edf5
Showing 1 changed file with 25 additions and 34 deletions.
59 changes: 25 additions & 34 deletions routes/routesKobo.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,6 @@ async def kobo_to_linked_kobo(
status_code=200,
content={"detail": "Submission has already been successfully processed"},
)
print("kobo_data")
print(kobo_data)

# get submissions of parent form
target_url = f"https://kobo.ifrc.org/api/v2/assets/{request.headers['parentasset']}/data/?format=json"
Expand All @@ -272,41 +270,38 @@ async def kobo_to_linked_kobo(
# create new choice list based on parent form submissions
new_choices_form, kuids, names = [], [], []
for parent_submission in parent_submissions["results"]:

parent_data = clean_kobo_data(parent_submission)
parent_question = request.headers["parentquestion"].lower()

if parent_question not in parent_data.keys():
continue

name = parent_data[request.headers["parentquestion"].lower()]
if name in names:
continue # avoid duplicate names
names.append(name)

kuid = str(uuid.uuid4())[:10].replace("-", "")
while kuid in kuids:
kuid = str(uuid.uuid4())[:10].replace("-", "") # avoid duplicate kuids
kuids.append(kuid)

new_choices_form.append(
{
"name": name,
"$kuid": kuid,
"label": [name],
"list_name": request.headers["childlist"],
"$autovalue": name,
}
)
for key in parent_submission.keys():
if key.split("/")[-1] == request.headers["parentquestion"]:
name = parent_submission[key]
if name in names:
continue # avoid duplicate names
names.append(name)

kuid = str(uuid.uuid4())[:10].replace("-", "")
while kuid in kuids:
kuid = str(uuid.uuid4())[:10].replace(
"-", ""
) # avoid duplicate kuids
kuids.append(kuid)

new_choices_form.append(
{
"name": name,
"$kuid": kuid,
"label": [name],
"list_name": request.headers["childlist"],
"$autovalue": name,
}
)
print("new_choices_form")
print(new_choices_form)

# get child form
target_url = f"https://kobo.ifrc.org/api/v2/assets/{request.headers['childasset']}/?format=json"
response = requests.get(target_url, headers=koboheaders)
assetdata = json.loads(response.content)
print("get child form")
print(assetdata)
print("child_choices")
print(assetdata["content"]["choices"])

# update child form with new choice list
assetdata["content"]["choices"] = [
Expand All @@ -318,16 +313,12 @@ async def kobo_to_linked_kobo(
logger.info("update child form with new choice list")
logger.info(assetdata)
response = requests.patch(target_url, headers=koboheaders, json=assetdata)
print(response.status_code)
print(response.content)

# get latest form version id
target_url = f"https://kobo.ifrc.org/api/v2/assets/{request.headers['childasset']}/?format=json"
response = requests.get(target_url, headers=koboheaders)
newassetdata = json.loads(response.content)
newversionid = newassetdata["version_id"]
print("get child form")
print(assetdata)

# deploy latest form version id
target_url = f"https://kobo.ifrc.org/api/v2/assets/{request.headers['childasset']}/deployment/"
Expand Down

0 comments on commit 3f5edf5

Please sign in to comment.