Exemple #1
0
def make_order3(request, template_name='service_order/make_order3.html'):
    request_params = request.GET.copy()
    #pop out the standard parameters, and the rest are the extra parameters and can be passed to Order_System as well
    request_params = request_params.dict() #TODO:
    #print 'request.REQUEST:', request.REQUEST
    #print 'request_params:', request_params
    order_id = request_params.pop('order_id')
    role = request_params.pop('role','')
    order_action = request_params.pop('action','')
    item_action = request_params.pop('item_action','')
    item_id = request_params.pop('item_id', '')
    #order = None
    refresh = request_params.pop('refresh','')   

    if refresh == 'y':
        context = Order_System.get_status(order_id)
        context.update(csrf(request))
        return render_to_response(template_name, context, context_instance=RequestContext(request))
    if not role:        
        return render_to_response(template_name, Order_System.get_initial(), context_instance=RequestContext(request))
    else:
        context = Order_System.goto_next(order_id, role, order_action, **request_params)
        context.update(csrf(request))
        return render_to_response(template_name, context, 
            context_instance=RequestContext(request))
Exemple #2
0
def make_order3(request, template_name='service_order/make_order3.html'):
    request_params = request.GET.copy()
    #pop out the standard parameters, and the rest are the extra parameters and can be passed to Order_System as well
    request_params = request_params.dict()  #TODO:
    #print 'request.REQUEST:', request.REQUEST
    #print 'request_params:', request_params
    order_id = request_params.pop('order_id')
    role = request_params.pop('role', '')
    order_action = request_params.pop('action', '')
    item_action = request_params.pop('item_action', '')
    item_id = request_params.pop('item_id', '')
    #order = None
    refresh = request_params.pop('refresh', '')

    if refresh == 'y':
        context = Order_System.get_status(order_id)
        context.update(csrf(request))
        return render_to_response(template_name,
                                  context,
                                  context_instance=RequestContext(request))
    if not role:
        return render_to_response(template_name,
                                  Order_System.get_initial(),
                                  context_instance=RequestContext(request))
    else:
        context = Order_System.goto_next(order_id, role, order_action,
                                         **request_params)
        context.update(csrf(request))
        return render_to_response(template_name,
                                  context,
                                  context_instance=RequestContext(request))
Exemple #3
0
def make_order2(request, template_name='service_order/make_order2.html'):
    order_id = request.REQUEST.get('order_id')
    role = request.REQUEST.get('role','')
    order_action = request.REQUEST.get('action','')
    item_action = request.REQUEST.get('item_action','')
    item_id = request.REQUEST.get('item_id')
    #order = None
    refresh = request.REQUEST.get('refresh')
    if refresh == 'y':
        return render_to_response(template_name, Order_System.get_status(order_id) , context_instance=RequestContext(request))
    if not role:        
        return render_to_response(template_name, Order_System.get_initial(), context_instance=RequestContext(request))
    else:
        return render_to_response(template_name, Order_System.goto_next(order_id, role, order_action, item_action, item_id), 
            context_instance=RequestContext(request))
Exemple #4
0
def create_order(request, template_name='service_order/create_order.html'):
    if request.method == 'POST':
        # item_list = request.POST.getlist('item')
        # o = Order_System.create_order(item_list=item_list)
        item_id_list = request.POST.getlist('item_id')
        item_name_list = request.POST.getlist('item_name')
        #pdb.set_trace()
        request_params = request.POST.copy()
        request_params = request_params.dict()
        items = []
        for i, item_id in enumerate(item_id_list):
            items.append({
                'commodity_id': item_id,
                'name': item_name_list[i],
                'sku_service_times': 5
            })  #pass in a default service_times here
        #items_snapshot = {'order_type':'service', 'items':items}
        items_snapshot = items
        items_json = json.dumps(items_snapshot)
        request_params['items_json'] = items_json
        print 'items_json:', items_json

        o = Order_System.create_order(item_list=item_id_list, **request_params)
        return HttpResponseRedirect(
            '/service_order_demo/make_order3/?order_id=' + o + '&refresh=y')
    cs = Service_Commodity.objects.all()
    return render_to_response(
        template_name,
        {'items': cs[:1]},  #for now one order has only one item
        context_instance=RequestContext(request))
Exemple #5
0
    def test_work_flow1(self):
        """no attendance code used, then expired

        """
        o_id2 = Order_System.create_order(
            **{
                'items_json':
                '[{"sku_service_times": 5, "price": 100.0, "commodity_id": "793669834", "name": "yoga meditation"}]',
                "buyer_id": "6769834"
            })

        so2 = get_object_or_404(Service_Order, id=o_id2)
        current_state_post_action = so2.goto_next('P', 'payment successful')
        self.assertTupleEqual(current_state_post_action,
                              (u'FP', u'payment_successful'))
        current_state_post_action = so2.goto_next('P',
                                                  'attendance code expired')
        self.assertTupleEqual(current_state_post_action,
                              (u'FP', u'attendance_code_expired'))
        current_state_post_action = so2.goto_next('P', 'finished refund')
        self.assertTupleEqual(current_state_post_action,
                              (u'FP', u'refund_sheet_finished'))
        current_state = so2.state
        self.assertEqual(current_state, u'CT')
        current_state_post_action = so2.get_role_actions()
        self.assertDictEqual(current_state_post_action, {})
Exemple #6
0
def make_order2(request, template_name='service_order/make_order2.html'):
    order_id = request.REQUEST.get('order_id')
    role = request.REQUEST.get('role', '')
    order_action = request.REQUEST.get('action', '')
    item_action = request.REQUEST.get('item_action', '')
    item_id = request.REQUEST.get('item_id')
    #order = None
    refresh = request.REQUEST.get('refresh')
    if refresh == 'y':
        return render_to_response(template_name,
                                  Order_System.get_status(order_id),
                                  context_instance=RequestContext(request))
    if not role:
        return render_to_response(template_name,
                                  Order_System.get_initial(),
                                  context_instance=RequestContext(request))
    else:
        return render_to_response(template_name,
                                  Order_System.goto_next(
                                      order_id, role, order_action,
                                      item_action, item_id),
                                  context_instance=RequestContext(request))
Exemple #7
0
    def test_work_flow6(self):
        """ create order, then cancel it

        """
        o_id = Order_System.create_order()
        so = get_object_or_404(Service_Order, id=o_id)
        current_state = so.service_order.state
        self.assertEqual(current_state, u"WP")
        next_actions = so.service_order.get_role_actions()
        self.assertDictEqual(
            next_actions, {u"P": [u"no payment", u"payment successful"], u"B": [u"cancel order", u"make payment"]}
        )
        current_state_post_action = so.goto_next("B", u"cancel order")
        self.assertTupleEqual(current_state_post_action, (u"CT", u""))
Exemple #8
0
    def test_work_flow6(self):
        """ create order, then cancel it

        """
        o_id = Order_System.create_order()
        so = get_object_or_404(Service_Order, id=o_id)
        current_state = so.service_order.state
        self.assertEqual(current_state, u'WP')
        next_actions = so.service_order.get_role_actions()
        self.assertDictEqual(
            next_actions, {
                u'P': [u'no payment', u'payment successful'],
                u'B': [u'cancel order', u'make payment']
            })
        current_state_post_action = so.goto_next('B', u'cancel order')
        self.assertTupleEqual(current_state_post_action, (u'CT', u''))
Exemple #9
0
    def test_work_flow1(self):
        """no attendance code used, then expired

        """
        o_id2 = Order_System.create_order(
            **{
                "items_json": '[{"sku_service_times": 5, "price": 100.0, "commodity_id": "793669834", "name": "yoga meditation"}]',
                "buyer_id": "6769834",
            }
        )

        so2 = get_object_or_404(Service_Order, id=o_id2)
        current_state_post_action = so2.goto_next("P", "payment successful")
        self.assertTupleEqual(current_state_post_action, (u"FP", u"payment_successful"))
        current_state_post_action = so2.goto_next("P", "attendance code expired")
        self.assertTupleEqual(current_state_post_action, (u"FP", u"attendance_code_expired"))
        current_state_post_action = so2.goto_next("P", "finished refund")
        self.assertTupleEqual(current_state_post_action, (u"FP", u"refund_sheet_finished"))
        current_state = so2.state
        self.assertEqual(current_state, u"CT")
        current_state_post_action = so2.get_role_actions()
        self.assertDictEqual(current_state_post_action, {})
Exemple #10
0
def create_order(request, template_name='service_order/create_order.html'):
    if request.method == 'POST':
        # item_list = request.POST.getlist('item')
        # o = Order_System.create_order(item_list=item_list)
        item_id_list = request.POST.getlist('item_id')
        item_name_list = request.POST.getlist('item_name')
        #pdb.set_trace()
        request_params = request.POST.copy()
        request_params = request_params.dict()
        items = []
        for i, item_id in enumerate(item_id_list):
            items.append({'commodity_id':item_id, 'name':item_name_list[i], 'sku_service_times':5}) #pass in a default service_times here
        #items_snapshot = {'order_type':'service', 'items':items}
        items_snapshot = items
        items_json = json.dumps(items_snapshot)  
        request_params['items_json'] = items_json
        print 'items_json:', items_json

        o = Order_System.create_order(item_list=item_id_list, **request_params)
        return HttpResponseRedirect('/service_order_demo/make_order3/?order_id='+o+'&refresh=y') 
    cs = Service_Commodity.objects.all()
    return render_to_response(template_name, {'items':cs[:1]}, #for now one order has only one item
            context_instance=RequestContext(request))