def read_product_with_query(self, query_str):
        try:
            product = Product.objects.get(**query_str)
            product_data = ProductSerializer(product).data
        except Exception as e:
            msg = '[ProductService][read_product_with_query][' + str(e) + ']'
            self.logger_error.error(msg)
            product_data = {}

        return product_data
    def read_product_data_with_id(self, product_id):
        try:
            product = Product.objects.get(id=product_id)
            product_data = ProductSerializer(product).data
        except Exception as e:
            msg = '[ProductService][read_product_data_with_id][' + str(e) + ']'
            self.logger_error.error(msg)
            raise BusinessLogicError(msg, None, None)

        return product_data
    def read_recommend_list(self, query_str):
        try:
            product_qs = Product.objects.filter(**query_str).order_by('?')[:2]
            products_data = ProductSerializer(product_qs, many=True).data
        except Exception as e:
            msg = '[ProductService][read_recommend_list][' + str(e) + ']'
            self.logger_error.error(msg)
            raise BusinessLogicError(msg, None, None)

        return products_data
示例#4
0
    def get_product_list_from_ids(self, product_list):
        """
        Get product list from product id list
        :param product_list:
        :return: json array of product data
        """
        product_service = ProductService(self.logger_info, self.logger_error, 'default')
        product_list_qs = product_service.read_product_list_with_query({'id__in': product_list})
        product_list = ProductSerializer(product_list_qs, many=True).data

        return product_list
示例#5
0
    def get_product_list_with_query(self, hub_id, start_date, end_date):
        """
        Get product list with query string
        :param hub_id: current hub id
        :param start_date: start date for getting product
        :param end_date: end date for getting product
        :return: dictionary with lunch product list and dinner product list
        """
        query_product = {'hub': hub_id, 'sales_time': 0,
                         'start_date__lte': start_date, 'end_date__gte': end_date}
        product_service = ProductService(self.logger_info, self.logger_error, 'default')

        product_list_qs = product_service.read_product_list_with_query(query_product)
        product_list = ProductSerializer(product_list_qs, many=True).data

        return product_list
    def read_product_list_v3(self, hub_id, current_date):
        try:
            products_qs = Product.objects.using('default').filter(
                Q(hub=hub_id,
                  type__lt=self.MENU_TYPE_LIMIT,
                  sales_time=self.ALL_DAY_MENU,
                  start_date__lte=current_date,
                  end_date__gte=current_date)).order_by('list_index')
            products_data = ProductSerializer(products_qs, many=True).data
        except Exception as e:
            msg = '[ProductService][read_product_count_with_query][' + str(
                e) + ']'
            self.logger_error.error(msg)
            raise BusinessLogicError(msg, None, None)

        return products_data