• 纪念一下第一次写的django代码


    @csrf_exempt
    def new_project_detail(request):
        if 'project_name' not in request.POST or 'project_position' not in request.POST or 'interest_rate' not in
                request.POST or 'financing_amount' not in request.POST or 'deadline' not in request.POST or
                        'repayment_time' not in request.POST or 'project_detail' not in request.POST or 'project_type'
                not in request.POST or 'bonding_company' not in request.POST:
            return json_response(False, '050002', 'lack of parameter')
        try:
            if store_data(request):
                return json_response(True)
            else:
                return json_response(False, '020005', '数据库错误')
        except ValueError:
            return json_response(False, '020002', '数据字段错误')
        except ProjectDetail.DoesNotExist:
            return json_response(False, '020003', '信息不存在')
        except Exception, e:
            print e
            return json_response(False, '020004', e)


    @transaction.commit_manually
    def store_data(request):
        try:
            project = ProjectDetail(project_name=request.POST.get("project_name"),
                                    project_position=request.POST.get("project_position"),
                                    interest_rate=request.POST.get("interest_rate"),
                                    financing_amount=request.POST.get("financing_amount"),
                                    deadline=request.POST.get("deadline"),
                                    repayment_time=request.POST.get("repayment_time"),
                                    project_detail=request.POST.get("project_detail"),
                                    project_type=request.POST.get("project_type"))
            project.save()
            project.project_NO = request.POST.get("project_NO", datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S"))
            project.project_purpose = request.POST.get("project_purpose", None)
            if 'company_id' in request.POST:
                company = Company.objects.get(id=request.POST.get("company_id"))
                financial_status = CompanyFinancialStatus.objects.get(company=company)
                project.company = company
                project.financial_status = financial_status

            bonding_company = BondingCompany.objects.get(id=request.POST.get("bonding_company"))
            project.bonding_company.add(bonding_company)
            project.status = PROJECT_STATUS_INIT
            project.project_end_type = request.POST.get("project_end_type", PROJECT_END_TYPE_BY_AMOUNT)
            project.save()
            transaction.commit()
            return True
        except Company.DoesNotExist:
            transaction.rollback()
            return False
        except CompanyFinancialStatus.DoesNotExist:
            transaction.rollback()
            return False
        except BondingCompany.DoesNotExist:
            transaction.rollback()
            return False
        except Exception, e:
            print e
            transaction.rollback()
            return False

  • 相关阅读:
    虎虎的小尾巴:作为交易员,从最初的新人到如今实现稳定盈利,一路走来你有过什么记忆非常深刻的亏损教训和体会? 2018-08-09
    虎虎的小尾巴:期货市场的资金吸引力?
    虎虎的小尾巴
    虎虎的小尾巴:高质量的期货研究报告去哪里找?
    虎虎的小尾巴:如何看待2017.8.7PTA1801一分钟内闪崩下跌6%?
    虎虎的小尾巴:交易逻辑重于一切 2017-08-13
    虎虎的小尾巴:期货数据入门
    虎虎的小尾巴:期货交易在使用基本面分析操作过程中要注意哪些问题?怎么控制风险? 2017-03-11
    Android开发-- 使用ADT23 的一些问题
    Git 学习笔记--3.EGit使用手册
  • 原文地址:https://www.cnblogs.com/tuifeideyouran/p/3724114.html
Copyright © 2020-2023  润新知