将odk样式xlsforms转换为django模型和html模板以用于wq的工具(https://wq.io/)
xlsconv的Python项目详细描述
xlsform转换器将通过XLSForm standard定义的测量转换为Django models并 HTML5 Mustache templates。这使得 可以重用 Open Data Kit ecosystem,而 利用Django对关系数据库的强大支持,如 PostgreSQL。
XLSForm转换器旨在促进 通过wq framework支持脱机的数据收集应用程序。最终目标是提供 与ODK (and Enketo, etc.)提供的表单创作工具的兼容性。注意,这不是 与完全xform兼容相同:客户机和服务器组件 WQ(wq.app和 wq.db)使用基于json的REST API来交换数据,而不是 直接与它们的odk类似物(odk collect和odk)兼容 分别为聚合)。
对于数据库本身,与其他xlsform工具的主要区别在于 (包括一些由django供电的)是xlsform转换器 xlsform字段直接进入django模型定义,而不是 表示django中的整个xform标准。这意味着 xlsform“survey”选项卡中的每一行都映射到(通常)单个 简单关系数据库表中的列。重复的问题是 通过创建第二个模型来处理,该模型对父模型使用ForeignKey。 调查模型。
xlsform转换器还支持两个额外的“约束” 不属于XLSForm标准的部分:
- wq:ForeignKey('app.ModelName'):创建 现有的Django模型(大概没有在电子表格中定义)。 这实际上是 select_one_external。
- wq:initial(3):与repeat_count非常相似,但仅为 新记录。
包含的模板
xlsform转换器使用以下模板生成django/wq 来自给定xlsform的项目文件。
django应用程序模板
- `models.py<;https://github.com/wq/xlsform-converter/blob/master/xlsconv/templates/models.py-tpl>;`\uu
- `rest.py<;https://github.com/wq/xlsform-converter/blob/master/xlsconv/templates/rest.py-tpl>;。`_ (用于`wq.db.rest<;https://wq.io/docs/about-rest>;``uu)
- `admin.py<;https://github.com/wq/xlsform-converter/blob/master/xlsconv/templates/admin.py-tpl>;。`_ (用于 `django.contrib.admin<;https://docs.djangoproject.com/en/1.10/ref/contrib/admin/>;``uu)
- `serializers.py<;https://github.com/wq/xlsform-converter/blob/master/xlsconv/templates/serializers.py-tpl>;。`_ (用于wq.db.rest)
胡子模板(用于wq)
- `edit.html<;https://github.com/wq/xlsform-converter/blob/master/xlsconv/templates/edit.html>;`\uu
- `detail.html<;https://github.com/wq/xlsform-converter/blob/master/xlsconv/templates/detail.html>;`\uu
- `list.html<;https://github.com/wq/xlsform-converter/blob/master/xlsconv/templates/list.html>;`\uu
- `popup.html<;https://github.com/wq/xlsform-converter/blob/master/xlsconv/templates/popup.html>;。`_ (用于wq/map.js)
用法
如果你使用wq,你可能对 wq.start,它使用 xlsconv内部用于wq addform和wq maketemplates 命令。否则,可以直接使用xlsconv 命令行api:
# Recommended: create virtual environment # python3 -m venv venv # . venv/bin/activate # Install xlsconv pip install xlsconv # Use the default models.py template xls2django my-odk-survey.xls > myapp/models.py # Use the rest.py template (or admin.py, or serializers.py) xls2django my-odk-survey.xls rest > myapp/models.py # Use a custom template xls2django my-odk-survey.xls my_templates/models.py > myapp/models.py # Use the default edit.html template xls2html my-odk-survey.xls > templates/survey_edit.html # Use the list.html template (or detail.html, or popup.html) xls2html my-odk-survey.xls list > templates/survey_list.html # Use a custom template xls2html my-odk-survey.xls my_templates/edit.html > templates/survey_edit.html