本文整理汇总了Python中xml.etree.ElementTree.can_be_added方法的典型用法代码示例。如果您正苦于以下问题:Python ElementTree.can_be_added方法的具体用法?Python ElementTree.can_be_added怎么用?Python ElementTree.can_be_added使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xml.etree.ElementTree
的用法示例。
在下文中一共展示了ElementTree.can_be_added方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_available_substrates
# 需要导入模块: from xml.etree import ElementTree [as 别名]
# 或者: from xml.etree.ElementTree import can_be_added [as 别名]
def get_available_substrates(monomers, current, curatedonly=True, selected=None):
if selected is None:
selected = len(monomers) - 1
reason = None
if current:
if selected > 0:
chirality = Substrate.objects.get(pk=monomers[selected - 1]).chirality
else:
chirality = None
reason = 3
else:
chirality = Substrate.objects.get(pk=monomers[-1]).chirality
substrates = Substrate.objects.exclude(user__username='sbspks')
if not current or selected == len(monomers) - 1:
aas = filter(lambda x: x.can_be_added(chirality, curatedonly), substrates)
if reason is None:
reason = 2
else:
following = Substrate.objects.get(pk=monomers[selected + 1])
aas = filter(lambda x: x.can_be_added(chirality, curatedonly) and following.can_be_added(x.chirality, curatedonly), substrates)
if reason is None:
reason = 1
if len(monomers) == 1 and current:
reason = 0
return (aas, reason)
示例2: get_available_monomers
# 需要导入模块: from xml.etree import ElementTree [as 别名]
# 或者: from xml.etree.ElementTree import can_be_added [as 别名]
def get_available_monomers(request):
reason = None
if request.method == 'POST' and "monomer[]" in request.POST:
monomers = request.POST.getlist("monomer[]")
if 'selected' in request.POST:
selected = int(request.POST['selected'])
else:
selected = None
aas, reason = get_available_substrates(monomers, toBool(request.POST['current']), toBool(request.POST['curatedonly']), selected)
else:
aas = filter(lambda x: x.can_be_added(curatedonly=toBool(request.POST['curatedonly'])), Substrate.objects.exclude(user__username='sbspks'))
reason = 0
json = {}
minid = float("Inf")
for aa in aas:
if aa.parent is None:
name = aa.name
if aa.name[0:2].upper() == 'L-' or aa.name[0:2].upper() == 'D-':
name = aa.name[2:]
if aa.pk in json:
key = aa.pk
elif aa.enantiomer is not None and aa.enantiomer.pk in json:
key = aa.enantiomer.pk
else:
key = None
if aa.enantiomer is None:
chirality = 'N'
else:
chirality = aa.chirality
if key is not None:
if key < minid:
minid = key
json[key][chirality.lower() + "id"] = aa.pk
json[key][chirality+'Children'] = [{"text": c.name, "id": c.pk} for c in aa.child.all()]
#names[name]['name'] = name
else:
json[aa.pk] = {"id": aa.pk, chirality.lower() + "id": aa.pk, 'text': name, aa.chirality+'Children': [{"text": c.name, "id": c.pk} for c in aa.child.all()]}
jsonlist = json.values()
jsonlist.sort(lambda x,y: cmp(x['text'], y['text']))
return JsonResponse({"monomers": json, "monomerslist": jsonlist, "reason": reason})