Esempio n. 1
0
def add_g_to_o(params):
    print "adding"
    g_path = STORAGE_ROOT+'/good-'+params['name']+'_'+params['country']+'_'+params['g_id']+'.json'
    t_good = json.load(open(g_path, 'r'))
    t_good = dict_to_good(t_good)
    print t_good

    o_path = STORAGE_ROOT+'/order-'+params['to']+'_'+params['ord_c']+'_'+params['o_id']+'.json'
    t_order = json.load(open(o_path, 'r'))
    #print t_good, t_order
    new_order = Order(t_order['name'], t_order['country'], datetime.strptime(t_order['delivery_time'], '%d.%m.%Y').strftime('%d.%m.%Y'))
    new_order.goods = dict_to_goods(t_order['goods'])
    new_order.price_of_order = int(t_order['price']) + int(t_good.good_price)
    new_order.goods.append(t_good)
    obj = new_order.to_dict()
    full_path = "%s\%s-%s_%s_%s.json" % (STORAGE_ROOT, 'order', new_order.order_name, new_order.delivery_country,
                                         params['o_id'])
    wfile = open(full_path, 'w')
    json.dump(obj, wfile)
    wfile.close()