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


Python Branch.save方法代码示例

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


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

示例1: create

# 需要导入模块: from models import Branch [as 别名]
# 或者: from models.Branch import save [as 别名]
 def create(self, request, **kwargs):
     serializer = BranchSerializer(data=request.data)
     if serializer.is_valid():
         user = save_user(request.data, UserPermissions.IS_BRANCH)
         company = Company(**request.data["company"])
         city = City(**request.data["city"])
         branch = Branch(
             nickName=request.data["nickName"],
             type=UserType.BRANCH,
             address=request.data["address"],
             phone=request.data["phone"],
             company=company,
             city=city,
             user=user,
         )
         branch.save()
         return Response(
             {
                 "status": "SUCCESS",
                 "msg_status": "Sucursal creada satisfactoriamente. Puede ingresar con su nueva contrasena.",
             }
         )
     else:
         messages = []
         make_error(serializer.errors.values(), messages)
         return Response({"status": "FAILURE", "msg_status": messages})
开发者ID:emosquera,项目名称:ticketIntelligence,代码行数:28,代码来源:viewsets.py

示例2: _branchAdd

# 需要导入模块: from models import Branch [as 别名]
# 或者: from models.Branch import save [as 别名]
def _branchAdd(requestData, user):
    '''
        增加一个选项的具体处理过程
    '''
    # 检查是否有提供Question
    keys = requestData.keys()
    if 'question' not in keys:
        return packageResult(RESULT_CODE.ERROR, RESULT_MESSAGE.NO_ID)
    questionIdSigned = requestData['question']

    # 对id进行数字签名的检查
    try:
        signer = Signer()
        questionId = signer.unsign(questionIdSigned)
    except BadSignature:
        # 篡改发现处理
        return packageResult(RESULT_CODE.ERROR, RESULT_MESSAGE.BAD_SAGNATURE)

    # 尝试读取question信息
    questionList = Question.objects.filter(id=questionId)
    if len(questionList) == 0:
        return packageResult(RESULT_CODE.ERROR, RESULT_MESSAGE.OBJECT_NOT_EXIST)
    question = questionList[0]

    # 检查是否有权限做新增
    if question.createBy.id != user.id:
        return packageResult(RESULT_CODE.ERROR, RESULT_MESSAGE.NO_PRIVILEGE)

    # 遍历Branch的所有Field,并尝试在request中寻找是否提供了对应的数据
    data = {}
    for field in getModelFields(Branch):
        # 跳过系统自动增加的字段
        if field.auto_created:
            continue
        # 读取request数据
        value = requestData.get(field.name, None)
        # 特殊处理json的Boolean型的变量
        if type(field) == BooleanField:
            value = jsonBoolean2Python(value)
        # 对创建人和修改人的信息进行特殊处理
        if field.name in [USER_CREATE_BY_FIELD_NAME, USER_MODIFY_BY_FIELD_NAME]:
            value = user
        # 对question字段进行特殊处理,提交的数据是id转化为对象
        if field.name == 'question':
            value = question
        # 对ord 字段进行特殊处理,取当前的问题数量加1
        if field.name == 'ord':
            # 这里锁定了question所有branch对象
            value = question.branch_set.select_for_update().count()
            # 如果调用者没有显示执行字段值为空,则不增加到data中去,让模型的默认值发挥作用
        # 字段代码不能早于对createBy和modifyBy的处理
        if value is None and field.name not in keys:
            continue
        # 将校验的数据添加到data,准备为创建数据库用
        data[field.name] = value
    branch = Branch(**data)

    # 进行数据校验
    try:
        branch.full_clean()
    except ValidationError as exception:
        return packageResult(
            RESULT_CODE.ERROR, RESULT_MESSAGE.VALIDATION_ERROR,
            {'validationMessage': exception.message_dict})

    # 写到数据库
    branch.save()
    # 返回成功
    return packageResult(RESULT_CODE.SUCCESS, RESULT_MESSAGE.SUCCESS, {'branchId': branch.id})
开发者ID:xmduhan,项目名称:qisite,代码行数:71,代码来源:services.py

示例3: index

# 需要导入模块: from models import Branch [as 别名]
# 或者: from models.Branch import save [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.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。