本文整理汇总了Python中corehq.apps.app_manager.xpath.XPath类的典型用法代码示例。如果您正苦于以下问题:Python XPath类的具体用法?Python XPath怎么用?Python XPath使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了XPath类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _add_action_to_detail
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: owner_name
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("")),
)
示例3: get_if_clause
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)
示例4: test_complex
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)
示例5: _get_reg_form_action
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
示例6: owner_name
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('')
)
)
示例7: get_userdata_autoselect
def get_userdata_autoselect(key, session_id, mode):
base_xpath = session_var("data", path="user")
xpath = session_var(key, path="user/data")
protected_xpath = XPath.if_(
XPath.and_(base_xpath.count().eq(1), xpath.count().eq(1)), xpath, XPath.empty_string()
)
datum = SessionDatum(id=session_id, function=protected_xpath)
assertions = [
EntriesHelper.get_assertion(
XPath.and_(base_xpath.count().eq(1), xpath.count().eq(1)),
"case_autoload.{0}.property_missing".format(mode),
[key],
),
EntriesHelper.get_assertion(
CaseIDXPath(xpath).case().count().eq(1), "case_autoload.{0}.case_missing".format(mode)
),
]
return datum, assertions
示例8: _add_case_search_action_to_detail
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)
示例9: to_frame
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
示例10: _get_case_search_action
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
示例11: test_paren
def test_paren(self):
xp = XPath('/data/q1')
self.assertEqual('/data/q1', xp.paren())
self.assertEqual('(/data/q1)', xp.paren(force=True))
self.assertEqual('(/data/q1)', XPath('/data/q1', compound=True).paren())
示例12: test_int
def test_int(self):
self.assertEqual('int(a)', XPath.int('a'))
示例13: test_date
def test_date(self):
self.assertEqual('date(a)', XPath.date('a'))
示例14: test_not
def test_not(self):
self.assertEqual('not a', XPath.not_('a'))
self.assertEqual('not (a or b)', XPath.not_(XPath.or_('a', 'b')))
示例15: test_and_or
def test_and_or(self):
self.assertEqual('a and b and c', XPath.and_('a', 'b', 'c'))
self.assertEqual('a and (b and c)', XPath.and_('a', XPath.and_('b', 'c')))
self.assertEqual('a or b or c', XPath.or_('a', 'b', 'c'))
self.assertEqual('(a or b) or c', XPath.or_(XPath.or_('a', 'b'), XPath('c')))