def test_updating_subtree_slugs_when_moving_category_to_new_parent(self): trail = 'A > B > C' create_from_breadcrumbs(trail) trail = 'A > B > D' create_from_breadcrumbs(trail) trail = 'A > E > F' create_from_breadcrumbs(trail) trail = 'A > E > G' create_from_breadcrumbs(trail) trail = 'T' target = create_from_breadcrumbs(trail) category = Category.objects.get(name='A') category.move(target, pos='first-child') c1 = Category.objects.get(name='A') self.assertEqual(c1.full_slug, 't/a') self.assertEqual(c1.full_name, 'T > A') child = Category.objects.get(name='F') self.assertEqual(child.full_slug, 't/a/e/f') self.assertEqual(child.full_name, 'T > A > E > F') child = Category.objects.get(name='D') self.assertEqual(child.full_slug, 't/a/b/d') self.assertEqual(child.full_name, 'T > A > B > D')
def setUp(self): breadcrumbs = ( 'Books > Fiction > Horror > Teen', 'Books > Fiction > Horror > Gothic', 'Books > Fiction > Comedy', 'Books > Non-fiction > Biography', 'Books > Non-fiction > Programming', 'Books > Children', ) for trail in breadcrumbs: create_from_breadcrumbs(trail)
def test_can_create_multiple_categories(self): trail = 'Books > Science-Fiction > Star Trek' create_from_breadcrumbs(trail) trail = 'Books > Factual > Popular Science' category = create_from_breadcrumbs(trail) self.assertIsNotNone(category) self.assertEqual(category.name, 'Popular Science') self.assertEqual(category.get_depth(), 3) self.assertEqual(category.get_parent().name, 'Factual') self.assertEqual(5, Category.objects.count()) self.assertEqual(category.full_slug, 'books/factual/popular-science', )
def create_product(self, product_class, attribute_codes, row): ptype, upc, title, description, category, partner, sku, price, stock = row[0:9] # Create product is_variant = ptype.lower() == 'variant' is_group = ptype.lower() == 'group' if upc: try: product = Product.objects.get(upc=upc) except Product.DoesNotExist: product = Product(upc=upc) else: product = Product() if not is_variant: product.title = title product.description = description product.product_class = product_class # Attributes if not is_group: for code, value in zip(attribute_codes, row[9:]): # Need to check if the attribute requires an Option instance attr = product_class.attributes.get( code=code) if attr.is_option: value = attr.option_group.options.get(option=value) if attr.type == 'date': value = datetime.strptime(value, "%d/%m/%Y").date() setattr(product.attr, code, value) # Assign parent for variants if is_variant: product.parent = self.parent product.save() # Save a reference to last group product if is_group: self.parent = product # Category information if category: leaf = create_from_breadcrumbs(category) ProductCategory.objects.get_or_create( product=product, category=leaf) # Stock record if partner: partner, __ = Partner.objects.get_or_create(name=partner) try: record = StockRecord.objects.get(product=product) except StockRecord.DoesNotExist: record = StockRecord(product=product) record.partner = partner record.partner_sku = sku record.price_excl_tax = D(price) if stock != 'NULL': record.num_in_stock = stock record.save()
def create_product(self, product_class, attribute_codes, row): category, upc, title, description, price = row[0:5] # Create product if upc: try: product = models.Product.objects.get( upc=upc) except models.Product.DoesNotExist: product = models.Product(upc=upc) else: product = models.Product() product.title = title product.description = description product.product_class = product_class product.price = D(price) # Attributes for code, value in zip(attribute_codes, row[5:]): setattr(product.attr, code, value) product.save() # Category information if category: leaf = categories.create_from_breadcrumbs(category) models.ProductCategory.objects.get_or_create( product=product, category=leaf)
def _create_item(self, product_class, category_str, upc, title, description, stats): # Ignore any entries that are NULL if description == 'NULL': description = '' # Create item class and item product_class, __ \ = ProductClass.objects.get_or_create(name=product_class) try: item = Product.objects.get(upc=upc) stats['updated_items'] += 1 except Product.DoesNotExist: item = Product() stats['new_items'] += 1 item.upc = upc item.title = title item.description = description item.product_class = product_class item.save() # Category cat = create_from_breadcrumbs(category_str) ProductCategory.objects.create(product=item, category=cat) return item
def add_category_from_breadcrumbs(self, breadcrumb): from oscar.apps.catalogue.categories import create_from_breadcrumbs category = create_from_breadcrumbs(breadcrumb) temp = get_model('catalogue', 'ProductCategory')( category=category, product=self) temp.save()
def save(self, *args, **kwargs): super(Partner, self).save(*args, **kwargs) newCategory = create_from_breadcrumbs(self.name) newCategory.partner = self newCategory.save()
def create_test_category_tree(): trail = 'A > B > C' create_from_breadcrumbs(trail) trail = 'A > B > D' create_from_breadcrumbs(trail) trail = 'A > E > F' create_from_breadcrumbs(trail) trail = 'A > E > G' create_from_breadcrumbs(trail)
def assign_categories(product, category_list): results = [] for category_name in category_list: print "Assigning category: %s." % category_name leaf = create_from_breadcrumbs(category_name) results.append(ProductCategory.objects.get_or_create(product=product, category=leaf)) return results
def setUp(self): breadcrumbs = ( 'Books > Fiction > Horror > Teen', 'Books > Fiction > Horror > Gothic', 'Books > Fiction > Comedy', 'Books > Non-fiction > Biography', 'Books > Non-fiction > Programming', 'Books > Children', ) for trail in breadcrumbs: create_from_breadcrumbs(trail) horror = Category.objects.get(name="Horror") programming = Category.objects.get(name="Programming") horror.move(programming) # Reload horror instance to pick up changes self.horror = Category.objects.get(name="Horror")
def test_can_create_parent_and_child_categories(self): trail = 'Books > Science-Fiction' category = create_from_breadcrumbs(trail) self.assertIsNotNone(category) self.assertEqual(category.name, 'Science-Fiction') self.assertEqual(category.get_depth(), 2) self.assertEqual(category.get_parent().name, 'Books') self.assertEqual(2, Category.objects.count()) self.assertEqual(category.full_slug, 'books/science-fiction')
def test_can_create_parent_and_child_categories(self): trail = 'Books > Science-Fiction' category = create_from_breadcrumbs(trail) self.assertIsNotNone(category) self.assertEqual(category.name, 'Science-Fiction') self.assertEqual(category.get_depth(), 2) self.assertEqual(category.get_parent().name, 'Books') self.assertEqual(2, models.Category.objects.count()) self.assertEqual(category.slug, 'books/science-fiction')
def update_categories(product_folder_syncs): for pf_sync in product_folder_syncs: category = pf_sync.category if pf_sync.category else create_from_breadcrumbs( pf_sync.path_name_changed, '${/}') # rename if category.name != pf_sync.name: category.name = pf_sync.name category.slug = category.generate_slug() # archived category.archived = pf_sync.archived category.save() if pf_sync.category is None: pf_sync.category = category pf_sync.save() # move ancestors = list(category.get_ancestors()) old_path = ancestors[-1].full_name.replace(' > ', '/') if ancestors else '' if pf_sync.path_name != old_path: if pf_sync.path_name == '': root = Category.objects.filter(depth=1).first() if root: category.move(root) else: print('Can`t find root category') else: parent_category = pf_sync.parent_product_folder_sync.category category.move(parent_category, 'last-child') # delete for category in ProductFolderSync.objects.all(): if category not in product_folder_syncs: try: category.category.delete() except AttributeError: pass category.delete() ProductFolderSync.objects.bulk_update(product_folder_syncs)
def test_updating_subtree_when_moving_category_to_new_sibling(self): trail = 'A > B > C' create_from_breadcrumbs(trail) trail = 'A > B > D' create_from_breadcrumbs(trail) trail = 'A > E > F' create_from_breadcrumbs(trail) trail = 'A > E > G' create_from_breadcrumbs(trail) category = Category.objects.get(name='E') target = Category.objects.get(name='A') category.move(target, pos='right') child = Category.objects.get(name='E') self.assertEqual(child.full_slug, 'e') self.assertEqual(child.full_name, 'E') child = Category.objects.get(name='F') self.assertEqual(child.full_slug, 'e/f') self.assertEqual(child.full_name, 'E > F')
def crear_categoria(self, breadcrumb, comp_img=None): path = self.cat_base + ' > '.join(breadcrumb[1:]) try: cat = create_from_breadcrumbs(path) logging.info("Created Category: %s", cat) except IntegrityError: logging.error("Offending category: %s", path) raise if comp_img: try: url = os.path.join(settings.SCRAPPER_ROOT, comp_img) result = urllib.urlretrieve(url) cat.diagram_image.save(comp_img, File(open(result[0]))) cat.save() logging.info("Saved diagram_image from %s", url) except Exception as e: print(e) return cat
def _get_or_create_categories(self, root_category, categories_list): breadcrumbs = '{} > {}'.format(root_category, categories_list) created_breadcrumbs = create_from_breadcrumbs(breadcrumbs) ''' if isinstance(categories_list, type(None)): categories_list = [] else: categories = Category.objects.filter( name__in=categories_list) if not categories: categories = [ Category.add_root(name=category.strip()) for category in categories_list ] return categories return [ Category.objects.get(name=name) for name in [root_category, categories_list] ] ''' return created_breadcrumbs
def handle(self, *args, **options): ''' Veel van onderstaande functionaliteit is gebaseerd op de CatalogueImporter klasse uit de django oscar Partner applicatie. Zie de importers.py file voor meer informatie ''' help = 'automatiseer de aanmaak van de product catalogus (voor onderdelen!)' with urlopen(DS_FILE) as file: csv_file = file.read() reader = csv.reader(csv_file.decode('utf-8').splitlines(), delimiter=';') product_class = ProductClass.objects.get(name='Onderdelen') for row in reader: upc = str(row[4]) if upc != '': alternate_id = upc price_purchase = 0 price_in_table = row[6] price_adjusted = price_in_table.replace(',', '.') price_inc = Decimal(price_adjusted) price_excl = price_inc / Decimal('1.21') price_sell = round(price_excl, 2) try: product = Product.objects.get(upc=upc) except Product.DoesNotExist: self.stdout.write('Bestaat niet ... ') continue if product: add_partner_information(product=product, partner_code=alternate_id, price_purchase=price_purchase, price_sell=price_sell) self.stdout.write('--Het is gefixt!--') with urlopen(PRODUCTS_FILE) as file: csv_file = file.read() reader = csv.reader(csv_file.decode('utf-8').splitlines(), delimiter=';') product_class = ProductClass.objects.get(name='Onderdelen') print('HHHHHHHHHHH') for row in reader: '''STAPPENPLAN: 1. Analyseer Product code (UPC), derde rij 2. Maak product category aan als nog niet bestaat 3. Maak product aan 4. Voeg afbeelding toe aan product 5. Voeg de nodige prijsinformatie toe ''' upc = str(row[2]) alternate_id = str(row[1]) price_purchase = row[4] price_sell = row[5] #print('---- prijs %s' % price_sell) if upc != '': if len(upc) == 6: car_type_id = upc[:1] category_id = upc[1:3] product_id = upc[-3:] if car_type_id == '2': main_cat = '2CV Onderdelen' if category_id == '11': cat_breadcrumb = 'Chassis' elif category_id == '12': cat_breadcrumb = 'Sierstrips' elif category_id == '13': cat_breadcrumb = 'Bumpers' elif category_id == '14': cat_breadcrumb = 'Voorvleugel' elif category_id == '15': cat_breadcrumb = 'Motorkap' elif category_id == '16': cat_breadcrumb = 'Deuren' elif category_id == '17': cat_breadcrumb = 'Dak' elif category_id == '18': cat_breadcrumb = 'Achtervleugel' elif category_id == '19': cat_breadcrumb = 'Kofferklep' elif category_id == '21': cat_breadcrumb = 'Ruiten' elif category_id == '22': cat_breadcrumb = 'Uitlaat' elif category_id == '23': cat_breadcrumb = 'Elektriciteit & Ontsteking' elif category_id == '24': cat_breadcrumb = 'Verlichting' elif category_id == '25': cat_breadcrumb = 'Motor' elif category_id == '26': cat_breadcrumb = 'Benzinesysteem' elif category_id == '27': cat_breadcrumb = 'Koeling & Verwarming' elif category_id == '28': cat_breadcrumb = 'Remmen' elif category_id == '30': cat_breadcrumb = 'Leidingen' elif category_id == '31': cat_breadcrumb = 'Koppeling' elif category_id == '32': cat_breadcrumb = 'Interieur' elif category_id == '33': cat_breadcrumb = 'Allerlei' elif category_id == '35': cat_breadcrumb = 'Stuurinrichting' elif category_id == '36': cat_breadcrumb = 'Aandrijving & Ophanging' elif category_id == '37': cat_breadcrumb = 'Accesoires' elif category_id == '38': cat_breadcrumb = 'Sloten' elif category_id == '39': cat_breadcrumb = 'Plaatwerk' elif category_id == '40': cat_breadcrumb = 'Banden' else: continue else: continue cat_string = main_cat + '>' + cat_breadcrumb category = create_from_breadcrumbs(cat_string) try: product = Product.objects.get(upc=upc) except Product.DoesNotExist: self.stdout.write( '*** creating product starts here') product = Product() product.title = row[0] product.upc = upc product.product_class = product_class product.save() # Link het product aan een ProductCategory ProductCategory.objects.update_or_create( product=product, category=category) finally: #self.stdout.write('*** Adding image to product starts here') if product: #add_image_to_product(product, main_cat, alternate_id) add_partner_information( product=product, partner_code=alternate_id, price_purchase=price_purchase, price_sell=price_sell) else: continue self.stdout.write('--Het is gefixt!--')
def setUp(self): super(CouponMixin, self).setUp() self.category = create_from_breadcrumbs('Coupons > Test category')
def setUp(self): self.staff = G(User, is_staff=True) create_from_breadcrumbs('A > B > C')
def create_edx_employee_category(apps, schema_editor): """Create edX employee coupon category.""" Category.skip_history_when_saving = True create_from_breadcrumbs('{} > {}'.format(COUPON_CATEGORY_NAME, EDX_EMPLOYEE_COUPON_CATEGORY))
def handle(self, *args, **options): help = 'automatiseer de aanmaak van de product catalogus' #FILE_PATH = os.path.join(settings.MEDIA_ROOT, 'product_list') # live FILE_PATH = settings.MEDIA_ROOT # development FILE = os.path.join(FILE_PATH, 'DS_Onderdelen.csv') PRODUCTS_FILE = 'http://s3.eu-central-1.amazonaws.com/dsshop/media/DS_Onderdelen.csv' #if settings.DEV == True: # PRODUCTS_FILE = 'file://' + settings.MEDIA_ROOT + '/DS_Onderdelen.csv' #with open(PRODUCTS_FILE) as file: with urlopen(PRODUCTS_FILE) as file: csv_file = file.read() #reader = csv.reader(csv_file, delimiter=';') reader = csv.reader(csv_file.decode('utf-8').splitlines(), delimiter=';') cat_string = '' product_class = ProductClass.objects.get(name='Onderdelen') for row in reader: ''' Stappenplan: 1. Check 5de rij (= UPC): mag niet leeg zijn 2. Check 2de rij: ? 'Category' 3. Maak product aan ''' # Stap 1: Check 2de rij op de naam 'CATEGORY' if row[1] == 'CATEGORY': cat_string = create_from_breadcrumbs(row[0]) print('category: %s' % row[1]) # Stap 2: Als geen categorie, dan proberen we product aan te maken else: if row[4] in (None, ''): print('deze rij (%s) heeft geen UPC -> ignore!' % reader.line_num) else: # Dit is een product! print('product: %s -- %s' % (row[0], row[4])) title = row[0] upc = row[4] alternate_id = '' price_purchase = 0 price_in_table = row[6] price_adjusted = price_in_table.replace(',', '.') price_inc = Decimal(price_adjusted) price_excl = price_inc / Decimal('1.21') price_sell = round(price_excl, 2) try: item = Product.objects.get(upc=upc) except Product.DoesNotExist: print('maak product aan') # Maak product aan item = Product() item.title = title item.upc = upc item.product_class = product_class item.save() # Voeg categorie toe ProductCategory.objects.update_or_create( product=item, category=cat_string) finally: if item: add_partner_information( product=item, partner_code=alternate_id, price_purchase=price_purchase, price_sell=price_sell) self.stdout.write('--Het is gefixt!--')
def create_on_campus_category(apps, schema_editor): """ Create on-campus coupon category """ Category.skip_history_when_saving = True create_from_breadcrumbs('{} > {}'.format(COUPON_CATEGORY_NAME, ON_CAMPUS_CATEGORY))
def test_can_create_single_level_category(self): trail = 'Books' category = create_from_breadcrumbs(trail) self.assertIsNotNone(category) self.assertEqual(category.name, 'Books') self.assertEqual(category.slug, 'books')
def setUp(self): self.staff = UserFactory(is_staff=True) create_from_breadcrumbs('A > B > C')
def _create_item(self, row, product_class_name, brand, country_manufactur, category_str, upc, title, description, images_urls, price, attr_list, stats): # Ignore any entries that are NULL if description == 'NULL': description = '' # Create item class and item # product_class, __ = ProductClass.objects.get_or_create(name=product_class_name, track_stock=False) klass, __ = ProductClass.objects.get_or_create(name=product_class_name, track_stock=False) # from Solr search, schema.xml # <dynamicField name="*_i" type="int" indexed="true" stored="true"/> # <dynamicField name="*_s" type="string" indexed="true" stored="true"/> # <dynamicField name="*_l" type="long" indexed="true" stored="true"/> # <dynamicField name="*_t" type="text_en" indexed="true" stored="true"/> # <dynamicField name="*_b" type="boolean" indexed="true" stored="true"/> # <dynamicField name="*_f" type="float" indexed="true" stored="true"/> # <dynamicField name="*_d" type="double" indexed="true" stored="true"/> # <dynamicField name="*_dt" type="date" indexed="true" stored="true"/> # <dynamicField name="*_p" type="location" indexed="true" stored="true"/> # <dynamicField name="*_coordinate" type="tdouble" indexed="true" stored="false"/> ProductAttribute.objects.get_or_create( # create and/or get created class product_class=klass, name='Виробник', # text in admin required=False, code='brand_s', # name in DB (use bootom connemt sufix) type='text', # type ) ProductAttribute.objects.get_or_create( product_class=klass, name='Країна виробник', required=False, code='country_manufactur_s', type='text', ) # dymanic create attributes item = Product( product_class=klass, # inherit from class! title=title, upc=upc, description=description, ) # if not (price is None): # item.price = price item.price = price # Set attributes item.attr.brand_s = brand item.attr.country_manufactur_s = country_manufactur item.save() for el in attr_list: pass # Associate with a category cat = create_from_breadcrumbs(category_str) ProductCategory.objects.update_or_create(product=item, category=cat) # Set the price self._create_stockrecord(item, 'Склад по змовчуванню', upc, price) # use one stock how main for sales # region 'image' c = urllib3.PoolManager() if self._add_images: images = str(images_urls).split(',') for image in images: image_url = image.strip() if len(image_url) < 5: continue file_name = image.replace('https://images.ua.prom.st/', '').strip() fn = tempfile.gettempdir() + '\\' + file_name fn = fn.strip() download(c, image_url, fn) # fix #15, some files has png on jpeg file error content with Image.open(fn) as img: image_format = img.format # logger.info(img.format) # 'JPEG' if image_format == 'PNG': nfn = os.path.splitext(fn)[0] + '.jpg' s = '%s/%s/convert.exe "%s" -background white -flatten "%s"' % \ (SITE_ROOT, '_private/ImageMagic', fn, nfn) logger.info(s) res = run_win_cmd(s) logging.info(res) fn = nfn else: if not image_format == 'JPEG': logger.error('image_format=%s' % image_format) exit() new_file = File(open(fn, 'rb')) im = ProductImage(product=item) im.original.save(file_name, new_file, save=False) im.save() logger.debug('Image added to "%s"' % item) # endregion return item
def test_creating_category_root(self): trail = 'Books' category = create_from_breadcrumbs(trail) self.assertIsNotNone(category) self.assertEquals(category.name, 'Books') self.assertEquals(category.slug, 'books')
def create_product(self, product_class, attribute_codes, row): ptype, upc, title, description, category, partner, sku, price, stock = row[ 0:9] # Create product is_variant = ptype.lower() == 'variant' is_group = ptype.lower() == 'group' if upc: try: product = models.Product.objects.get(upc=upc) except models.Product.DoesNotExist: product = models.Product(upc=upc) else: product = models.Product() if not is_variant: product.title = title product.description = description product.product_class = product_class # Attributes if not is_group: for code, value in zip(attribute_codes, row[9:]): # Need to check if the attribute requires an Option instance attr = product_class.attributes.get(code=code) if attr.is_option: value = attr.option_group.options.get(option=value) if attr.type == 'date': value = datetime.datetime.strptime(value, "%d/%m/%Y").date() setattr(product.attr, code, value) # Assign parent for variants if is_variant: product.parent = self.parent product.save() # Save a reference to last group product if is_group: self.parent = product # Category information if category: leaf = categories.create_from_breadcrumbs(category) models.ProductCategory.objects.get_or_create(product=product, category=leaf) # Stock record if partner: partner, __ = partner_models.Partner.objects.get_or_create( name=partner) try: record = partner_models.StockRecord.objects.get( product=product) except partner_models.StockRecord.DoesNotExist: record = partner_models.StockRecord(product=product) record.partner = partner record.partner_sku = sku record.price_excl_tax = D(price) if stock != 'NULL': record.num_in_stock = stock record.save()
"Shoes > Women's Footwear > Shoes", "Shoes > Women's Footwear > Boots", "Shoes > Women's Footwear > Socks", # Kid's Shoes "Shoes > Kid's Footwear > Kid's Shoes", "Shoes > Kid's Footwear > Kid's Boots", "Shoes > Kid's Footwear > Kid's Socks", # Outdoor Gear #"Sports & Outdoors > Outdoor Gear > Camping & Hiking", #"Sports & Outdoors > Outdoor Gear > Hunting", #"Sports & Outdoors > Outdoor Gear > Climbing Gear", #"Sports & Outdoors > Outdoor Gear > Binoculars & Camera", # Sporting Goods #"Sports & Outdoors > Sporting Goods > Running & Fitness", #"Sports & Outdoors > Sporting Goods > Golf", #"Sports & Outdoors > Sporting Goods > Ski", #"Sports & Outdoors > Sporting Goods > Water Sports", #"Sports & Outdoors > Sporting Goods > Tennis", # Brands # "Brands > H.A.D.", # "Brands > Charko", # "Brands > Bourg-de-Peage", # "Brands > F-Lite", # "Brands > 8BPlus", # "Brands > Makak", ) for breadcrumbs in categories: create_from_breadcrumbs(breadcrumbs)
def setUp(self): super(CouponCategoriesListViewTests, self).setUp() self.user = self.create_user() self.client.login(username=self.user.username, password=self.password) Category.objects.all().delete() create_from_breadcrumbs('Coupons > Coupon test category')
def django_db_setup(django_db_setup, django_db_blocker, django_db_use_migrations): if django_db_use_migrations: return with django_db_blocker.unblock(): BasketAttributeType = get_model('basket', 'BasketAttributeType') Category = get_model("catalogue", "Category") ProductAttribute = get_model("catalogue", "ProductAttribute") ProductClass = get_model("catalogue", "ProductClass") Option = get_model("catalogue", "Option") EcommerceFeatureRole = get_model('core', 'EcommerceFeatureRole') Condition = get_model('offer', 'Condition') Benefit = get_model('offer', 'Benefit') ConditionalOffer = get_model('offer', 'ConditionalOffer') BasketAttributeType.objects.get_or_create(name=EMAIL_OPT_IN_ATTRIBUTE) BasketAttributeType.objects.get_or_create(name=PURCHASER_BEHALF_ATTRIBUTE) BasketAttributeType.objects.get_or_create(name=BUNDLE) for klass in (Category, ProductAttribute, ProductClass, Option): klass.skip_history_when_saving = True # Create a new product class for course seats seat, _ = ProductClass.objects.get_or_create( track_stock=False, requires_shipping=False, name=SEAT_PRODUCT_CLASS_NAME, slug=slugify(SEAT_PRODUCT_CLASS_NAME) ) # Create product attributes for course seat products ProductAttribute.objects.get_or_create( product_class=seat, name="course_key", code="course_key", type="text", required=True ) ProductAttribute.objects.get_or_create( product_class=seat, name="id_verification_required", code="id_verification_required", type="boolean", required=False ) ProductAttribute.objects.get_or_create( product_class=seat, name="certificate_type", code="certificate_type", type="text", required=False ) # Create a category for course seats Category.objects.get_or_create( description="All course seats", numchild=1, slug="seats", depth=1, path="0001", image="", name="Seats" ) ProductAttribute.objects.get_or_create( product_class=seat, name='credit_provider', code='credit_provider', type='text', required=False ) ProductAttribute.objects.get_or_create( product_class=seat, name='credit_hours', code='credit_hours', type='integer', required=False ) Option.objects.get_or_create( name='Course Entitlement', code='course_entitlement', type=Option.OPTIONAL, ) coupon, _ = ProductClass.objects.get_or_create( track_stock=False, requires_shipping=False, name=COUPON_PRODUCT_CLASS_NAME, slug=slugify(COUPON_PRODUCT_CLASS_NAME), ) ProductAttribute.objects.get_or_create( product_class=coupon, name='Coupon vouchers', code='coupon_vouchers', type='entity', required=False ) # Create a category for coupons. Category.objects.get_or_create( description='All Coupons', slug='coupons', depth=1, path='0002', image='', name='Coupons' ) ProductAttribute.objects.create( product_class=coupon, name='Note', code='note', type='text', required=False ) ProductAttribute.objects.create( product_class=coupon, name='Notification Email', code='notify_email', type='text', required=False ) ProductAttribute.objects.create( product_class=coupon, name='Enterprise Customer UUID', code='enterprise_customer_uuid', type='text', required=False ) ProductAttribute.objects.create( product_class=coupon, name='Enterprise Contract Metadata', code='enterprise_contract_metadata', type='entity', required=False ) ProductAttribute.objects.create( product_class=coupon, name='Inactive', code='inactive', type=ProductAttribute.BOOLEAN, required=False ) ProductAttribute.objects.create( product_class=coupon, name='Sales Force ID', code='sales_force_id', type='text', required=False ) ProductAttribute.objects.create( product_class=coupon, name='Is Public Code?', code='is_public_code', type='boolean', required=False ) # Create a new product class for course entitlement course_entitlement, _ = ProductClass.objects.get_or_create( track_stock=False, requires_shipping=False, name=COURSE_ENTITLEMENT_PRODUCT_CLASS_NAME, slug=slugify(COURSE_ENTITLEMENT_PRODUCT_CLASS_NAME) ) # Create product attributes for course entitlement products ProductAttribute.objects.get_or_create( product_class=course_entitlement, name="UUID", code="UUID", type="text", required=True ) ProductAttribute.objects.get_or_create( product_class=course_entitlement, name="certificate_type", code="certificate_type", type="text", required=False ) ProductAttribute.objects.get_or_create( product_class=course_entitlement, name='id_verification_required', code='id_verification_required', type='boolean', required=False ) try: Category.objects.get(name="Course Entitlements") except Category.DoesNotExist: # Create a category for course entitlements Category.add_root( description="All course entitlements", slug="course_entitlements", image="", name="Course Entitlements" ) enrollment_code, _ = ProductClass.objects.get_or_create( track_stock=False, requires_shipping=False, name=ENROLLMENT_CODE_PRODUCT_CLASS_NAME, slug=slugify(ENROLLMENT_CODE_PRODUCT_CLASS_NAME), ) ProductAttribute.objects.get_or_create( product_class=enrollment_code, name='Course Key', code='course_key', type='text', required=True ) ProductAttribute.objects.get_or_create( product_class=enrollment_code, name='Seat Type', code='seat_type', type='text', required=True ) ProductAttribute.objects.get_or_create( product_class=enrollment_code, name='id_verification_required', code='id_verification_required', type='boolean', required=False ) EcommerceFeatureRole.objects.get_or_create(name=ORDER_MANAGER_ROLE) new_dynamic_condition, _ = Condition.objects.get_or_create( proxy_class='ecommerce.extensions.offer.dynamic_conditional_offer.DynamicDiscountCondition' ) # The value doesn't matter, because it's dynamic, but oscar will complain without one. new_dynamic_benefit, _ = Benefit.objects.get_or_create( value=1, proxy_class='ecommerce.extensions.offer.dynamic_conditional_offer.DynamicPercentageDiscountBenefit' ) ConditionalOffer.objects.get_or_create( name='dynamic_conditional_offer', benefit=new_dynamic_benefit, condition=new_dynamic_condition, max_basket_applications=1, priority=-10 ) # Create a new product class for donations for the donations from checkout tests ProductClass.objects.get_or_create( track_stock=False, requires_shipping=False, name=DONATIONS_FROM_CHECKOUT_TESTS_PRODUCT_TYPE_NAME, slug=slugify(DONATIONS_FROM_CHECKOUT_TESTS_PRODUCT_TYPE_NAME) ) try: Category.objects.get(name="Donations") except Category.DoesNotExist: Category.add_root( description="All donations", slug="donations", image="", name="Donations" ) EcommerceFeatureRole.objects.get_or_create(name=ENTERPRISE_COUPON_ADMIN_ROLE) for category in DEFAULT_CATEGORIES: create_from_breadcrumbs('{} > {}'.format(COUPON_CATEGORY_NAME, category))
def create_on_campus_category(apps, schema_editor): """ Create on-campus coupon category """ create_from_breadcrumbs('{} > {}'.format(COUPON_CATEGORY_NAME, ON_CAMPUS_CATEGORY))
def create_new_categories(apps, schema_editor): """ Create new coupon categories """ Category.skip_history_when_saving = True for category in NEW_CATEGORIES: create_from_breadcrumbs('{} > {}'.format(COUPON_CATEGORY_NAME, category))
def test_can_use_alternative_separator(self): trail = 'Food|Cheese|Blue' create_from_breadcrumbs(trail, separator='|') self.assertEqual(3, len(Category.objects.all()))
def forwards_func(apps, schema_editor): categories = [ 'Haushalt, Garten, Tier & Baumarkt > Küchen- & Haushaltsgeräte', 'Haushalt, Garten, Tier & Baumarkt > Kochen & Essen', 'Haushalt, Garten, Tier & Baumarkt > Aufbewahren & Ordnen', 'Haushalt, Garten, Tier & Baumarkt > Möbel & Wohnaccessoires', 'Haushalt, Garten, Tier & Baumarkt > Heimtextilien', 'Haushalt, Garten, Tier & Baumarkt > Beleuchtung', 'Haushalt, Garten, Tier & Baumarkt > Sonstige', 'Blumen', 'Beauty & Drogerie & Lebensmittel > Damen', 'Beauty & Drogerie & Lebensmittel > Herren', 'Beauty & Drogerie & Lebensmittel > Baby', 'Beauty & Drogerie & Lebensmittel > Sonstige', 'Beauty & Drogerie & Lebensmittel > Lebensmittel', 'Kleidung, Schuhe, Schmuck > Damen > Bekleidung > Accessoires', 'Kleidung, Schuhe, Schmuck > Damen > Bekleidung > Tops, T-Shirts & Blusen', 'Kleidung, Schuhe, Schmuck > Damen > Bekleidung > Kleider', 'Kleidung, Schuhe, Schmuck > Damen > Bekleidung > Streetwear', 'Kleidung, Schuhe, Schmuck > Damen > Bekleidung > Bademode', 'Kleidung, Schuhe, Schmuck > Damen > Bekleidung > Jacken, Mäntel & Westen', 'Kleidung, Schuhe, Schmuck > Damen > Bekleidung > Sportbekleidung', 'Kleidung, Schuhe, Schmuck > Damen > Bekleidung > Socken & Strümpfe', 'Kleidung, Schuhe, Schmuck > Damen > Bekleidung > Unterwäsche', 'Kleidung, Schuhe, Schmuck > Damen > Bekleidung > Pullover & Strickjacken', 'Kleidung, Schuhe, Schmuck > Damen > Schuhe > Sneaker & Sportschuhe', 'Kleidung, Schuhe, Schmuck > Damen > Schuhe > Stiefel', 'Kleidung, Schuhe, Schmuck > Damen > Schuhe > Sandalen & Slides', 'Kleidung, Schuhe, Schmuck > Damen > Schuhe > Flache Schuhe', 'Kleidung, Schuhe, Schmuck > Damen > Schuhe > Hausschuhe', 'Kleidung, Schuhe, Schmuck > Damen > Schuhe > Pumps', 'Kleidung, Schuhe, Schmuck > Damen > Schuhe > Arbeits- & Berufsschuhe', 'Kleidung, Schuhe, Schmuck > Damen > Taschen > Zubehör', 'Kleidung, Schuhe, Schmuck > Damen > Taschen > Umhängetaschen', 'Kleidung, Schuhe, Schmuck > Damen > Taschen > Clutches', 'Kleidung, Schuhe, Schmuck > Damen > Taschen > Handtaschen & Schultertaschen', 'Kleidung, Schuhe, Schmuck > Damen > Taschen > Henkeltaschen', 'Kleidung, Schuhe, Schmuck > Damen > Taschen > Rucksäcke', 'Kleidung, Schuhe, Schmuck > Damen > Taschen > Schultaschen, Federmäppchen', 'Kleidung, Schuhe, Schmuck > Damen > Taschen > Sporttaschen', 'Kleidung, Schuhe, Schmuck > Damen > Taschen > Einkaufskörbe & -taschen', 'Kleidung, Schuhe, Schmuck > Damen > Taschen > Business- & Laptop-Taschen', 'Kleidung, Schuhe, Schmuck > Damen > Uhren', 'Kleidung, Schuhe, Schmuck > Damen > Schmuck', 'Kleidung, Schuhe, Schmuck > Damen > Gepäck > Koffer', 'Kleidung, Schuhe, Schmuck > Damen > Gepäck > Reisetaschen', 'Kleidung, Schuhe, Schmuck > Damen > Gepäck > Zubehör', 'Kleidung, Schuhe, Schmuck > Herren > Bekleidung > Accessoires', 'Kleidung, Schuhe, Schmuck > Herren > Bekleidung > Tops, T-Shirts & Hedem', 'Kleidung, Schuhe, Schmuck > Herren > Bekleidung > Streetwear', 'Kleidung, Schuhe, Schmuck > Herren > Bekleidung > Bademode', 'Kleidung, Schuhe, Schmuck > Herren > Bekleidung > Jacken, Mäntel & Westen', 'Kleidung, Schuhe, Schmuck > Herren > Bekleidung > Sportbekleidung', 'Kleidung, Schuhe, Schmuck > Herren > Bekleidung > Socken & Strümpfe', 'Kleidung, Schuhe, Schmuck > Herren > Bekleidung > Unterwäsche', 'Kleidung, Schuhe, Schmuck > Herren > Bekleidung > Pullover & Strickjacken', 'Kleidung, Schuhe, Schmuck > Herren > Schuhe > Sneaker & Sportschuhe', 'Kleidung, Schuhe, Schmuck > Herren > Schuhe > Stiefel', 'Kleidung, Schuhe, Schmuck > Herren > Schuhe > Sandalen & Slides', 'Kleidung, Schuhe, Schmuck > Herren > Schuhe > Flache Schuhe', 'Kleidung, Schuhe, Schmuck > Herren > Schuhe > Hausschuhe', 'Kleidung, Schuhe, Schmuck > Herren > Schuhe > Arbeits- & Berufsschuhe', 'Kleidung, Schuhe, Schmuck > Herren > Taschen > Zubehör', 'Kleidung, Schuhe, Schmuck > Herren > Taschen > Umhängetaschen', 'Kleidung, Schuhe, Schmuck > Herren > Taschen > Clutches', 'Kleidung, Schuhe, Schmuck > Herren > Taschen > Handtaschen & Schultertaschen', 'Kleidung, Schuhe, Schmuck > Herren > Taschen > Rucksäcke', 'Kleidung, Schuhe, Schmuck > Herren > Taschen > Schultaschen, Federmäppchen', 'Kleidung, Schuhe, Schmuck > Herren > Taschen > Sporttaschen', 'Kleidung, Schuhe, Schmuck > Herren > Taschen > Einkaufskörbe & -taschen', 'Kleidung, Schuhe, Schmuck > Herren > Taschen > Business- & Laptop-Taschen', 'Kleidung, Schuhe, Schmuck > Herren > Uhren', 'Kleidung, Schuhe, Schmuck > Herren > Schmuck', 'Kleidung, Schuhe, Schmuck > Herren > Gepäck > Koffer', 'Kleidung, Schuhe, Schmuck > Herren > Gepäck > Reisetaschen', 'Kleidung, Schuhe, Schmuck > Herren > Gepäck > Zubehör', 'Kleidung, Schuhe, Schmuck > Mädchen > Accessoires', 'Kleidung, Schuhe, Schmuck > Mädchen > Hosen', 'Kleidung, Schuhe, Schmuck > Mädchen > Kleider', 'Kleidung, Schuhe, Schmuck > Mädchen > Tops & Shirts', 'Kleidung, Schuhe, Schmuck > Mädchen > Jacken & Mäntel', 'Kleidung, Schuhe, Schmuck > Mädchen > Schuhe > Sneaker & Sportschuhe', 'Kleidung, Schuhe, Schmuck > Mädchen > Schuhe > Stiefel', 'Kleidung, Schuhe, Schmuck > Mädchen > Schuhe > Sandalen & Slides', 'Kleidung, Schuhe, Schmuck > Mädchen > Schuhe > Flache Schuhe', 'Kleidung, Schuhe, Schmuck > Mädchen > Schuhe > Hausschuhe', 'Kleidung, Schuhe, Schmuck > Mädchen > Schuhe > Pumps', 'Kleidung, Schuhe, Schmuck > Mädchen > Schmuck', 'Kleidung, Schuhe, Schmuck > Mädchen > Uhren', 'Kleidung, Schuhe, Schmuck > Jungen > Accessoires', 'Kleidung, Schuhe, Schmuck > Jungen > Hosen', 'Kleidung, Schuhe, Schmuck > Jungen > Shirts', 'Kleidung, Schuhe, Schmuck > Jungen > Pullover & Stickjacken', 'Kleidung, Schuhe, Schmuck > Jungen > Jacken & Mäntel', 'Kleidung, Schuhe, Schmuck > Jungen > Schuhe > Sneaker & Sportschuhe', 'Kleidung, Schuhe, Schmuck > Jungen > Schuhe > Stiefel', 'Kleidung, Schuhe, Schmuck > Jungen > Schuhe > Sandalen & Slides', 'Kleidung, Schuhe, Schmuck > Jungen > Schuhe > Flache Schuhe', 'Kleidung, Schuhe, Schmuck > Jungen > Schuhe > Hausschuhe', 'Kleidung, Schuhe, Schmuck > Jungen > Schmuck', 'Kleidung, Schuhe, Schmuck > Jungen > Uhren', 'Kleidung, Schuhe, Schmuck > Babies', 'Bücher & Musik > Bücher > Kinder & Jugend', 'Bücher & Musik > Bücher > Fachliteratur & Lernen', 'Bücher & Musik > Bücher > Ratgeber & Freizeit', 'Bücher & Musik > Bücher > Sachbücher', 'Bücher & Musik > Bücher > Fremdsprachige Bücher', 'Bücher & Musik > Bücher > Sonstige', 'Bücher & Musik > Musik', 'Büro & IT > Elektronik & Foto', 'Büro & IT > Computer & Büro', 'Spielzeug & Baby > Spielzeug', 'Spielzeug & Baby > Baby', 'Spielzeug & Baby > Babybekleidung & Babyschuhe', 'Kunst', 'Sport & Freizeit > Camping & Outdoor', 'Sport & Freizeit > Fitness', 'Sport & Freizeit > Fußball', 'Sport & Freizeit > Radsport', 'Sport & Freizeit > Running', 'Sport & Freizeit > Sportelektronik', 'Sonstiges', ] for breadcrumbs in categories: create_from_breadcrumbs(breadcrumbs)
def create_default_categories(apps, schema_editor): """Create default coupon categories.""" for category in DEFAULT_CATEGORIES: create_from_breadcrumbs('{} > {}'.format(COUPON_CATEGORY_NAME, category))
def create_default_categories(apps, schema_editor): """Create default coupon categories.""" Category.skip_history_when_saving = True for category in DEFAULT_CATEGORIES: create_from_breadcrumbs('{} > {}'.format(COUPON_CATEGORY_NAME, category))
def create_product(self, product_class, cols): (upc, title, sku) = cols[0:3] description = cols[12] partner = 'msh' price = cols[8] stock = cols[9] country = cols[3] region = cols[4] if country in self.small_categories: category = 'Wines > Others' else: if region in self.small_regions: category = 'Wines > %s > Others' % country else: category = 'Wines > %s > %s' % (country, region) if upc: try: product = Product.objects.get(upc=upc) except Product.DoesNotExist: product = Product(upc=upc) else: product = Product() product.structure = Product.STANDALONE product.title = title #product.slug = upc product.description = description if description else '' product.product_class = product_class attr_names = ['Country', 'Region', 'Rating', 'Type', 'Size', 'Classification', 'Vintage'] attr_values = [cols[3], cols[4], cols[5], cols[6], '%dml' % cols[7], cols[10], cols[11]] # Attributes for code, value in zip(attr_names, attr_values): # Need to check if the attribute requires an Option instance attr = product_class.attributes.get( code=code) if attr.is_option: value = attr.option_group.options.get(option=value) if attr.type == 'date': value = datetime.strptime(value, "%d/%m/%Y").date() setattr(product.attr, code, value) product.save() # Category information if category: leaf = create_from_breadcrumbs(category) ProductCategory.objects.get_or_create( product=product, category=leaf) # Stock record if partner: partner, __ = Partner.objects.get_or_create(name=partner) try: record = StockRecord.objects.get(product=product) except StockRecord.DoesNotExist: record = StockRecord(product=product) record.partner = partner record.partner_sku = sku record.price_excl_tax = D(price) record.price_currency = 'HKD' if stock != 'NULL': record.num_in_stock = stock record.save()
def create_security_disclosure_reward_category(apps, schema_editor): """ Create coupon category for rewarding security disclosures. """ Category.skip_history_when_saving = True create_from_breadcrumbs('{} > {}'.format( COUPON_CATEGORY_NAME, SECURITY_DISCLOSURE_REWARD_CATEGORY))
def create_product(self, product_class, cols): (upc, title, sku) = cols[0:3] description = cols[12] partner = 'msh' price = cols[8] stock = cols[9] country = cols[3] region = cols[4] if country in self.small_categories: category = 'Wines > Others' else: if region in self.small_regions: category = 'Wines > %s > Others' % country else: category = 'Wines > %s > %s' % (country, region) if upc: try: product = Product.objects.get(upc=upc) except Product.DoesNotExist: product = Product(upc=upc) else: product = Product() product.structure = Product.STANDALONE product.title = title #product.slug = upc product.description = description if description else '' product.product_class = product_class attr_names = [ 'Country', 'Region', 'Rating', 'Type', 'Size', 'Classification', 'Vintage' ] attr_values = [ cols[3], cols[4], cols[5], cols[6], '%dml' % cols[7], cols[10], cols[11] ] # Attributes for code, value in zip(attr_names, attr_values): # Need to check if the attribute requires an Option instance attr = product_class.attributes.get(code=code) if attr.is_option: value = attr.option_group.options.get(option=value) if attr.type == 'date': value = datetime.strptime(value, "%d/%m/%Y").date() setattr(product.attr, code, value) product.save() # Category information if category: leaf = create_from_breadcrumbs(category) ProductCategory.objects.get_or_create(product=product, category=leaf) # Stock record if partner: partner, __ = Partner.objects.get_or_create(name=partner) try: record = StockRecord.objects.get(product=product) except StockRecord.DoesNotExist: record = StockRecord(product=product) record.partner = partner record.partner_sku = sku record.price_excl_tax = D(price) record.price_currency = 'HKD' if stock != 'NULL': record.num_in_stock = stock record.save()