Ejemplo n.º 1
0
    def get_children_product_classifications(self,
                                             father_id,
                                             with_father=True):
        """
		获得所有子分类集合(包括子级和子级的子级)
		"""
        father_id = int(father_id)
        if self.corp.is_supplier():
            models = list(mall_models.Classification.select().dj_where(
                status=mall_models.CLASSIFICATION_ONLINE).where(
                    (mall_models.Classification.id <<
                     self.corp.details.classification_ids)
                    | (mall_models.Classification.father_id <<
                       self.corp.details.classification_ids)))
        else:
            models = list(mall_models.Classification.select().dj_where(
                status=mall_models.CLASSIFICATION_ONLINE))
        children = []
        child_ids = set()

        models.sort(lambda x, y: cmp(x.father_id, y.father_id))
        if father_id == 0:
            return [ProductClassification(model) for model in models]

        for model in models:
            if (model.father_id in child_ids):
                children.append(ProductClassification(model))
                child_ids.add(model.id)

            if model.id == father_id:
                child_ids.add(model.id)
                if with_father:
                    children.append(ProductClassification(model))

        return children
Ejemplo n.º 2
0
    def get_child_product_classifications(self, father_id):
        """
		获得子分类,不包含子分类的子分类
		"""
        father_id = int(father_id)
        models = mall_models.Classification.select().dj_where(
            father_id=father_id, status=mall_models.CLASSIFICATION_ONLINE)

        return [ProductClassification(model) for model in models]
Ejemplo n.º 3
0
    def put(args):
        name = args['name']
        father_id = args['father_id']
        note = args.get('note', '')

        product_classification = ProductClassification.create({
            'corp':
            args['corp'],
            'name':
            name,
            'father_id':
            father_id,
            'note':
            note
        })

        return {'id': product_classification.id}
Ejemplo n.º 4
0
    def get_product_classifications(self):
        """
		获得所有子分类集合(包括子级和子级的子级)
		如果是供货商,则获取帐号配置中的分类
		"""
        if self.corp.is_supplier():
            models = mall_models.Classification.select().dj_where(
                status=mall_models.CLASSIFICATION_ONLINE,
                id__in=self.corp.details.classification_ids)
            children = []
            for father in models:
                children += self.get_children_product_classifications(
                    father.id)
            return children
        else:
            models = mall_models.Classification.select().dj_where(
                status=mall_models.CLASSIFICATION_ONLINE).order_by(
                    -mall_models.Classification.created_at)
            return [ProductClassification(model) for model in models]
Ejemplo n.º 5
0
    def get_product_classification_tree_by_end(self, end_id):
        """
		获得以end_id为终结节点的classification路径的集合
		"""
        classification_id = end_id

        classifications = []
        while True:
            if classification_id == 0:
                break

            model = mall_models.Classification.select().dj_where(
                id=classification_id).get()
            classifications.append(ProductClassification(model))

            classification_id = model.father_id

        classifications.reverse()
        return classifications
Ejemplo n.º 6
0
 def get_classification_by_product_ids(self, product_ids):
     models = mall_models.ClassificationHasProduct.select().dj_where(
         product_id__in=product_ids)
     return [
         ProductClassification(model.classification) for model in models
     ]
Ejemplo n.º 7
0
 def get_classification_by_product_id(self, product_id):
     model = mall_models.ClassificationHasProduct.select().dj_where(
         product_id=product_id).first()
     return ProductClassification(model.classification)
Ejemplo n.º 8
0
 def get_product_classification_by_ids(self, classification_ids):
     models = mall_models.Classification.select().dj_where(
         id__in=classification_ids)
     return [ProductClassification(model) for model in models]
Ejemplo n.º 9
0
 def get_product_classification(self, id):
     model = mall_models.Classification.select().dj_where(id=id).get()
     return ProductClassification(model)
Ejemplo n.º 10
0
 def get_root_product_classifications(self):
     models = mall_models.Classification.select().dj_where(
         status=mall_models.CLASSIFICATION_ONLINE, father_id=0)
     return [ProductClassification(model) for model in models]