示例#1
0
    def put(self, prod_id=None):
        if not prod_id:
            return "Відсутній id в url"
        json_data = json.dumps(request.json)
        try:
            try:
                products_data = ProductsSchema().loads(json_data)
                products_data = json.loads(
                    ProductsSchema().dumps(products_data))

                products = Products(id=prod_id)
                category = Category.objects.filter(
                    id=products_data['category'])

                # Наступний if не дозволяє переміщати товари в категорії, лише в підкатегорії
                if category[0].parent_category:
                    products.update(id=prod_id,
                                    in_stock=products_data['in_stock'],
                                    category=category[0].id,
                                    model=products_data['model'],
                                    name=products_data['name'],
                                    price=products_data['price'])
                else:
                    products_data = "Продукти не можна переміщати в категорії, лише в підкатегорії"
            except ValidationError as error:
                products_data = error.messages
            return products_data
        except Val_error as error:
            data = "Введений ID у невірному форматі або неіснуючий: " + str(
                error)
            return data
示例#2
0
def handle_products():

    if request.method == 'POST':
        body = request.get_json()

        if body is None:
            raise APIException("You need to specify the request body as a json object", status_code=400)
        if 'plan_name' not in body:
            raise APIException('You need to specify the plan_name', status_code=400)
        # if 'price' not in body:
        #     raise APIException('You need to specify the price', status_code=400)
        # if 'orders_id' not in body:
        #     raise APIException('You need to specify the orders_id', status_code=400)
        # if 'mag_f' not in body:
        #     raise APIException('You need to specify the mag_f', status_code=400)
        # if 'temp' not in body:
        #     raise APIException('You need to specify the temp', status_code=400)
        # if 'atmo_pressure' not in body:
        #     raise APIException('You need to specify the atmo_pressure', status_code=400)
        # if 'axis_measure' not in body:
        #     raise APIException('You need to specify the axis_measure', status_code=400)
        # return "Invalid Method", 404

        product1 = Products(plan_name=body['plan_name'], price=body['price'])
        db.session.add(product1)
        db.session.commit()
        return "ok", 200

    if request.method == 'GET':
        all_products = Products.query.all()
        all_products = list(map(lambda x: x.serialize(), all_products))
    return jsonify(all_products), 200
示例#3
0
def db_create_product(name, amount, price):
    #Here we could also check existence of the product (do not allow duplicate name)
    if validate_int((amount, price)):
        new_product = Products(None, name, amount, price)
        db.session.add(new_product)
        db.session.commit()
        return True
    return False
示例#4
0
    def process_item(self, item, spider):

        session = self.Session()
        product = Products(**item)

        try:
            session.add(product)
            session.commit()
        except:
            session.rollback()
            raise
        finally:
            session.close()

        return item
示例#5
0
    def delete(self, prod_id=None):
        if not prod_id:
            return "Відсутній id в url"
        try:
            product_to_delete = Products.objects.get(id=prod_id)
            product_to_delete = ProductsSchema().dump(product_to_delete)

            product = Products(id=prod_id)
            product.delete()
            return product_to_delete
        except DoesNotExist as error:
            data = "За введеним ID наразі немає записів: " + str(error)
            return data
        except Val_error as error:
            data = "Введений ID у невірному форматі: " + str(error)
            return data
示例#6
0
文件: collectdata.py 项目: zipu/Quant
    def __init__(self):
        self.logger = logging.getLogger('CollectData')
        try:
            self.products = pickle.load(open(PRODUCTSFILE, 'rb'))
        except FileNotFoundError:
            self.products = Products()

        XAEvents.instance = self  #이벤트 처리 클래스에 현재 인스턴스를 저장
        self.session = None  #세션 오브젝트
        self.query = None  #쿼리 오브젝트
        self.timer = 0  #타이머
        #self.yesterday = (datetime.today() - timedelta(1)).strftime('%Y%m%d')

        #로그인
        self.next_step(0)

        #dev
        self.flag = False