本文整理汇总了Python中corehq.apps.app_manager.xform.XForm.get_questions方法的典型用法代码示例。如果您正苦于以下问题:Python XForm.get_questions方法的具体用法?Python XForm.get_questions怎么用?Python XForm.get_questions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corehq.apps.app_manager.xform.XForm
的用法示例。
在下文中一共展示了XForm.get_questions方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_form_data_source
# 需要导入模块: from corehq.apps.app_manager.xform import XForm [as 别名]
# 或者: from corehq.apps.app_manager.xform.XForm import get_questions [as 别名]
def get_form_data_source(app, form):
xform = XForm(form.source)
form_name = form.default_name()
questions = xform.get_questions([])
return DataSourceConfiguration(
domain=app.domain,
referenced_doc_type="XFormInstance",
table_id=_clean_table_name(app.domain, form_name),
display_name=form_name,
configured_filter=make_form_data_source_filter(xform.data_node.tag_xmlns),
configured_indicators=[
make_form_question_indicator(q, column_id=get_column_name(q["value"])) for q in questions
]
+ [make_form_meta_block_indicator(field) for field in FORM_METADATA_PROPERTIES],
)
示例2: get_questions
# 需要导入模块: from corehq.apps.app_manager.xform import XForm [as 别名]
# 或者: from corehq.apps.app_manager.xform.XForm import get_questions [as 别名]
def get_questions(form):
xform = XForm(form.source)
prefix = '/%s/' % xform.data_node.tag_name
def remove_prefix(string):
if string.startswith(prefix):
return string[len(prefix):]
else:
raise Exception()
def transform_question(q):
return {
'id': remove_prefix(q['value']),
'type': q['tag'],
'text': q['label'] if q['tag'] != 'hidden' else ''
}
return [transform_question(q) for q in xform.get_questions(langs)]
示例3: get_questions
# 需要导入模块: from corehq.apps.app_manager.xform import XForm [as 别名]
# 或者: from corehq.apps.app_manager.xform.XForm import get_questions [as 别名]
def get_questions(form):
xform = XForm(form.source)
prefix = "/%s/" % xform.data_node.tag_name
def remove_prefix(string):
if string.startswith(prefix):
return string[len(prefix) :]
else:
raise Exception()
def transform_question(q):
return {
"id": remove_prefix(q["value"]),
"type": q["tag"],
"text": q["label"] if q["tag"] != "hidden" else "",
}
return [transform_question(q) for q in xform.get_questions(langs)]
示例4: DataSourceBuilder
# 需要导入模块: from corehq.apps.app_manager.xform import XForm [as 别名]
# 或者: from corehq.apps.app_manager.xform.XForm import get_questions [as 别名]
#.........这里部分代码省略.........
return ret
@property
@memoized
def data_source_properties(self):
"""
A dictionary containing the various properties that may be used as indicators
or columns in the data source or report.
Keys are strings that uniquely identify properties.
Values are dicts representing the properties, ex:
>> self.data_source_properties
{
"/data/question1": {
"type": "question",
"id": "/data/question1",
"text": "Enter the child's name",
"column_id": "data--question1",
"source": {
'repeat': None,
'group': None,
'value': '/data/question1',
'label': 'question1',
'tag': 'input',
'type': 'Text'
}
},
"meta/deviceID": {
"type": "meta",
"id": "meta/deviceID",
"text": "deviceID",
"column_id": "meta--deviceID",
"source": ("deviceID", "string")
}
}
"id" is used as the value in selects/select2s in the form. Uniquely identifies questions.
"column_id" is used as the column name for this indicator. There are bugs
with slashes which requires this to be different from "id"
"text" will be used as the visible text in selects/select2s
"type" is "question", "case_property", or "meta"
For questions, "source" is the dict returned by Xform.get_questions, for
case properties and form metadata it is simply the name of the property.
"""
if self.source_type == 'case':
return {
cp: {
'type': 'case_property',
'id': cp,
'column_id': get_column_name(cp),
'text': cp,
'source': cp
} for cp in self.case_properties
}
if self.source_type == 'form':
ret = {}
questions = self.source_xform.get_questions([])
ret.update({
q['value']: {
"type": "question",
"id": q['value'],
"column_id": get_column_name(q['value'].strip("/")),
'text': q['label'],
"source": q,
} for q in questions
})
ret.update({
p[0]: {
"type": "meta",
"id": p[0],
"column_id": get_column_name(p[0].strip("/")),
'text': p[0],
"source": p,
} for p in FORM_METADATA_PROPERTIES
})
return ret
@property
@memoized
def data_source_name(self):
if self.source_type == 'form':
return "{} (v{})".format(self.source_form.default_name(), self.app.version)
if self.source_type == 'case':
return "{} (v{})".format(self.source_id, self.app.version)
def get_existing_match(self):
return DataSourceConfiguration.view(
'userreports/data_sources_by_build_info',
key=[
self.domain,
self.source_doc_type,
self.source_id,
self.app._id,
self.app.version
],
reduce=False
).one()
示例5: get_form_data_source
# 需要导入模块: from corehq.apps.app_manager.xform import XForm [as 别名]
# 或者: from corehq.apps.app_manager.xform.XForm import get_questions [as 别名]
def get_form_data_source(app, form):
xform = XForm(form.source)
form_name = form.default_name()
def _get_indicator_data_type(data_type, options):
if data_type == "date":
return {"datatype": "date"}
if data_type == "MSelect":
return {
"type": "choice_list",
"select_style": DATATYPE_MAP[data_type],
"choices": [
option['value'] for option in options
],
}
return {"datatype": "string"}
def _make_indicator(question):
path = question['value'].split('/')
data_type = question['type']
options = question.get('options')
ret = {
"type": "raw",
"column_id": path[-1],
'property_path': ['form'] + path[2:],
"display_name": path[-1],
}
ret.update(_get_indicator_data_type(data_type, options))
return ret
def _make_meta_block_indicator(field_name, data_type):
ret = {
"type": "raw",
"column_id": field_name,
"property_path": ['form', 'meta'] + [field_name],
"display_name": field_name,
}
ret.update(_get_indicator_data_type(data_type, []))
return ret
questions = xform.get_questions([])
return DataSourceConfiguration(
domain=app.domain,
referenced_doc_type='XFormInstance',
table_id=_clean_table_name(app.domain, form_name),
display_name=form_name,
configured_filter={
"type": "property_match",
"property_name": "xmlns",
"property_path": [],
"property_value": xform.data_node.tag_xmlns
},
configured_indicators=[
_make_indicator(q) for q in questions
] + [
_make_meta_block_indicator(field[0], field[1]) for field in [
('username', 'string'),
('userID', 'string'),
('timeStart', 'datetime'),
('timeEnd', 'datetime'),
('deviceID', 'string'),
]
],
)