def categorylist(self): shopCategories = set() shopCategoryNames = set() shopProductCategories = self.shop_product_categories() for productcategory in shopProductCategories: if productcategory != None: currentcategory = get_or_none(Category, id=productcategory.category.id) shopCategories.add(currentcategory) shopCategoryNames.add(currentcategory.name) return shopCategories, shopCategoryNames
def get_categoryName(request, shop_slug=None, group_by=None): shopCategoryNames = [] if shop_slug is None: shopProductCategories = get_filter_lists().shop_product_categories() else: shop = get_object_or_404(Shop, slug__iexact=shop_slug) shopProductCategories = get_filter_lists( shop).shop_product_categories() for productcategory in shopProductCategories: if productcategory != None: currentcategory = get_or_none(Category, id=productcategory.category.id) if group_by != "All": if currentcategory.full_name.find(group_by) >= 0: if not shopCategoryNames.__contains__( currentcategory.name): shopCategoryNames.append(str(currentcategory.name)) else: if not shopCategoryNames.__contains__(currentcategory.name): shopCategoryNames.append(currentcategory.name) return shopCategoryNames
def itemdetail(request, shop_slug, item_slug=None): shop = get_object_or_404(Shop, slug__iexact=shop_slug) if not (shop.user.is_approved): if (request.user.is_active): if (not request.user.slug == shop.user.slug and not request.user.is_staff): return HttpResponseRedirect(reverse('under_construction')) else: return HttpResponseRedirect(reverse('under_construction')) item = get_object_or_404(Product, slug__iexact=item_slug, shop_id=shop.id, parent__isnull=True) variants = get_list_or_empty(Product, parent=item.id) images = get_list_or_empty(ProductImage, product_id=item.id) colorlist = [] for variant in variants: colorattribute = get_or_none(Attributes, product_id=variant.id, attribute_id=5) colorlist.append(colorattribute.value_as_text) colorset = set(colorlist) colorsizequantity = get_variants(item) return render( request, 'designer_shop/itemdetail.html', { 'shop': shop, 'item': item, 'variants': variants, 'validcolors': colorset, 'colorsizequantity': colorsizequantity, 'images': images, # What what in the butt (Tom Bowman) 6-22-14 })
def shop_product_categories(self): shopProductCategories = set() for products in self.shop_products: shopProductCategories.add( get_or_none(Categories, product_id=products.id)) return shopProductCategories
def get_single_variant(variant, group=None): if group is None: colorsizequantitydict = [] else: colorsizequantitydict = collections.defaultdict(list) color = "" sizeSet = "" isSizeSet = False sizeX = "" sizeY = "" sizeNum = "" divider = "" oneSize = "" quantity = get_or_none(StockRecords, product_id=variant.id).net_stock_level price = str( get_or_none(StockRecords, product_id=variant.id).price_excl_tax) currency = get_or_none(StockRecords, product_id=variant.id).price_currency if get_or_none(Attributes, product_id=variant.id, attribute_id=5) != None: primary_color = get_or_none(Attributes, product_id=variant.id, attribute_id=5).value_as_text secondary_color = get_or_none(Attributes, product_id=variant.id, attribute_id=7) if secondary_color: color = str(primary_color).capitalize() + "/" + str( secondary_color.value_as_text).capitalize() else: color = primary_color if get_or_none(Attributes, product_id=variant.id, attribute_id=1) != None: sizeSetNum = get_or_none(Attributes, product_id=variant.id, attribute_id=1).value_option_id sizeSet = get_or_none(Attributes, product_id=variant.id, attribute_id=1).value_as_text isSizeSet = True if get_or_none(Attributes, product_id=variant.id, attribute_id=2) != None: sizeX = get_or_none(Attributes, product_id=variant.id, attribute_id=2).value_as_text if get_or_none(Attributes, product_id=variant.id, attribute_id=3) != None: sizeY = get_or_none(Attributes, product_id=variant.id, attribute_id=3).value_as_text if get_or_none(Attributes, product_id=variant.id, attribute_id=4) != None: sizeNum = get_or_none(Attributes, product_id=variant.id, attribute_id=4).value_as_text if get_or_none(Attributes, product_id=variant.id, attribute_id=6) != None: oneSize = "One Size" if sizeX != "" and sizeY != "": divider = " x " variantsize = str(sizeSet) + str(sizeX) + divider + str(sizeY) + str( sizeNum) + str(oneSize) caseFunc = str.capitalize if not isSizeSet else str.upper return str(color).capitalize(), caseFunc(variantsize)
def get_variants(item, group=None): variants = get_list_or_empty(Product, parent=item.id) sizeType = get_sizetype(variants) if group is None: colorsizequantitydict = [] else: colorsizequantitydict = collections.defaultdict(list) for variant in variants: color = "" sizeSet = "" sizeX = "" sizeY = "" sizeNum = "" divider = "" oneSize = "" quantity = get_or_none(StockRecords, product_id=variant.id).net_stock_level price = str( get_or_none(StockRecords, product_id=variant.id).price_excl_tax) currency = get_or_none(StockRecords, product_id=variant.id).price_currency if get_or_none(Attributes, product_id=variant.id, attribute_id=5) != None: primary_color = get_or_none(Attributes, product_id=variant.id, attribute_id=5).value_as_text secondary_color = get_or_none(Attributes, product_id=variant.id, attribute_id=7) if secondary_color: color = str(primary_color).capitalize() + "/" + str( secondary_color.value_as_text).capitalize() else: color = str(primary_color).capitalize() if get_or_none(Attributes, product_id=variant.id, attribute_id=1) != None: sizeSetNum = get_or_none(Attributes, product_id=variant.id, attribute_id=1).value_option_id sizeSet = get_or_none(Attributes, product_id=variant.id, attribute_id=1).value_as_text if get_or_none(Attributes, product_id=variant.id, attribute_id=2) != None: sizeX = get_or_none(Attributes, product_id=variant.id, attribute_id=2).value_as_text if get_or_none(Attributes, product_id=variant.id, attribute_id=3) != None: sizeY = get_or_none(Attributes, product_id=variant.id, attribute_id=3).value_as_text if get_or_none(Attributes, product_id=variant.id, attribute_id=4) != None: sizeNum = get_or_none(Attributes, product_id=variant.id, attribute_id=4).value_as_text if get_or_none(Attributes, product_id=variant.id, attribute_id=6) != None: oneSize = "One Size" if sizeX != "" and sizeY != "": divider = " x " variantsize = str(sizeSet) + str(sizeX) + divider + str(sizeY) + str( sizeNum) + str(oneSize) caseFunc = str.capitalize if sizeType != SIZE_SET else str.upper if group is None: if sizeType == SIZE_SET: quantitysize = { 'color': color, 'size': caseFunc(variantsize), 'quantity': quantity, 'price': price, 'currency': currency, 'sizeorder': sizeSetNum } else: quantitysize = { 'color': color, 'size': caseFunc(variantsize), 'quantity': quantity, 'price': price, 'currency': currency } colorsizequantitydict.append(quantitysize) else: if sizeType == SIZE_SET: groupdict = { 'color': color, 'size': caseFunc(variantsize), 'quantity': quantity, 'price': price, 'currency': currency, 'sizeorder': sizeSetNum } else: groupdict = { 'color': color, 'size': caseFunc(variantsize), 'quantity': quantity, 'price': price, 'currency': currency } mysort = groupdict[group] groupdict.pop(group) quantitysize = groupdict colorsizequantitydict[mysort].append(quantitysize) if str(group) == 'color': if sizeType == SIZE_SET: colorsizequantitydict[mysort] = sorted( colorsizequantitydict[mysort], key=itemgetter('sizeorder')) elif sizeType == SIZE_NUM: colorsizequantitydict[mysort] = sorted( colorsizequantitydict[mysort], key=lambda x: float(x.get('size'))) elif sizeType == SIZE_DIM: colorsizequantitydict[mysort] = sorted( colorsizequantitydict[mysort], key=lambda x: (float(x.get('size').split('x')[0]), float(x.get('size').split('x')[1]))) else: colorsizequantitydict[mysort] = sorted( colorsizequantitydict[mysort], key=itemgetter('size')) elif group == 'size': colorsizequantitydict[mysort] = sorted( colorsizequantitydict[mysort], key=itemgetter('color')) if sizeType == SIZE_NUM and group == 'size': colorsizequantitydict = collections.OrderedDict( sorted(colorsizequantitydict.items(), key=lambda x: float(x[0]))) if sizeType == SIZE_DIM and group == 'size': colorsizequantitydict = collections.OrderedDict( sorted(colorsizequantitydict.items(), key=lambda x: (float(x[0].split('x')[0]), float(x[0].split('x')[1])))) addsizetype = { 'sizetype': sizeType, 'variants': colorsizequantitydict, 'minprice': get_min_price(item) } return json.dumps(addsizetype)
def genderlist(self): shopGenders = set() categorylist, names = self.categorylist() for category in categorylist: shopGenders.add(get_or_none(Category, path=category.path[:4])) return shopGenders