示例#1
0
'discount_product_banner/q4m8wddfe7tvivn0zyp9ep2h2ea4lzy7tjgtk3vtmrwzy1ftkq.jpg',
'discount_product_banner/r0diavzk0vsbu2v6rn1hpz13z672yr2hcoip8rmrva8jn84ode.jpg',

]

models.ShopsToUsers.objects.create(shop=s, user=u, confirmed=True)

categs = models.ProductType.objects.filter(level=1)
for categ in categs:
    pt = models.ProductType.objects.filter(has_childs=False).filter(Q(parent=categ) | Q(parent__parent=categ) | Q(parent__parent__parent=categ)).earliest('created')

    random.shuffle(product_images)
    for image in product_images:
        product = Product.objects.create(title='Рекламная акция Татамо', body='Рекламная акция Татамо',
                                         normal_price=100, stock_price=1,
                                             start_date=models.get_today(),
                                             end_date=models.get_today() + timezone.timedelta(days=365),
                                             code='12345', product_type=pt,
                                            shop=s,
                                            user=u,
                                            ad=True,
                                            brand=b,
                                         status=models.STATUS_PROJECT,
                                         compound=''
                                             )
        models.ProductImage.objects.create(
            product=product,
            image=image,
            weight=1,
                                           )
for banner in banners:
示例#2
0
    def create_single_product(self, line, line_number):
        errors = []
        try:
            line = line.decode()
            print(line)
            line_as_list = line.split(';')
            line_as_list = [elem.strip() for elem in line_as_list]

            try:
                normal_price = int(line_as_list[0])
            except:
                if line_number <= 2:
                    return
                else:
                    errors.append('Цена не указана')
                    normal_price = 100000

            try:
                stock_price = int(line_as_list[1])
            except:
                errors.append('Цена по акции не указана')
                stock_price = 1

            product_type = line_as_list[2]

            try:
                start_date = datetime.strptime(line_as_list[3], '%d.%m.%Y')
            except:
                errors.append('Дата начала акции не указана')
                start_date = max(settings.START_DATE, models.get_today())


            try:
                end_date = datetime.strptime(line_as_list[4], '%d.%m.%Y')
            except:
                errors.append('Дата окончания акции не указана')
                end_date = max(settings.START_DATE, models.get_today())

            brand = line_as_list[5]
            title = line_as_list[6]
            body = line_as_list[7]
            product_shop_code = line_as_list[8]
            compound = line_as_list[9]
            link = line_as_list[10]
            colors = line_as_list[11]
            sizes = line_as_list[12]
            images = line_as_list[13]


            #code = models.Product.generate_unique_code()
            try:
                brand = models.Brand.objects.get(title__iexact=brand)
            except:
                errors.append('Бренд не найден')
                brand = models.Brand.objects.get(title='Татамо')

            if not self.shop:
                shop = line_as_list[14]
                try:
                    shop = models.Shop.objects.get(title__iexact=shop)
                except:
                    errors.append('Магазин не найден')
                    shop = models.Shop.objects.get(title='Татамо')
            else:
                shop = self.shop


            #try:
            #    category = models.ProductType.objects.get(title=category)
            #except:
            #    raise Exception('Категория не найдена')

            try:
                product_type = models.ProductType.objects.get(pk=product_type)
                    #Q(parent=category) |
                    #Q(parent__parent=category) |
                    #Q(parent__parent__parent=category)).filter(
                    #has_childs=False, title=product_type
                #)
            except:
                errors.append('Тип товара не найден')
                product_type = models.ProductType.objects.filter(has_childs=False, filtervaluetoproducttype=None).latest('created')

            try:
                product = models.Product.objects.create(title=title,
                                                    body=body,
                                                    normal_price=normal_price,
                                                    stock_price=stock_price,
                                                    start_date=start_date,
                                                    end_date=end_date,
                                                    #code=code,
                                                    product_type=product_type,
                                                    shop=shop,
                                                    user=self.user,
                                                    ad=False,
                                                    brand=brand,
                                                    status=models.STATUS_PROJECT,
                                                    compound=compound,
                                                    product_shop_code=product_shop_code,
                                                    link=link,

                                                 )
            except models.ValidationError as e:
                errors.append(str(e))
                product = models.Product.objects.filter(shop=models.Shop.objects.get(title='Татамо'))


            top_parent = product_type.get_top_parent()

            try:
                fvtpt = models.FilterValueToProductType.objects.get(filter_type=models.FILTER_TYPE_COLOR, product_type=top_parent)

            except:
                fvtpt = None

            if fvtpt:
                color_names = colors.split(',')
                color_names = [elem.strip().lower() for elem in color_names if elem.strip()]
                for color_name in color_names:
                    try:
                        color = models.FilterValue.objects.get(title__iexact=color_name)
                        product.filter_values.add(color)
                    except:
                        errors.append('Цвет {0} не найден'.format(color_name))

            try:

                fvtpt = models.FilterValueToProductType.objects.get(~Q(filter_type=models.FILTER_TYPE_COLOR), product_type=top_parent)
                size_param = fvtpt.filter_type
            except:
                size_param = None


            if size_param:
                size_names = sizes.split(',')
                size_names = [elem.strip() for elem in size_names if elem.strip()]
                for size_name in size_names:
                    try:
                        size = models.FilterValue.objects.get(title=size_name, filter_type=size_param)
                        product.filter_values.add(size)
                    except:
                        errors.append('Размер {0} не найден'.format(size_name))

            images = images.split(',')
            images = [elem.strip() for elem in images if elem.strip()]

            weight = 0
            try:
                for image in images:
                    weight += 1
                    image_name = self.save_image(image, line_number)
                    if image_name:
                        models.ProductImage.objects.create(
                            product=product,
                            image=image_name,
                            weight=weight,
                                                       )
            except:
                #self.delete_images(product)
                errors.append('Ошибка при загрузке изображений')


        except:
            errors.append('Непредвиденная ошибка')
        if errors:
            print(errors)
            self.errors[line_number] += errors
        else:
            self.products[line_number] = product
示例#3
0
models.ShopsToUsers.objects.create(shop=s, user=u, confirmed=True)

categs = models.ProductType.objects.filter(level=1)
for categ in categs:
    pt = models.ProductType.objects.filter(has_childs=False).filter(
        Q(parent=categ) | Q(parent__parent=categ)
        | Q(parent__parent__parent=categ)).earliest('created')

    random.shuffle(product_images)
    for image in product_images:
        product = Product.objects.create(title='Рекламная акция Татамо',
                                         body='Рекламная акция Татамо',
                                         normal_price=100,
                                         stock_price=1,
                                         start_date=models.get_today(),
                                         end_date=models.get_today() +
                                         timezone.timedelta(days=365),
                                         code='12345',
                                         product_type=pt,
                                         shop=s,
                                         user=u,
                                         ad=True,
                                         brand=b,
                                         status=models.STATUS_PROJECT,
                                         compound='')
        models.ProductImage.objects.create(
            product=product,
            image=image,
            weight=1,
        )
示例#4
0
    def create_single_product(self, line, line_number):
        errors = []
        try:
            line = line.decode()
            print(line)
            line_as_list = line.split(';')
            line_as_list = [elem.strip() for elem in line_as_list]

            try:
                normal_price = int(line_as_list[0])
            except:
                if line_number <= 2:
                    return
                else:
                    errors.append('Цена не указана')
                    normal_price = 100000

            try:
                stock_price = int(line_as_list[1])
            except:
                errors.append('Цена по акции не указана')
                stock_price = 1

            product_type = line_as_list[2]

            try:
                start_date = datetime.strptime(line_as_list[3], '%d.%m.%Y')
            except:
                errors.append('Дата начала акции не указана')
                start_date = max(settings.START_DATE, models.get_today())

            try:
                end_date = datetime.strptime(line_as_list[4], '%d.%m.%Y')
            except:
                errors.append('Дата окончания акции не указана')
                end_date = max(settings.START_DATE, models.get_today())

            brand = line_as_list[5]
            title = line_as_list[6]
            body = line_as_list[7]
            product_shop_code = line_as_list[8]
            compound = line_as_list[9]
            link = line_as_list[10]
            colors = line_as_list[11]
            sizes = line_as_list[12]
            images = line_as_list[13]

            #code = models.Product.generate_unique_code()
            try:
                brand = models.Brand.objects.get(title__iexact=brand)
            except:
                errors.append('Бренд не найден')
                brand = models.Brand.objects.get(title='Татамо')

            if not self.shop:
                shop = line_as_list[14]
                try:
                    shop = models.Shop.objects.get(title__iexact=shop)
                except:
                    errors.append('Магазин не найден')
                    shop = models.Shop.objects.get(title='Татамо')
            else:
                shop = self.shop

            #try:
            #    category = models.ProductType.objects.get(title=category)
            #except:
            #    raise Exception('Категория не найдена')

            try:
                product_type = models.ProductType.objects.get(pk=product_type)
                #Q(parent=category) |
                #Q(parent__parent=category) |
                #Q(parent__parent__parent=category)).filter(
                #has_childs=False, title=product_type
                #)
            except:
                errors.append('Тип товара не найден')
                product_type = models.ProductType.objects.filter(
                    has_childs=False,
                    filtervaluetoproducttype=None).latest('created')

            try:
                product = models.Product.objects.create(
                    title=title,
                    body=body,
                    normal_price=normal_price,
                    stock_price=stock_price,
                    start_date=start_date,
                    end_date=end_date,
                    #code=code,
                    product_type=product_type,
                    shop=shop,
                    user=self.user,
                    ad=False,
                    brand=brand,
                    status=models.STATUS_PROJECT,
                    compound=compound,
                    product_shop_code=product_shop_code,
                    link=link,
                )
            except models.ValidationError as e:
                errors.append(str(e))
                product = models.Product.objects.filter(
                    shop=models.Shop.objects.get(title='Татамо'))

            top_parent = product_type.get_top_parent()

            try:
                fvtpt = models.FilterValueToProductType.objects.get(
                    filter_type=models.FILTER_TYPE_COLOR,
                    product_type=top_parent)

            except:
                fvtpt = None

            if fvtpt:
                color_names = colors.split(',')
                color_names = [
                    elem.strip().lower() for elem in color_names
                    if elem.strip()
                ]
                for color_name in color_names:
                    try:
                        color = models.FilterValue.objects.get(
                            title__iexact=color_name)
                        product.filter_values.add(color)
                    except:
                        errors.append('Цвет {0} не найден'.format(color_name))

            try:

                fvtpt = models.FilterValueToProductType.objects.get(
                    ~Q(filter_type=models.FILTER_TYPE_COLOR),
                    product_type=top_parent)
                size_param = fvtpt.filter_type
            except:
                size_param = None

            if size_param:
                size_names = sizes.split(',')
                size_names = [
                    elem.strip() for elem in size_names if elem.strip()
                ]
                for size_name in size_names:
                    try:
                        size = models.FilterValue.objects.get(
                            title=size_name, filter_type=size_param)
                        product.filter_values.add(size)
                    except:
                        errors.append('Размер {0} не найден'.format(size_name))

            images = images.split(',')
            images = [elem.strip() for elem in images if elem.strip()]

            weight = 0
            try:
                for image in images:
                    weight += 1
                    image_name = self.save_image(image, line_number)
                    if image_name:
                        models.ProductImage.objects.create(
                            product=product,
                            image=image_name,
                            weight=weight,
                        )
            except:
                #self.delete_images(product)
                errors.append('Ошибка при загрузке изображений')

        except:
            errors.append('Непредвиденная ошибка')
        if errors:
            print(errors)
            self.errors[line_number] += errors
        else:
            self.products[line_number] = product