コード例 #1
0
ファイル: product.py プロジェクト: scorpioxiatian/gringotts
    def get_all(self, name=None, service=None, region_id=None,
                limit=None, offset=None,
                sort_key='created_at', sort_dir='desc'):
        """Get all product
        """
        filters = {}
        if name:
            filters.update(name=name)
        if service:
            filters.update(service=service)
        if region_id:
            filters.update(region_id=region_id)

        conn = pecan.request.db_conn

        result = conn.get_products(request.context,
                                   filters=filters,
                                   limit=limit,
                                   offset=offset,
                                   sort_key=sort_key,
                                   sort_dir=sort_dir)
        products = []
        for p in result:
            unit_price = \
                gringutils.transform_unit_price_string(p.unit_price)
            sp = models.SimpleProduct.transform(name=p.name,
                                                service=p.service,
                                                unit_price_price=unit_price,
                                                currency='CNY')
            products.append(sp)
        return products
コード例 #2
0
ファイル: product.py プロジェクト: scorpioxiatian/gringotts
    def _product(self):
        self.conn = pecan.request.db_conn
        try:
            product = self.conn.get_product(request.context,
                                            product_id=self._id)
        except Exception:
            LOG.error('Product %s not found' % self._id)
            raise exception.ProductIdNotFound(product_id=self._id)

        product.unit_price = \
            gringutils.transform_unit_price_string(product.unit_price)
        return product
コード例 #3
0
ファイル: product.py プロジェクト: ShooterTT/gringotts
    def get_all(self, name=None, service=None, region_id=None,
                limit=None, offset=None,
                sort_key='created_at', sort_dir='desc'):
        """Get all product."""

        if limit and limit < 0:
            raise exception.InvalidParameterValue(err="Invalid limit")
        if offset and offset < 0:
            raise exception.InvalidParameterValue(err="Invalid offset")

        filters = {}
        if name:
            filters.update(name=name)
        if service:
            filters.update(service=service)
        if region_id:
            filters.update(region_id=region_id)

        conn = pecan.request.db_conn

        result = conn.get_products(request.context,
                                   filters=filters,
                                   limit=limit,
                                   offset=offset,
                                   sort_key=sort_key,
                                   sort_dir=sort_dir)
        products = []
        for p in result:
            unit_price = \
                gringutils.transform_unit_price_string(p.unit_price)
            sp = models.Product.transform(name=p.name,
                                          service=p.service,
                                          region_id=p.region_id,
                                          product_id=p.product_id,
                                          description=p.description,
                                          unit_price=unit_price,
                                          created_at=p.created_at,
                                          updated_at=p.updated_at)
            products.append(sp)
        total_count = conn.get_products_count(request.context,
                                              filters=filters)
        return models.Products(total_count=total_count,
                               products=products)