本文整理汇总了Python中corehq.apps.app_manager.xpath.XPath.string方法的典型用法代码示例。如果您正苦于以下问题:Python XPath.string方法的具体用法?Python XPath.string怎么用?Python XPath.string使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corehq.apps.app_manager.xpath.XPath
的用法示例。
在下文中一共展示了XPath.string方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _add_action_to_detail
# 需要导入模块: from corehq.apps.app_manager.xpath import XPath [as 别名]
# 或者: from corehq.apps.app_manager.xpath.XPath import string [as 别名]
def _add_action_to_detail(self, detail, module):
# add form action to detail
form = self.app.get_form(module.case_list_form.form_id)
if self.app.enable_localized_menu_media:
case_list_form = module.case_list_form
detail.action = LocalizedAction(
menu_locale_id=id_strings.case_list_form_locale(module),
media_image=bool(len(case_list_form.all_image_paths())),
media_audio=bool(len(case_list_form.all_audio_paths())),
image_locale_id=id_strings.case_list_form_icon_locale(module),
audio_locale_id=id_strings.case_list_form_audio_locale(module),
stack=Stack(),
for_action_menu=True,
)
else:
detail.action = Action(
display=Display(
text=Text(locale_id=id_strings.case_list_form_locale(module)),
media_image=module.case_list_form.default_media_image,
media_audio=module.case_list_form.default_media_audio,
),
stack=Stack()
)
frame = PushFrame()
frame.add_command(XPath.string(id_strings.form_command(form)))
target_form_dm = self.entries_helper.get_datums_meta_for_form_generic(form)
source_form_dm = self.entries_helper.get_datums_meta_for_form_generic(module.get_form(0))
for target_meta in target_form_dm:
if target_meta.requires_selection:
# This is true for registration forms where the case being created is a subcase
try:
[source_dm] = [
source_meta for source_meta in source_form_dm
if source_meta.case_type == target_meta.case_type
]
except ValueError:
message = _(
"The '{form}' form selected as the case list registration form "
"for the '{module}' module requires a '{case_type}' case. "
"The '{module}' must load a case of this type.").format(
form=form.default_name(),
module=module.default_name(),
case_type=target_meta.case_type
)
raise SuiteValidationError(message)
else:
frame.add_datum(StackDatum(
id=target_meta.datum.id,
value=session_var(source_dm.datum.id))
)
else:
s_datum = target_meta.datum
frame.add_datum(StackDatum(id=s_datum.id, value=s_datum.function))
frame.add_datum(StackDatum(id=RETURN_TO, value=XPath.string(id_strings.menu_id(module))))
detail.action.stack.add_frame(frame)
示例2: test_complex
# 需要导入模块: from corehq.apps.app_manager.xpath import XPath [as 别名]
# 或者: from corehq.apps.app_manager.xpath.XPath import string [as 别名]
def test_complex(self):
xp = XPath.and_(
XPath('a').eq('1'),
XPath('b').neq(XPath.string('')),
XPath.or_(
XPath('c').eq(XPath.string('')),
XPath.date('d').neq('today()')
))
self.assertEqual("a = 1 and b != '' and (c = '' or date(d) != today())", xp)
示例3: _get_reg_form_action
# 需要导入模块: from corehq.apps.app_manager.xpath import XPath [as 别名]
# 或者: from corehq.apps.app_manager.xpath.XPath import string [as 别名]
def _get_reg_form_action(self, module):
"""
Returns registration form action
"""
form = self.app.get_form(module.case_list_form.form_id)
if self.app.enable_localized_menu_media:
case_list_form = module.case_list_form
action = LocalizedAction(
menu_locale_id=id_strings.case_list_form_locale(module),
media_image=bool(len(case_list_form.all_image_paths())),
media_audio=bool(len(case_list_form.all_audio_paths())),
image_locale_id=id_strings.case_list_form_icon_locale(module),
audio_locale_id=id_strings.case_list_form_audio_locale(module),
stack=Stack(),
for_action_menu=True,
)
else:
action = Action(
display=Display(
text=Text(locale_id=id_strings.case_list_form_locale(module)),
media_image=module.case_list_form.default_media_image,
media_audio=module.case_list_form.default_media_audio,
),
stack=Stack()
)
frame = PushFrame()
frame.add_command(XPath.string(id_strings.form_command(form)))
target_form_dm = self.entries_helper.get_datums_meta_for_form_generic(form)
source_form_dm = []
if len(module.forms):
source_form_dm = self.entries_helper.get_datums_meta_for_form_generic(module.get_form(0))
for target_meta in target_form_dm:
if target_meta.requires_selection:
# This is true for registration forms where the case being created is a subcase
try:
[source_dm] = [
source_meta for source_meta in source_form_dm
if source_meta.case_type == target_meta.case_type
]
except ValueError:
pass
else:
frame.add_datum(StackDatum(
id=target_meta.datum.id,
value=session_var(source_dm.datum.id))
)
else:
s_datum = target_meta.datum
frame.add_datum(StackDatum(id=s_datum.id, value=s_datum.function))
frame.add_datum(StackDatum(id=RETURN_TO, value=XPath.string(id_strings.menu_id(module))))
action.stack.add_frame(frame)
return action
示例4: owner_name
# 需要导入模块: from corehq.apps.app_manager.xpath import XPath [as 别名]
# 或者: from corehq.apps.app_manager.xpath.XPath import string [as 别名]
def owner_name(owner_id):
groups = XPath(u"instance('groups')/groups/group")
group = groups.select("@id", owner_id)
return XPath.if_(
group.count().neq(0),
group.slash("name"),
XPath.if_(CommCareSession.userid.eq(owner_id), CommCareSession.username, XPath.string("")),
)
示例5: get_if_clause
# 需要导入模块: from corehq.apps.app_manager.xpath import XPath [as 别名]
# 或者: from corehq.apps.app_manager.xpath.XPath import string [as 别名]
def get_if_clause(case_count_xpath, target_command):
return_to = session_var(RETURN_TO)
args = [
return_to.count().eq(1),
return_to.eq(XPath.string(target_command)),
]
if case_count_xpath:
args.append(case_count_xpath)
return XPath.and_(*args)
示例6: _add_case_search_action_to_detail
# 需要导入模块: from corehq.apps.app_manager.xpath import XPath [as 别名]
# 或者: from corehq.apps.app_manager.xpath.XPath import string [as 别名]
def _add_case_search_action_to_detail(detail, module):
detail.action = Action(
display=Display(
text=Text(locale_id=id_strings.case_search_locale(module))
),
stack=Stack()
)
frame = PushFrame()
frame.add_command(XPath.string(id_strings.search_command(module)))
detail.action.stack.add_frame(frame)
示例7: owner_name
# 需要导入模块: from corehq.apps.app_manager.xpath import XPath [as 别名]
# 或者: from corehq.apps.app_manager.xpath.XPath import string [as 别名]
def owner_name(owner_id):
groups = XPath(u"instance('groups')/groups/group")
group = groups.select('@id', owner_id)
return XPath.if_(
group.count().not_equals(0),
group.slash('name'),
XPath.if_(
CommCareSession.userid.equals(owner_id),
CommCareSession.username,
XPath.string('')
)
)
示例8: to_frame
# 需要导入模块: from corehq.apps.app_manager.xpath import XPath [as 别名]
# 或者: from corehq.apps.app_manager.xpath.XPath import string [as 别名]
def to_frame(self):
if not self.children and not self.allow_empty_frame:
return
frame = CreateFrame(if_clause=self.if_clause)
for child in self.children:
if isinstance(child, CommandId):
frame.add_command(XPath.string(child.id))
elif isinstance(child, StackDatum):
frame.add_datum(child)
else:
raise Exception("Unexpected child type: {} ({})".format(type(child), child))
return frame
示例9: _get_case_search_action
# 需要导入模块: from corehq.apps.app_manager.xpath import XPath [as 别名]
# 或者: from corehq.apps.app_manager.xpath.XPath import string [as 别名]
def _get_case_search_action(module):
relevant_kwarg = {}
if module.search_config.search_button_display_condition:
relevant_kwarg = dict(
relevant=XPath(module.search_config.search_button_display_condition),
)
action = Action(
display=Display(
text=Text(locale_id=id_strings.case_search_locale(module))
),
stack=Stack(),
**relevant_kwarg
)
frame = PushFrame()
frame.add_mark()
frame.add_command(XPath.string(id_strings.search_command(module)))
action.stack.add_frame(frame)
return action
示例10: configure_entry_careplan_form
# 需要导入模块: from corehq.apps.app_manager.xpath import XPath [as 别名]
# 或者: from corehq.apps.app_manager.xpath.XPath import string [as 别名]
def configure_entry_careplan_form(self, module, e, form=None, **kwargs):
parent_module = self.app.get_module_by_unique_id(module.parent_select.module_id)
e.datums.append(
SessionDatum(
id="case_id",
nodeset=EntriesHelper.get_nodeset_xpath(parent_module.case_type),
value="./@case_id",
detail_select=self.details_helper.get_detail_id_safe(parent_module, "case_short"),
detail_confirm=self.details_helper.get_detail_id_safe(parent_module, "case_long"),
)
)
def session_datum(datum_id, case_type, parent_ref, parent_val):
nodeset = (
CaseTypeXpath(case_type)
.case()
.select("index/%s" % parent_ref, session_var(parent_val), quote=False)
.select("@status", "open")
)
return SessionDatum(
id=datum_id,
nodeset=nodeset,
value="./@case_id",
detail_select=self.details_helper.get_detail_id_safe(module, "%s_short" % case_type),
detail_confirm=self.details_helper.get_detail_id_safe(module, "%s_long" % case_type),
)
e.stack = Stack()
frame = CreateFrame()
e.stack.add_frame(frame)
if form.case_type == CAREPLAN_GOAL:
if form.mode == "create":
new_goal_id_var = "case_id_goal_new"
e.datums.append(SessionDatum(id=new_goal_id_var, function="uuid()"))
elif form.mode == "update":
new_goal_id_var = "case_id_goal"
e.datums.append(session_datum(new_goal_id_var, CAREPLAN_GOAL, "parent", "case_id"))
if not module.display_separately:
open_goal = CaseIDXPath(session_var(new_goal_id_var)).case().select("@status", "open")
frame.if_clause = "{count} = 1".format(count=open_goal.count())
frame.add_command(XPath.string(id_strings.menu_id(parent_module)))
frame.add_datum(StackDatum(id="case_id", value=session_var("case_id")))
frame.add_command(XPath.string(id_strings.menu_id(module)))
frame.add_datum(StackDatum(id="case_id_goal", value=session_var(new_goal_id_var)))
else:
frame.add_command(XPath.string(id_strings.menu_id(module)))
frame.add_datum(StackDatum(id="case_id", value=session_var("case_id")))
elif form.case_type == CAREPLAN_TASK:
if not module.display_separately:
frame.add_command(XPath.string(id_strings.menu_id(parent_module)))
frame.add_datum(StackDatum(id="case_id", value=session_var("case_id")))
frame.add_command(XPath.string(id_strings.menu_id(module)))
frame.add_datum(StackDatum(id="case_id_goal", value=session_var("case_id_goal")))
if form.mode == "update":
count = (
CaseTypeXpath(CAREPLAN_TASK)
.case()
.select("index/goal", session_var("case_id_goal"), quote=False)
.select("@status", "open")
.count()
)
frame.if_clause = "{count} >= 1".format(count=count)
frame.add_command(
XPath.string(id_strings.form_command(module.get_form_by_type(CAREPLAN_TASK, "update")))
)
else:
frame.add_command(XPath.string(id_strings.menu_id(module)))
frame.add_datum(StackDatum(id="case_id", value=session_var("case_id")))
if form.mode == "create":
e.datums.append(session_datum("case_id_goal", CAREPLAN_GOAL, "parent", "case_id"))
elif form.mode == "update":
e.datums.append(session_datum("case_id_goal", CAREPLAN_GOAL, "parent", "case_id"))
e.datums.append(session_datum("case_id_task", CAREPLAN_TASK, "goal", "case_id_goal"))
示例11: configure_entry_careplan_form
# 需要导入模块: from corehq.apps.app_manager.xpath import XPath [as 别名]
# 或者: from corehq.apps.app_manager.xpath.XPath import string [as 别名]
def configure_entry_careplan_form(self, module, e, form=None, **kwargs):
parent_module = self.app.get_module_by_unique_id(module.parent_select.module_id)
e.datums.append(SessionDatum(
id='case_id',
nodeset=EntriesHelper.get_nodeset_xpath(parent_module.case_type),
value="./@case_id",
detail_select=self.details_helper.get_detail_id_safe(parent_module, 'case_short'),
detail_confirm=self.details_helper.get_detail_id_safe(parent_module, 'case_long')
))
def session_datum(datum_id, case_type, parent_ref, parent_val):
nodeset = CaseTypeXpath(case_type).case().select(
'index/%s' % parent_ref, session_var(parent_val), quote=False
).select('@status', 'open')
return SessionDatum(
id=datum_id,
nodeset=nodeset,
value="./@case_id",
detail_select=self.details_helper.get_detail_id_safe(module, '%s_short' % case_type),
detail_confirm=self.details_helper.get_detail_id_safe(module, '%s_long' % case_type)
)
e.stack = Stack()
frame = CreateFrame()
e.stack.add_frame(frame)
if form.case_type == CAREPLAN_GOAL:
if form.mode == 'create':
new_goal_id_var = 'case_id_goal_new'
e.datums.append(SessionDatum(id=new_goal_id_var, function='uuid()'))
elif form.mode == 'update':
new_goal_id_var = 'case_id_goal'
e.datums.append(session_datum(new_goal_id_var, CAREPLAN_GOAL, 'parent', 'case_id'))
if not module.display_separately:
open_goal = CaseIDXPath(session_var(new_goal_id_var)).case().select('@status', 'open')
frame.if_clause = '{count} = 1'.format(count=open_goal.count())
frame.add_command(XPath.string(id_strings.menu_id(parent_module)))
frame.add_datum(StackDatum(id='case_id', value=session_var('case_id')))
frame.add_command(XPath.string(id_strings.menu_id(module)))
frame.add_datum(StackDatum(id='case_id_goal', value=session_var(new_goal_id_var)))
else:
frame.add_command(XPath.string(id_strings.menu_id(module)))
frame.add_datum(StackDatum(id='case_id', value=session_var('case_id')))
elif form.case_type == CAREPLAN_TASK:
if not module.display_separately:
frame.add_command(XPath.string(id_strings.menu_id(parent_module)))
frame.add_datum(StackDatum(id='case_id', value=session_var('case_id')))
frame.add_command(XPath.string(id_strings.menu_id(module)))
frame.add_datum(StackDatum(id='case_id_goal', value=session_var('case_id_goal')))
if form.mode == 'update':
count = CaseTypeXpath(CAREPLAN_TASK).case().select(
'index/goal', session_var('case_id_goal'), quote=False
).select('@status', 'open').count()
frame.if_clause = '{count} >= 1'.format(count=count)
frame.add_command(XPath.string(
id_strings.form_command(module.get_form_by_type(CAREPLAN_TASK, 'update'))
))
else:
frame.add_command(XPath.string(id_strings.menu_id(module)))
frame.add_datum(StackDatum(id='case_id', value=session_var('case_id')))
if form.mode == 'create':
e.datums.append(session_datum('case_id_goal', CAREPLAN_GOAL, 'parent', 'case_id'))
elif form.mode == 'update':
e.datums.append(session_datum('case_id_goal', CAREPLAN_GOAL, 'parent', 'case_id'))
e.datums.append(session_datum('case_id_task', CAREPLAN_TASK, 'goal', 'case_id_goal'))
示例12: get_module_contributions
# 需要导入模块: from corehq.apps.app_manager.xpath import XPath [as 别名]
# 或者: from corehq.apps.app_manager.xpath.XPath import string [as 别名]
def get_module_contributions(self, module):
if module_offers_search(module):
domain = self.app.domain
details_helper = DetailsHelper(self.app)
sync_request = SyncRequest(
post=SyncRequestPost(
url=absolute_reverse('claim_case', args=[domain]),
# Check whether the case to be claimed already exists in casedb:
# count(
# instance('casedb')/casedb/case[@case_id=instance('querysession')/session/data/case_id]
# ) = 0
relevant=XPath.count(
CaseIDXPath(QuerySessionXPath('case_id').instance()).case()
) + ' = 0',
data=[
QueryData(
key='case_id',
ref=QuerySessionXPath('case_id').instance(),
# e.g. instance('querysession')/session/data/case_id
),
]
),
command=Command(
id=id_strings.search_command(module),
display=Display(
text=Text(locale_id=id_strings.case_search_locale(module)),
),
),
instances=[Instance(
id=SESSION_INSTANCE,
src='jr://instance/session'
)],
session=SyncRequestSession(
queries=[
SyncRequestQuery(
url=absolute_reverse('sync_search', args=[domain]),
storage_instance=RESULTS_INSTANCE,
data=[
QueryData(
key='case_type',
ref="'{}'".format(module.case_type)
),
],
prompts=[
QueryPrompt(
key=p.name,
display=Display(
text=Text(locale_id=id_strings.search_property_locale(module, p.name)),
),
) for p in module.search_config.properties
]
)
],
data=[SessionDatum(
id='case_id',
nodeset=(CaseTypeXpath(module.case_type)
.case(instance_name=RESULTS_INSTANCE)
.select(u'@status', u'open', quote=True)),
value='./@case_id',
detail_select=details_helper.get_detail_id_safe(module, 'case_short'),
detail_confirm=details_helper.get_detail_id_safe(module, 'case_long'),
)],
),
stack=Stack(),
)
frame = PushFrame()
# Open first form in module
frame.add_command(XPath.string(id_strings.menu_id(module)))
frame.add_datum(StackDatum(id=CALCULATED_DATA, value=XPath.string(MARK_AS_CLAIMED)))
sync_request.stack.add_frame(frame)
return [sync_request]
return []