当前位置: 首页>>代码示例>>Python>>正文


Python ElementTree.can_be_added方法代码示例

本文整理汇总了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)
开发者ID:ilia-kats,项目名称:NRPSDesigner,代码行数:28,代码来源:views.py

示例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})
开发者ID:ilia-kats,项目名称:NRPSDesigner,代码行数:43,代码来源:views.py


注:本文中的xml.etree.ElementTree.can_be_added方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。