Skip to content

Instantly share code, notes, and snippets.

@dorey
Last active April 15, 2020 22:18
Show Gist options
  • Save dorey/0146dddf0fd1a2c4c7002a5117f1f88b to your computer and use it in GitHub Desktop.
Save dorey/0146dddf0fd1a2c4c7002a5117f1f88b to your computer and use it in GitHub Desktop.
place in kpi's directory "kpi/scripts" then run
from kpi.models.asset import Asset
import json
ASSET_CONTENT = json.loads('''
{
"survey": [
{
"$autoname": "s1",
"required": false,
"kobo--rank-items": "legacyrankitems",
"label": [
"legacy koborank"
],
"$kuid": "0000m42",
"type": "begin_rank"
},
{
"type": "rank__level",
"name": "rl1",
"label": [
"first choice"
]
},
{
"type": "rank__level",
"name": "rl2",
"label": [
"second choice"
]
},
{
"type": "end_rank"
},
{
"$autoname": "s1",
"required": false,
"rank_from": "ri2bk45",
"label": [
"s1"
],
"$kuid": "rn69m42",
"type": "odkrank"
}
],
"choices": [
{
"$autovalue": "red",
"list_name": "ri2bk45",
"$kuid": "odkr1fAsW",
"value": "red",
"label": [
"Red"
]
},
{
"$autovalue": "yellow",
"list_name": "ri2bk45",
"$kuid": "odkr2f3cX",
"value": "yellow",
"label": [
"Yellow"
]
},
{
"$autovalue": "blue",
"list_name": "ri2bk45",
"$kuid": "odkr3f3cX",
"value": "blue",
"label": [
"Blue"
]
},
{
"$autovalue": "red",
"list_name": "legacyrankitems",
"$kuid": "kr111fAsW",
"value": "red",
"label": [
"Red"
]
},
{
"$autovalue": "yellow",
"list_name": "legacyrankitems",
"$kuid": "kr222f3cX",
"value": "yellow",
"label": [
"Yellow"
]
},
{
"$autovalue": "blue",
"list_name": "legacyrankitems",
"$kuid": "kr333f3cX",
"value": "blue",
"label": [
"Blue"
]
}
],
"settings": {},
"translations": [
null
],
"translated": [
"label"
],
"schema": "1"
}
''')
def run():
# most_recent_asset
asset = Asset.objects.order_by('date_created').last()
asset.content = ASSET_CONTENT
Asset.objects.bulk_update([asset], ['content'])
uid = asset.uid
print('''
Your asset has been updated with the example odkrank form.
http://kf.kobo.local/#/forms/{}/landing
'''.format(uid))
@dorey
Copy link
Author

dorey commented Apr 15, 2020

./run.py -cf run kpi /bin/bash
python manage.py runscript import_odkrank_question

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment