예제 #1
0
def market_over_view(request,tp_id=None):
    
    tp_id  = tp_id_proc(request,tp_id)

    tp_obj = TradePlanModel.objects.get(pk = tp_id)

    if request.method == "POST":
        movd_formset = MovDetailInlineFormset(request.POST,
                                              request.FILES,
                                              instance = tp_obj.market_overview)
        mov_form     = MarketOverViewForm(request.POST,instance = tp_obj.market_overview)
        plan_res_form  = PlanResultForm(request.POST,instance = tp_obj)
        if movd_formset.is_valid():
            movd_formset.save()

        if mov_form.is_valid():
            mov_form.save()
        else:
            return redirect('tradesys.views.TradePlan.market_over_view')

        if plan_res_form.is_valid() and plan_res_form.cleaned_data['plan_result'] is not None:
            plan_res_form.save()
        else:
            return redirect('tradesys.views.TradePlan.market_over_view')

        if tp_obj.diff_s_overview is None:
            tp_obj.diff_s_overview = diff_overview_init(request,tp_obj,'s')
            tp_obj.save()

        if tp_obj.diff_b_overview is None:
            tp_obj.diff_b_overview = diff_overview_init(request,tp_obj,'b')
            tp_obj.save()

        if plan_res_form.cleaned_data['plan_result'] == 'N':
            return redirect('/tradesys/MyTradePlan/report_view/%d/' % tp_obj.id )

        return redirect('tradesys.views.TradePlan.market_diff_view')
    else:

        movd_formset   = MovDetailInlineFormset(instance = tp_obj.market_overview)
        mov_form       = MarketOverViewForm(instance = tp_obj.market_overview)
        plan_res_form  = PlanResultForm(instance = tp_obj)

    return render_to_response("tradesys/MarketOverView.html", {
            "tradeframe_dict" : dict(TRADEFRAME),
            "tradetype_dict" : dict(TRADETYPE),
            "timeframe_dict" : dict(TIMEFRAME),
            "tradetype" : tp_obj.tradetype,
            "movd_formset" : movd_formset,
            "mov_form" : mov_form,
            "plan_res_result" : plan_res_form,
            "image_base_url": settings.IMAGE_BASE_URL,
            },context_instance=RequestContext(request))
예제 #2
0
def market_diff_view(request,tp_id = None):

    tp_id  = tp_id_proc(request,tp_id)
    tp_obj = TradePlanModel.objects.get(pk = tp_id)

    # usdx 是六大非美货币的交易功课.
    # 黄金/白银/交叉盘该如何设计,需要和小月月等专业人事共同设计.
    # if tp_obj.tradeytype != 'USDX':
    mdi_obj = MarketDetailInfo.objects

    s_queryset = mdi_obj.filter(market_overview = tp_obj.diff_s_overview,
                                timeframe = trade_frame_map(tp_obj.tradeframe)[0])
    b_queryset = mdi_obj.filter(market_overview = tp_obj.diff_s_overview,
                                timeframe = trade_frame_map(tp_obj.tradeframe)[1])

    if request.method == "POST":
        s_diffview = MdvDetailFormset(request.POST, request.FILES,
                                      prefix = 's',
                                      queryset = s_queryset)

        b_diffview = MdvDetailFormset(request.POST, request.FILES,
                                      prefix = 'b',
                                      queryset = b_queryset)

        mov_b_form = MarketOverViewForm(request.POST,
                                        prefix = 'b',
                                        instance = tp_obj.diff_b_overview)

        mov_s_form = MarketOverViewForm(request.POST,
                                        prefix = 's',
                                        instance = tp_obj.diff_s_overview)

        if s_diffview.is_valid():
            s_diffview.save()

        if b_diffview.is_valid():
            b_diffview.save()

        if mov_b_form.is_valid():
            mov_b_form.save()

        if mov_s_form.is_valid():
            mov_s_form.save()
        return redirect('tradesys.views.TradePlan.first_select_view')

    else:
        b_diffview = MdvDetailFormset(prefix = 'b',queryset = b_queryset)
        s_diffview = MdvDetailFormset(prefix = 's',queryset = s_queryset)
        mov_b_form =  MarketOverViewForm(prefix = 'b',instance = tp_obj.diff_b_overview)
        mov_s_form =  MarketOverViewForm(prefix = 's',instance = tp_obj.diff_s_overview)


    return render_to_response("tradesys/MarketDiffView.html", {
            "tradeframe_dict" : dict(TRADEFRAME),
            "tradetype_dict" : dict(TRADETYPE),
            "timeframe_dict" : dict(TIMEFRAME),
            "tradetype"  : tp_obj.tradetype,
            "b_diffview" : b_diffview,
            "s_diffview" : s_diffview,
            "mov_b_form" : mov_b_form,
            "mov_s_form" : mov_s_form,
            "image_base_url": settings.IMAGE_BASE_URL,
            },context_instance=RequestContext(request))