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


Python Branch.get_tips方法代码示例

本文整理汇总了Python中models.Branch.get_tips方法的典型用法代码示例。如果您正苦于以下问题:Python Branch.get_tips方法的具体用法?Python Branch.get_tips怎么用?Python Branch.get_tips使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Branch的用法示例。


在下文中一共展示了Branch.get_tips方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: index

# 需要导入模块: from models import Branch [as 别名]
# 或者: from models.Branch import get_tips [as 别名]
def index(request):
    if request.method != 'POST':
        return render(request, 'index.html')
    else:
        if request.is_ajax():
            if request.POST.get('userName'):
                user_name=request.POST.get('userName')
                user=User.objects.get(user_name=user_name)
            else:
                user=None

            if request.POST.get("mode") == "grow":
                    
                parent = request.POST.get('parent')
                child = request.POST.get('child')
                
                # case 1: parent already trunk -- create branch from child
                try:
                    trunk = Trunk.objects.get(text=parent)
                    drawing = trunk.drawing                    
                    if trunk:
                        try:
                            branch = Branch.objects.get(text=child)
                            data = {"already" : True,
                                    "parent" : parent,
                                    "child" : child
                            }
                            return JsonResponse(data)
                        except Branch.DoesNotExist:                            
                            branch = Branch(text=child, trunk=trunk)
                            branch.save()
                            branch.get_tips()
                            data = drawing.get_data()
                            if trunk.branch_set.count() > 1:
                                data["tree?"] = trunk.text
                                branch.stage = "filled"
                                branch.save()
                            return JsonResponse(data)
                        # display message saying that this combo already exists.
                                
                except Trunk.DoesNotExist:
                    # case 2: parent already branch -- create twig from child
                    print("trying case 2")
                    try:
                        branch = Branch.objects.get(text=parent)
                        drawing = branch.trunk.drawing
                        if branch:
                            try:
                                twig = Twig.objects.get(text=child)
                                data = {"already" : True,
                                        "parent" : parent,
                                        "child" : child
                                }
                                return JsonResponse(data)
                            except Twig.DoesNotExist:
                                twig = Twig(text=child, branch=branch)                        
                                twig.save()
                                twig.get_tips()
                                data = drawing.get_data()
                                if branch.trunk.branch_set.count() > 1:
                                    data["tree?"] = branch.trunk.text
                                    twig.stage = "filled"
                                    twig.save()
                                return JsonResponse(data)
                                
                    except Branch.DoesNotExist:
                        # case 3: parent already twig -- create leaf from child
                        print("trying case 3")
                        try:
                            twig = Twig.objects.get(text=parent)
                            drawing = twig.branch.trunk.drawing
                            if twig:
                                try:
                                    leaf = Leaf.objects.get(text=child)
                                    leaf.twigs.add(twig)
                                    leaf.save()
                                    leaf.get_tips(parent)
                                    data = drawing.get_data()
                                    return JsonResponse(data)
                                except Leaf.DoesNotExist:                                    
                                    leaf = Leaf(text=child)
                                    leaf.save()
                                    leaf.twigs.add(twig)
                                    leaf.save()
                                    leaf.get_tips(parent)
                                    data = drawing.get_data()
                                    if twig.branch.trunk.branch_set.count() > 1:
                                        data["tree?"] = twig.branch.trunk.text
                                        leaf.stage = "filled"
                                        leaf.save()
                                    return JsonResponse(data)
                                
                        except Twig.DoesNotExist:
                            # case 4: neither child nor parent saved to tree -- 
                            # create branch from child and trunk from parent
                            print("trying case 4")
                            trunk = Trunk.objects.create(text=parent)
                            branch = Branch.objects.create(text=child)
                            branch.get_tips()
                            branch.trunk = trunk
#.........这里部分代码省略.........
开发者ID:qualisign,项目名称:treeli,代码行数:103,代码来源:views.py


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