Exemple #1
0
    def setUp(self):
        """
        """
        self.client.login(username="******", password="******")

        for i in range(0, 10):
            product = Product(
                name="Product %s" % i,
                slug="product-%s" % i,
                description="This is the description %s" % i,
                price=i
            )
            product.save()

        c1 = Category(name="Category 1", slug="category-1")
        c1.save()

        c11 = Category(name="Category 1-1", slug="category-1-1", parent=c1)
        c11.save()

        c111 = Category(name="Category 1-1-1", slug="category-1-1-1", parent=c11)
        c111.save()

        # Assign products
        product = Product.objects.get(slug="product-1")
        c111.products = (product, )
Exemple #2
0
def add_product_variant(request):
    result = simplejson.dumps({
        "html": "Hi",
        "message": "Hi",
    }, cls=LazyEncoder)
    item_uuid = request.GET.get('item_uuid','')
    logging.error(item_uuid)
    item = Item.objects.get(uuid=item_uuid)
    old_products = Product.objects.filter(slug=item.uuid)
    if len(old_products)>0:
        return HttpResponse(result)
    controller = Controller()
    controller.item_to_product(item);
    product = Product.objects.get(ghdefinition=item.definition)
    #props = product.get_properties()
    slug = item_uuid
    sku = item_uuid[:30]
    price = product.price
    name = product.name
    variants_count = product.variants.count()
    variant = Product(name=name, slug=slug, sku=sku, parent=product, price=price, item=item, 
                      active=True, active_images=True, active_sku=True, active_price=True, active_name=False,
                      variant_position=(variants_count + 1), sub_type=VARIANT)  
    
    variant.save()
    return HttpResponse(result)
Exemple #3
0
    def setUp(self):
        """
        """
        self.client.login(username="******", password="******")

        for i in range(0, 10):
            product = Product(
                name="Product %s" % i,
                slug="product-%s" % i,
                description="This is the description %s" % i,
                price=i
            )
            product.save()

        c1 = Category(name="Category 1", slug="category-1")
        c1.save()

        c11 = Category(name="Category 1-1", slug="category-1-1", parent=c1)
        c11.save()

        c111 = Category(name="Category 1-1-1", slug="category-1-1-1", parent=c11)
        c111.save()

        # Assign products
        product = Product.objects.get(slug="product-1")
        c111.products = (product, )
Exemple #4
0
 def save_model(self, request, obj, form, change):
     form.default_material = Material.objects.all()[1]
     obj.default_material = Material.objects.all()[1]
     super(GhDefinitionAdmin, self).save_model(request, obj, form, change)
     if change==False:
         obj.set_defaults()
         p = Product(name=obj.name, slug=uuid.uuid1(), ghdefinition=obj, sub_type=PRODUCT_WITH_VARIANTS, active=False)
         p.save()
         
     if "uploaded_file" in form.changed_data:
         controller = Controller()
         obj.set_file_name()
         controller.process_ghx(obj)
         obj.save()
Exemple #5
0
def update_products_from_es(request):
    """
    """
    products_fh = open("%s/products.csv" % UPDATE_PATH)
    reader = csv.reader(products_fh, delimiter=";", quotechar="'")
            
    for row in reader:
        try:
            price = float(row[7])
        except:
            price = 0

        try:
            product = Product.objects.get(sku=row[2])
        except ObjectDoesNotExist:
            product = Product()
            product.slug = slugify(row[1])
            product.sku=row[2]
            print "Created Product: %s" % row[2]
        else:
            print "Updated Product: %s" % product.id
            
        product.name = row[3]
        product.price = price
        product.short_description = row[6]
        product.description = row[5]
        product.meta_description = row[4]
        product.for_sale = int(row[15])
        product.for_sale_price = row[16] 
        product.stock_amount = row[10]
        product.manage_stock_amount = not int(row[9])
        product.weight = row[11]
        product.height = row[13]
        product.length = row[12]
        product.width  = row[14]
        
        product.save()
                        
    return HttpResponse("")
Exemple #6
0
def update_products_from_es(request):
    """
    """
    products_fh = open("%s/products.csv" % UPDATE_PATH)
    reader = csv.reader(products_fh, delimiter=";", quotechar="'")

    for row in reader:
        try:
            price = float(row[7])
        except:
            price = 0

        try:
            product = Product.objects.get(sku=row[2])
        except ObjectDoesNotExist:
            product = Product()
            product.slug = slugify(row[1])
            product.sku = row[2]
            print "Created Product: %s" % row[2]
        else:
            print "Updated Product: %s" % product.id

        product.name = row[3]
        product.price = price
        product.short_description = row[6]
        product.description = row[5]
        product.meta_description = row[4]
        product.for_sale = int(row[15])
        product.for_sale_price = row[16]
        product.stock_amount = row[10]
        product.manage_stock_amount = not int(row[9])
        product.weight = row[11]
        product.height = row[13]
        product.length = row[12]
        product.width = row[14]

        product.save()

    return HttpResponse("")
Exemple #7
0
def add_variants(request, product_id):
    """Adds variants to product with passed product_id based on property/option-
    combinations passed within request body.
    """
    cache.delete("%s-variants%s" %
                 (settings.CACHE_MIDDLEWARE_KEY_PREFIX, product_id))

    product = Product.objects.get(pk=product_id)

    # Add variant(s)
    #variant_simple_form = ProductVariantSimpleForm(data=request.POST)

    # We don't have to check whether the form is valid. If the fields
    # are empty we create default ones.

    variants_count = product.variants.count()

    # First we need to prepare the requested properties for the use
    # with cartesian product. That means if the keyword "all" is
    # found we collect all options of this properties.
    properties = []
    for key, value in request.POST.items():
        if key.startswith("property"):
            property_id = key.split("_")[1]
            if value == "all":
                temp = []
                for option in PropertyOption.objects.filter(
                        property=property_id):
                    temp.append("%s|%s" % (property_id, option.id))
                properties.append(temp)
            else:
                properties.append(["%s|%s" % (property_id, value)])

    # Create a variant for every requested option combination
    for i, options in enumerate(manage_utils.cartesian_product(*properties)):

        if product.has_variant(options):
            continue

        name = request.POST.get("name")
        price = request.POST.get("price")
        slug = request.POST.get("slug")

        for option in options:
            property_id, option_id = option.split("|")
            o = PropertyOption.objects.get(pk=option_id)
            if slug:
                slug += "-"
            slug += slugify(o.name)

        slug = "%s-%s" % (product.slug, slug)
        sku = "%s-%s" % (product.sku, i + 1)

        variant = None
        # need to validate the amalgamated slug to make sure it is not already in use
        try:
            variant = Product.objects.get(slug=slug)
            message = _(u"That slug is already in use. Please use another.")
        except Product.MultipleObjectsReturned:
            message = _(u"That slug is already in use. Please use another.")
        except Product.DoesNotExist:
            variant = Product(name=name,
                              slug=slug,
                              sku=sku,
                              parent=product,
                              price=price,
                              variant_position=(variants_count + i + 1) * 10,
                              sub_type=VARIANT)
            try:
                variant.save()
            except IntegrityError:
                continue
            else:
                # By default we copy the property groups of the product to
                # the variants
                for property_group in product.property_groups.all():
                    variant.property_groups.add(property_group)

            # Save the value for this product and property.
            for option in options:
                property_id, option_id = option.split("|")
                ProductPropertyValue.objects.create(
                    product=variant,
                    property_id=property_id,
                    value=option_id,
                    type=PROPERTY_VALUE_TYPE_VARIANT)
                # By default we create also the filter values as this most of
                # the users would excepct.
                if Property.objects.get(pk=property_id).filterable:
                    ProductPropertyValue.objects.create(
                        product=variant,
                        property_id=property_id,
                        value=option_id,
                        type=PROPERTY_VALUE_TYPE_FILTER)

            message = _(u"Variants have been added.")

    html = (
        ("#selectable-products-inline",
         _selectable_products_inline(request, product)),
        ("#variants", manage_variants(request, product_id, as_string=True)),
    )

    result = simplejson.dumps({
        "html": html,
        "message": message,
    },
                              cls=LazyEncoder)

    return HttpResponse(result)
Exemple #8
0
def products(amount=20):
    """
    """
    import lfs.core.utils
    from lfs.catalog.models import Category
    from lfs.catalog.models import Image
    from lfs.catalog.models import Product
    from lfs.core.models import Shop

    from lfs.catalog.models import Property
    from lfs.catalog.models import PropertyOption

    from lfs.shipping.models import ShippingMethod
    from lfs.criteria.models import CartPriceCriterion

    Image.objects.all().delete()
    Product.objects.all().delete()
    Category.objects.all().delete()
    PropertyOption.objects.all().delete()
    Property.objects.all().delete()

    # Images
    path = os.path.join(os.path.dirname(__file__), "data")
    fh = open(os.path.join(path, "image1.jpg"), 'rb')
    cf_1 = ContentFile(fh.read())
    fh = open(os.path.join(path, "image2.jpg"), 'rb')
    cf_2 = ContentFile(fh.read())
    fh = open(os.path.join(path, "image3.jpg"), 'rb')
    cf_3 = ContentFile(fh.read())

    image_1 = Image(title="Image 1")
    image_1.image.save("Laminat01.jpg", cf_1)
    image_1.save()

    image_2 = Image(title="Image 2")
    image_2.image.save("Laminat02.jpg", cf_2)
    image_2.save()

    image_3 = Image(title="Image 3")
    image_3.image.save("Laminat03.jpg", cf_3)
    image_3.save()

    # Properties
    property = Property(name="Color")
    property.save()

    property_option = PropertyOption(name="Yellow", property=property, price=1.0)
    property_option.save()

    property_option = PropertyOption(name="Red", property=property, price=2.0)
    property_option.save()

    property = Property(name="Size")
    property.save()

    property_option = PropertyOption(name="L", property=property, price=11.0)
    property_option.save()

    property_option = PropertyOption(name="M", property=property, price=12.0)
    property_option.save()

    shop = lfs.core.utils.get_default_shop()

    # Create categories
    category_1 = Category(name="Clothes", slug="clothes")
    category_1.save()

    category_2 = Category(name="Women", slug="women", parent=category_1)
    category_2.save()

    category_3 = Category(name="Pants", slug="pants-woman", parent=category_2)
    category_3.save()

    category_4 = Category(name="Dresses", slug="dresses", parent=category_2)
    category_4.save()

    category_5 = Category(name="Men", slug="men", parent=category_1)
    category_5.save()

    category_6 = Category(name="Pants", slug="pants-men", parent=category_5)
    category_6.save()

    category_7 = Category(name="Pullover", slug="pullover", parent=category_5)
    category_7.save()

    shop.categories = [category_1, category_2, category_3, category_4, category_5, category_6, category_7]
    shop.save()

    # Create products
    for i in range(1, amount):
        p = Product(name="Rock-%s" % i, slug="rock-%s" % i, sku="rock-000%s" % i, price=i * 10)
        p.save()

        if i == 1:
            p.images.add(image_1)
            p.images.add(image_2)
            p.images.add(image_3)
            p.save()
        else:
            img = Image(title="Image 1", image="images/Laminat01.jpg")
            img.save()
            p.images.add(img)
            p.save()

        category_3.products.add(p)
        category_3.save()

        print "Rock-%s created" % i

    for i in range(1, amount):
        p = Product(name="Hemd-%s" % i, slug="hemd-%s" % i, sku="hemd-000%s" % i, price=i * 10, active=True)
        p.save()

        img = Image(title="Image 1", image="images/Laminat02.jpg")
        img.save()
        p.images.add(img)
        p.save()

        category_4.products.add(p)
        category_4.save()

        print "Hemd-%s created" % i

    for i in range(1, amount):
        p = Product(name="Pullover-%s" % i, slug="pullover-%s" % i, sku="pullover-000%s" % i, price=i * 10, active=True)
        p.save()

        img = Image(title="Image 1", image="images/Laminat03.jpg")
        img.save()
        p.images.add(img)
        p.save()

        category_6.products.add(p)
        category_6.save()

        print "Pullover-%s created" % i

    for i in range(1, amount):
        p = Product(name="Hose-%s" % i, slug="hose-%s" % i, sku="hose-000%s" % i, price=i * 10, active=True)
        p.save()

        img = Image(title="Image 1", image="images/Laminat03.jpg")
        img.save()
        p.images.add(img)
        p.save()

        category_7.products.add(p)
        category_7.save()

        print "Hose-%s created" % i
Exemple #9
0
def products(amount=20):
    """
    """
    import lfs.core.utils
    from lfs.catalog.models import Category
    from lfs.catalog.models import Image
    from lfs.catalog.models import Product
    from lfs.core.models import Shop

    from lfs.catalog.models import Property
    from lfs.catalog.models import PropertyOption

    from lfs.shipping.models import ShippingMethod
    from lfs.criteria.models import CartPriceCriterion

    Image.objects.all().delete()
    Product.objects.all().delete()
    Category.objects.all().delete()
    PropertyOption.objects.all().delete()
    Property.objects.all().delete()

    # Images
    path = os.path.join(os.getcwd(), "parts/lfs/lfs/utils/data")
    fh = open(os.path.join(path, "image1.jpg"))
    cf_1 = ContentFile(fh.read())
    fh = open(os.path.join(path, "image2.jpg"))
    cf_2 = ContentFile(fh.read())
    fh = open(os.path.join(path, "image3.jpg"))
    cf_3 = ContentFile(fh.read())

    image_1 = Image(title="Image 1")
    image_1.image.save("Laminat01.jpg", cf_1)
    image_1.save()

    image_2 = Image(title="Image 2")
    image_2.image.save("Laminat02.jpg", cf_2)
    image_2.save()

    image_3 = Image(title="Image 3")
    image_3.image.save("Laminat03.jpg", cf_3)
    image_3.save()

    # Properties
    property = Property(name="Color")
    property.save()

    property_option = PropertyOption(name="Yellow",
                                     property=property,
                                     price=1.0)
    property_option.save()

    property_option = PropertyOption(name="Red", property=property, price=2.0)
    property_option.save()

    property = Property(name="Size")
    property.save()

    property_option = PropertyOption(name="L", property=property, price=11.0)
    property_option.save()

    property_option = PropertyOption(name="M", property=property, price=12.0)
    property_option.save()

    shop = lfs.core.utils.get_default_shop()

    # Create categories
    category_1 = Category(name="Clothes", slug="clothes")
    category_1.save()

    category_2 = Category(name="Women", slug="women", parent=category_1)
    category_2.save()

    category_3 = Category(name="Pants", slug="pants-woman", parent=category_2)
    category_3.save()

    category_4 = Category(name="Dresses", slug="dresses", parent=category_2)
    category_4.save()

    category_5 = Category(name="Men", slug="men", parent=category_1)
    category_5.save()

    category_6 = Category(name="Pants", slug="pants-men", parent=category_5)
    category_6.save()

    category_7 = Category(name="Pullover", slug="pullover", parent=category_5)
    category_7.save()

    shop.categories = [
        category_1, category_2, category_3, category_4, category_5, category_6,
        category_7
    ]
    shop.save()

    # Create products
    for i in range(1, amount):
        p = Product(name="Rock-%s" % i,
                    slug="rock-%s" % i,
                    sku="rock-000%s" % i,
                    price=i * 10)
        p.save()

        if i == 1:
            p.images.add(image_1)
            p.images.add(image_2)
            p.images.add(image_3)
            p.save()
        else:
            img = Image(title="Image 1", image="images/Laminat01.jpg")
            img.save()
            p.images.add(img)
            p.save()

        category_3.products.add(p)
        category_3.save()

        print "Rock-%s created" % i

    for i in range(1, amount):
        p = Product(name="Hemd-%s" % i,
                    slug="hemd-%s" % i,
                    sku="hemd-000%s" % i,
                    price=i * 10,
                    active=True)
        p.save()

        img = Image(title="Image 1", image="images/Laminat02.jpg")
        img.save()
        p.images.add(img)
        p.save()

        category_4.products.add(p)
        category_4.save()

        print "Hemd-%s created" % i

    for i in range(1, amount):
        p = Product(name="Pullover-%s" % i,
                    slug="pullover-%s" % i,
                    sku="pullover-000%s" % i,
                    price=i * 10,
                    active=True)
        p.save()

        img = Image(title="Image 1", image="images/Laminat03.jpg")
        img.save()
        p.images.add(img)
        p.save()

        category_6.products.add(p)
        category_6.save()

        print "Pullover-%s created" % i

    for i in range(1, amount):
        p = Product(name="Hose-%s" % i,
                    slug="hose-%s" % i,
                    sku="hose-000%s" % i,
                    price=i * 10,
                    active=True)
        p.save()

        img = Image(title="Image 1", image="images/Laminat03.jpg")
        img.save()
        p.images.add(img)
        p.save()

        category_7.products.add(p)
        category_7.save()

        print "Hose-%s created" % i
Exemple #10
0
def add_variants(request, product_id):
    """Adds variants to product with passed product_id based on property/option-
    combinations passed within request body.
    """
    cache.delete("%s-variants%s" % (settings.CACHE_MIDDLEWARE_KEY_PREFIX, product_id))

    product = Product.objects.get(pk=product_id)

    # Add variant(s)
    variant_simple_form = ProductVariantSimpleForm(data=request.POST)

    # We don't have to check whether the form is valid. If the fields
    # are empty we create default ones.

    # First we need to prepare the requested properties for the use
    # with cartesian product. That means if the keyword "all" is
    # found we collect all options of this properties.
    properties = []
    for key, value in request.POST.items():
        if key.startswith("property"):
            property_id = key.split("_")[1]
            if value == "all":
                temp = []
                for option in PropertyOption.objects.filter(property=property_id):
                    temp.append("%s|%s" % (property_id, option.id))
                properties.append(temp)
            else:
                properties.append(["%s|%s" % (property_id, value)])

    # Create a variant for every requested option combination
    for i, options in enumerate(manage_utils.cartesian_product(*properties)):

        if product.has_variant(options):
            continue

        name = request.POST.get("name")
        price = request.POST.get("price")
        slug = request.POST.get("slug")

        for option in options:
            property_id, option_id = option.split("|")
            o = PropertyOption.objects.get(pk=option_id)
            if slug:
                slug += "-"
            slug += slugify(o.name)

        slug = "%s-%s" % (product.slug, slug)
        sku = "%s-%s" % (product.sku, i + 1)

        variant = None
        # need to validate the amalgamated slug to make sure it is not already in use
        try:
            product = Product.objects.get(slug=slug)
            message = _(u"That slug is already in use. Please use another.")
        except Product.MultipleObjectsReturned:
            message = _(u"That slug is already in use. Please use another.")
        except Product.DoesNotExist:
            variant = Product(name=name, slug=slug, sku=sku, parent=product, price=price, variant_position=(i + 1) * 10, sub_type=VARIANT)
            try:
                variant.save()
            except IntegrityError:
                continue
            else:
                # By default we copy the property groups of the product to
                # the variants
                for property_group in product.property_groups.all():
                    variant.property_groups.add(property_group)

            # Save the value for this product and property.
            for option in options:
                property_id, option_id = option.split("|")
                ProductPropertyValue.objects.create(product=variant, property_id=property_id, value=option_id, type=PROPERTY_VALUE_TYPE_VARIANT)
                # By default we create also the filter values as this most of
                # the users would excepct.
                if Property.objects.get(pk=property_id).filterable:
                    ProductPropertyValue.objects.create(product=variant, property_id=property_id, value=option_id, type=PROPERTY_VALUE_TYPE_FILTER)

            message = _(u"Variants have been added.")

    html = (
        ("#selectable-products-inline", _selectable_products_inline(request, product)),
        ("#variants", manage_variants(request, product_id, as_string=True)),
    )

    result = simplejson.dumps({
        "html": html,
        "message": message,
    }, cls=LazyEncoder)

    return HttpResponse(result)
Exemple #11
0
def add_variants(request, product_id):
    """Adds variants to product with passed product_id based on property/option-
    combinations passed within request body.
    """
    cache.delete("variants%s" % product_id)

    product = Product.objects.get(pk=product_id)

    # Add variant(s)
    variant_simple_form = ProductVariantSimpleForm(data=request.POST)

    # We don't have to check whether the form is valid. If the fields
    # are empty we create default ones.

    # First we need to prepare the requested properties for the use
    # with cartesian product. That means if the keyword "all" is
    # found we collect all options of this properties.
    properties = []
    for key, value in request.POST.items():
        if key.startswith("property"):
            property_id = key.split("_")[1]
            if value == "all":
                temp = []
                for option in PropertyOption.objects.filter(property=property_id):
                    temp.append("%s|%s" % (property_id, option.id))
                properties.append(temp)
            else:
                properties.append(["%s|%s" % (property_id, value)])

    # Create a variant for every requested option combination
    for i, options in enumerate(manage_utils.cartesian_product(*properties)):

        if product.has_variant(options):
            continue

        price = request.POST.get("price")

        slug = ""
        for option in options:
            property_id, option_id = option.split("|")
            o = PropertyOption.objects.get(pk=option_id)
            slug += "-" + slugify(o.name)

        slug = "%s%s" % (product.slug, slug)
        sku = "%s-%s" % (product.sku, i+1)

        variant = Product(slug=slug, sku=sku, parent=product, price=price, variant_position=i+1, sub_type=VARIANT)
        variant.save()

        # Save the value for this product and property
        for option in options:
            property_id, option_id = option.split("|")
            pvo = ProductPropertyValue(product = variant, property_id = property_id, value=option_id)
            pvo.save()

    from lfs.manage.views.product.product import selectable_products_inline
    result = simplejson.dumps({
        "properties" : manage_variants(request, product_id, as_string=True),
    })

    return HttpResponse(result)
Exemple #12
0
def add_variants(request, product_id):
    """Adds variants to product with passed product_id based on property/option-
    combinations passed within request body.
    """
    cache.delete("variants%s" % product_id)

    product = Product.objects.get(pk=product_id)

    # Add variant(s)
    variant_simple_form = ProductVariantSimpleForm(data=request.POST)

    # We don't have to check whether the form is valid. If the fields
    # are empty we create default ones.

    # First we need to prepare the requested properties for the use
    # with cartesian product. That means if the keyword "all" is
    # found we collect all options of this properties.
    properties = []
    for key, value in request.POST.items():
        if key.startswith("property"):
            property_id = key.split("_")[1]
            if value == "all":
                temp = []
                for option in PropertyOption.objects.filter(
                        property=property_id):
                    temp.append("%s|%s" % (property_id, option.id))
                properties.append(temp)
            else:
                properties.append(["%s|%s" % (property_id, value)])

    # Create a variant for every requested option combination
    for i, options in enumerate(manage_utils.cartesian_product(*properties)):

        if product.has_variant(options):
            continue

        price = request.POST.get("price")

        slug = ""
        for option in options:
            property_id, option_id = option.split("|")
            o = PropertyOption.objects.get(pk=option_id)
            slug += "-" + slugify(o.name)

        slug = "%s%s" % (product.slug, slug)
        sku = "%s-%s" % (product.sku, i + 1)

        variant = Product(slug=slug,
                          sku=sku,
                          parent=product,
                          price=price,
                          variant_position=i + 1,
                          sub_type=VARIANT)
        variant.save()

        # Save the value for this product and property
        for option in options:
            property_id, option_id = option.split("|")
            pvo = ProductPropertyValue(product=variant,
                                       property_id=property_id,
                                       value=option_id)
            pvo.save()

    from lfs.manage.views.product.product import selectable_products_inline
    result = simplejson.dumps({
        "properties":
        manage_variants(request, product_id, as_string=True),
    })

    return HttpResponse(result)
Exemple #13
0
def products(request):
    """
    """    
    amount = int(request.GET.get("amount", 20))
    
    Image.objects.all().delete()
    Product.objects.all().delete()
    Category.objects.all().delete()
    Shop.objects.all().delete()
    PropertyOption.objects.all().delete()
    Property.objects.all().delete()
    
    # Images
    path = os.path.join(sys.path[0], "lfs/utils/data")
    fh = open(os.path.join(path, "image1.jpg"))
    cf_1 = ContentFile(fh.read())
    fh = open(os.path.join(path, "image2.jpg"))
    cf_2 = ContentFile(fh.read())
    fh = open(os.path.join(path, "image3.jpg"))
    cf_3 = ContentFile(fh.read())
    
    image_1 = Image(title="Image 1")    
    image_1.image.save("Laminat01.jpg", cf_1)
    image_1.save()

    image_2 = Image(title="Image 2")
    image_2.image.save("Laminat02.jpg", cf_2)
    image_2.save()

    image_3 = Image(title="Image 3")
    image_3.image.save("Laminat03.jpg", cf_3)
    image_3.save()

    # Properties
    property = Property(name="Color")
    property.save()

    property_option= PropertyOption(name = "Yellow", property = property, price = 1.0)
    property_option.save()

    property_option = PropertyOption(name = "Red", property = property, price = 2.0)
    property_option.save()

    property = Property(name="Size")
    property.save()

    property_option = PropertyOption(name = "L", property = property, price = 11.0)
    property_option.save()

    property_option = PropertyOption(name = "M", property = property, price = 12.0)
    property_option.save()
    
    # Create shop
    shop = Shop(name="Test", shop_owner="Test")
    shop.save()

    # Create categories
    category_1 = Category(name="Clothes", slug="clothes")
    category_1.save()
    
    category_2 = Category(name="Women", slug="women", parent=category_1)
    category_2.save()

    category_3 = Category(name="Pants", slug="pants-woman", parent=category_2)
    category_3.save()

    category_4 = Category(name="Dresses", slug="dresses", parent=category_2)
    category_4.save()

    category_5 = Category(name="Men", slug="men", parent=category_1)
    category_5.save()

    category_6 = Category(name="Pants", slug="pants-men", parent=category_5)
    category_6.save()

    category_7 = Category(name="Pullover", slug="pullover", parent=category_5)
    category_7.save()
    
    shop.categories = [category_1, category_2, category_3, category_4, category_5, category_6, category_7]
    shop.save()
    
    # Create products
    for i in range(1, amount):
        p = Product(name="1-%s" % i, slug="1-%s" % i, price=i)
        p.save()

        if i == 1:
            p.images.add(image_1)
            p.images.add(image_2)
            p.images.add(image_3)
            p.save()            
        else:
            img = Image(title="Image 1", image="images/Laminat01.jpg")
            img.save()
            p.images.add(img)
            p.save()
        
        category_3.products.add(p)
        category_3.save()
        
        print "1-%s created" % i
        

    for i in range(1, amount):
        p = Product(name="2-%s" % i, slug="2-%s" % i, price=i*10)
        p.save()

        img = Image(title="Image 1", image="images/Laminat02.jpg")
        img.save()
        p.images.add(img)
        p.save()

        category_4.products.add(p)
        category_4.save()

        print "2-%s created" % i
    
    for i in range(1, amount):
        p = Product(name="3-%s" % i, slug="3-%s" % i, price=i*100)
        p.save()

        img = Image(title="Image 1", image="images/Laminat03.jpg")
        img.save()
        p.images.add(img)
        p.save()

        category_6.products.add(p)
        category_6.save()

        print "3-%s created" % i

    for i in range(1, amount):
        p = Product(name="4-%s" % i, slug="4-%s" % i, price=i*100)
        p.save()

        img = Image(title="Image 1", image="images/Laminat03.jpg")
        img.save()
        p.images.add(img)
        p.save()

        category_7.products.add(p)
        category_7.save()

        print "4-%s created" % i
    
    product = Product.objects.get(slug="1-1")

    return HttpResponseRedirect("/shops")
Exemple #14
0
def products(request):
    """
    """
    amount = int(request.GET.get("amount", 20))

    Image.objects.all().delete()
    Product.objects.all().delete()
    Category.objects.all().delete()
    Shop.objects.all().delete()
    PropertyOption.objects.all().delete()
    Property.objects.all().delete()

    # Images
    path = os.path.join(sys.path[0], "lfs/utils/data")
    fh = open(os.path.join(path, "image1.jpg"))
    cf_1 = ContentFile(fh.read())
    fh = open(os.path.join(path, "image2.jpg"))
    cf_2 = ContentFile(fh.read())
    fh = open(os.path.join(path, "image3.jpg"))
    cf_3 = ContentFile(fh.read())

    image_1 = Image(title="Image 1")
    image_1.image.save("Laminat01.jpg", cf_1)
    image_1.save()

    image_2 = Image(title="Image 2")
    image_2.image.save("Laminat02.jpg", cf_2)
    image_2.save()

    image_3 = Image(title="Image 3")
    image_3.image.save("Laminat03.jpg", cf_3)
    image_3.save()

    # Properties
    property = Property(name="Color")
    property.save()

    property_option = PropertyOption(name="Yellow",
                                     property=property,
                                     price=1.0)
    property_option.save()

    property_option = PropertyOption(name="Red", property=property, price=2.0)
    property_option.save()

    property = Property(name="Size")
    property.save()

    property_option = PropertyOption(name="L", property=property, price=11.0)
    property_option.save()

    property_option = PropertyOption(name="M", property=property, price=12.0)
    property_option.save()

    # Create shop
    shop = Shop(name="Test", shop_owner="Test")
    shop.save()

    # Create categories
    category_1 = Category(name="Clothes", slug="clothes")
    category_1.save()

    category_2 = Category(name="Women", slug="women", parent=category_1)
    category_2.save()

    category_3 = Category(name="Pants", slug="pants-woman", parent=category_2)
    category_3.save()

    category_4 = Category(name="Dresses", slug="dresses", parent=category_2)
    category_4.save()

    category_5 = Category(name="Men", slug="men", parent=category_1)
    category_5.save()

    category_6 = Category(name="Pants", slug="pants-men", parent=category_5)
    category_6.save()

    category_7 = Category(name="Pullover", slug="pullover", parent=category_5)
    category_7.save()

    shop.categories = [
        category_1, category_2, category_3, category_4, category_5, category_6,
        category_7
    ]
    shop.save()

    # Create products
    for i in range(1, amount):
        p = Product(name="1-%s" % i, slug="1-%s" % i, price=i)
        p.save()

        if i == 1:
            p.images.add(image_1)
            p.images.add(image_2)
            p.images.add(image_3)
            p.save()
        else:
            img = Image(title="Image 1", image="images/Laminat01.jpg")
            img.save()
            p.images.add(img)
            p.save()

        category_3.products.add(p)
        category_3.save()

        print "1-%s created" % i

    for i in range(1, amount):
        p = Product(name="2-%s" % i, slug="2-%s" % i, price=i * 10)
        p.save()

        img = Image(title="Image 1", image="images/Laminat02.jpg")
        img.save()
        p.images.add(img)
        p.save()

        category_4.products.add(p)
        category_4.save()

        print "2-%s created" % i

    for i in range(1, amount):
        p = Product(name="3-%s" % i, slug="3-%s" % i, price=i * 100)
        p.save()

        img = Image(title="Image 1", image="images/Laminat03.jpg")
        img.save()
        p.images.add(img)
        p.save()

        category_6.products.add(p)
        category_6.save()

        print "3-%s created" % i

    for i in range(1, amount):
        p = Product(name="4-%s" % i, slug="4-%s" % i, price=i * 100)
        p.save()

        img = Image(title="Image 1", image="images/Laminat03.jpg")
        img.save()
        p.images.add(img)
        p.save()

        category_7.products.add(p)
        category_7.save()

        print "4-%s created" % i

    product = Product.objects.get(slug="1-1")

    return HttpResponseRedirect("/shops")