Refactor + improve order list
This commit is contained in:
parent
2c1a9986f4
commit
56725af770
1 changed files with 12 additions and 3 deletions
|
@ -3,6 +3,7 @@ import json
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from decouple import config, Csv
|
from decouple import config, Csv
|
||||||
|
from datetime import datetime
|
||||||
from flask import Flask, request
|
from flask import Flask, request
|
||||||
from flask_restful import Resource, Api
|
from flask_restful import Resource, Api
|
||||||
from pyotp import TOTP
|
from pyotp import TOTP
|
||||||
|
@ -369,9 +370,17 @@ class OrderList(Resource):
|
||||||
orders = client.get_prefix("/v1/user/{}/orders".format(data['name']), value_in_json=True)
|
orders = client.get_prefix("/v1/user/{}/orders".format(data['name']), value_in_json=True)
|
||||||
orders_dict = {}
|
orders_dict = {}
|
||||||
for p in orders:
|
for p in orders:
|
||||||
order_dict[p.key] = p.value
|
order_dict = json.loads(p.value)
|
||||||
logging.debug("Orders = {}".format(order_dict))
|
logging.debug("order_dict = " + str(order_dict))
|
||||||
return order_dict, 200
|
logging.debug("type p.value = " + str(type(p.value)))
|
||||||
|
logging.debug("p.value = " + str(p.value))
|
||||||
|
order_dict["ordered_at"] = datetime.fromtimestamp(
|
||||||
|
order_dict["ordered_at"]).strftime("%c")
|
||||||
|
order_dict["product"] = get_user_friendly_product(
|
||||||
|
order_dict["product"])
|
||||||
|
orders_dict[p.key] = order_dict
|
||||||
|
logging.debug("Orders = {}".format(orders_dict))
|
||||||
|
return orders_dict, 200
|
||||||
|
|
||||||
except KeyError as kerr:
|
except KeyError as kerr:
|
||||||
logging.error(str(kerr))
|
logging.error(str(kerr))
|
||||||
|
|
Loading…
Reference in a new issue