Exemplo n.º 1
0
    def commit(self, product):
        product_type = self.cleaned_data.get('product_type')

        if product_type == 'bulk_product':
            product = cmod.BulkProduct()
        elif product_type == 'unique_product':
            product = cmod.UniqueProduct()
        else:
            product = cmod.RentalProduct()

        product.name = self.cleaned_data.get('name')
        product.category = self.cleaned_data.get('category')
        product.brand = self.cleaned_data.get('brand')
        product.price = self.cleaned_data.get('price')
        if hasattr(product, 'serial_number'):
            product.serial_number = self.cleaned_data.get('serial_number')
        if hasattr(product, 'quantity'):
            product.quantity = self.cleaned_data.get('quantity')
        if hasattr(product, 'reorder_point'):
            product.reorder_point = self.cleaned_data.get('reorder_point')
        if hasattr(product, 'reorder_quantity'):
            product.reorder_quantity = self.cleaned_data.get('reorder_quantity')
        product.save()

        product.images.create(
            product=product,
            subdir=self.cleaned_data.get('image_url'),
            is_primary=True
        )
Exemplo n.º 2
0
    def commit(self):
        print('>>>>> form is valid')
        if (self.cleaned_data.get('type') == 'bulk'):
            bp = cmod.BulkProduct()
            bp.category = self.cleaned_data.get('category', None)
            bp.name = self.cleaned_data.get('name')
            bp.price = self.cleaned_data.get('price')
            bp.quantity = self.cleaned_data.get('quantity')
            bp.reorder_trigger = self.cleaned_data.get('reorder_trigger')
            bp.reorder_qty = self.cleaned_data.get('reorder_qty')
            bp.save()

        elif (self.cleaned_data.get('type') == 'unique'):
            up = cmod.UniqueProduct()
            up.category = self.cleaned_data.get('category', None)
            up.name = self.cleaned_data.get('name')
            up.price = self.cleaned_data.get('price')
            up.serial_number = self.cleaned_data.get('serial_number')
            up.save()

        elif (self.cleaned_data.get('type') == 'rental'):
            rp = cmod.RentalProduct()
            rp.category = self.cleaned_data.get('category', None)
            rp.name = self.cleaned_data.get('name')
            rp.price = self.cleaned_data.get('price')
            rp.quantity = self.cleaned_data.get('quantity')
            rp.serial_number = self.cleaned_data.get('serial_number')
            rp.save()
Exemplo n.º 3
0
    def test_polymorphism(self):
        """Test polymorphism of products """
        ##Creates categories
        cat1 = cmod.Category()
        cat1.code = 'brass'
        cat1.name = 'Brass Instruments'
        cat1.save()

        cat2 = cmod.Category()
        cat2.code = 'woodwind'
        cat2.name = 'Woodwind Instruments'
        cat2.save()

        cat3 = cmod.Category()
        cat3.code = 'string'
        cat3.name = 'String Instruments'
        cat3.save()

        #Creates conditions
        con1 = cmod.Condition()
        con1.name = 'Poor'
        con1.save()

        con2 = cmod.Condition()
        con2.name = 'Good'
        con2.save()

        con3 = cmod.Condition()
        con3.name = 'Excellent'
        con3.save()

        ##Creates a unique product
        up1 = cmod.UniqueProduct()
        up1.category = cat1
        up1.name = 'Trumpet'
        up1.brand = 'Yamaha'
        up1.price = Decimal('899.99')
        up1.serial_number = '747amfhuefhi'
        up1.save()

        ##Creates a rental product
        rp1 = cmod.RentalProduct()
        rp1.category = cat3
        rp1.name = 'Trombone'
        rp1.brand = 'Yamaha'
        rp1.price = Decimal('1029.99')
        rp1.serial_number = '0348dsaiopjd'
        rp1.condition = con2
        rp1.save()

        #pull back off of the database
        brand1 = up1.brand
        brand2 = rp1.brand
        self.assertEqual(brand1, brand2)
Exemplo n.º 4
0
    def commit(self, new_product):
        print('>>>>>>>>> WORKING?')

        myproduct = self.cleaned_data.get('producttype')
        if myproduct == "bulk":
            new_product = cmod.BulkProduct()
        elif myproduct == "unique":
            new_product = cmod.UniqueProduct()
        else:
            new_product = cmod.RentalProduct()

        new_product.name = self.cleaned_data.get('name')
        new_product.category = self.cleaned_data.get('category')
        new_product.price = self.cleaned_data.get('price')
        new_product.quantity = self.cleaned_data.get('quantity')
        new_product.reorder_trigger = self.cleaned_data.get('reoderpoint')
        new_product.reorder_quantity = self.cleaned_data.get('reoderquantity')
        new_product.serial_number = self.cleaned_data.get('serial_number')
        new_product.save()
Exemplo n.º 5
0
    def commit(self):

        if (self.cleaned_data.get('producttype') == 'unique'):
            product = cmod.UniqueProduct()
            product.serial_number = self.cleaned_data.get('serial')
        elif (self.cleaned_data.get('producttype') == 'bulk'):
            product = cmod.BulkProduct()
            product.quantity = self.cleaned_data.get('quantity')
            product.reorder_trigger = self.cleaned_data.get('reorder-trigger')
            product.reorder_quantity = self.cleaned_data.get(
                'reorder-quantity')
        else:
            product = cmod.RentalProduct()
            product.serial_number = self.cleaned_data.get('serial')

        product.name = self.cleaned_data.get('name')
        product.category = self.cleaned_data.get('category')
        product.price = self.cleaned_data.get('price')
        product.save()
        return 4
Exemplo n.º 6
0
    def test_create_a_unique_product(self):
        ## Will create a category and a unique product, then make sure the values saved and that we have access to those values
        ## Assumptions
        # User would be logged in
        # User would have the permissions to create a product

        # Create a category
        cat5 = cmod.Category()
        cat5.codename = 'st'
        cat5.name = 'Strings'
        cat5.save()

        # Create a Unique Product
        p1 = cmod.UniqueProduct()
        p1.product = p1
        p1.serial_number = '1234asdf'
        p1.name = 'Violin'
        p1.category = cat5
        p1.price = Decimal('250.99')
        dList = [
            'Violin hand made in 1456', 'Played be Bach and Beethoved',
            'Korys favorite instrument'
        ]
        p1.descriptionList = json.dumps(dList)
        iList = [
            '/static/homepage/media/img/violin.jpg',
            '/static/homepage/media/img/violin2.png',
            '/static/homepage/media/img/violin3.jpg',
            '/static/homepage/media/img/thumbnail_violin.jpg'
        ]
        p1.imgList = json.dumps(iList)
        p1.save()

        p2 = cmod.Product.objects.get(id=p1.id)
        self.assertEquals(p2.serial_number, '1234asdf')
        self.assertEquals(p2.name, 'Violin')
        self.assertEquals(p2.category, cat5)
        self.assertEquals(p2.price, Decimal('250.99'))
        self.assertEquals(p2.descriptionList, json.dumps(dList))
        self.assertEquals(p2.imgList, json.dumps(iList))
Exemplo n.º 7
0
bp1.save()

bp2 = cmod.BulkProduct()
bp2.category = cat1
bp2.name = 'Trumpet Mouthpiece'
bp2.brand = 'Yamaha'
bp2.price = Decimal('25.00')
bp2.quantity = 30
bp2.reorder_trigger = 10
bp2.reorder_quantity = 20
bp2.serial_number = 'ijnh09'
bp2.save()
#end of bulk products

#UniqueProduct
up1 = cmod.UniqueProduct()
up1.category = cat1  #
up1.name = 'Trumpet'  #
up1.brand = 'Yamaha'  #
up1.price = Decimal('899.99')  #
up1.serial_number = '747amfhuefhi'  #
up1.save()  #

up2 = cmod.UniqueProduct()
up2.category = cat2  #
up2.name = 'Saxophone'  #
up2.brand = 'Selmer'  #
up2.price = Decimal('750.00')  #
up2.serial_number = '897dnsaiuefhi'  #
up2.save()
Exemplo n.º 8
0
bp15.path = '/static/homepage/media/images/instruments/accessories/trumpet_mute1.png'
bp15.desc = "This special mute is created entirely from aluminum. It is a free-blowing mute that will not alter or change the pitch in any way."
bp15.save()

pp26 = cmod.ProductPicture()
pp26.product = bp15
pp26.path = '/static/homepage/media/images/instruments/accessories/trumpet_mute1.png'
pp26.save()

pp27 = cmod.ProductPicture()
pp27.product = bp15
pp27.path = '/static/homepage/media/images/instruments/accessories/trumpet_mute2.png'
pp27.save()

######################## Unique Products ##########################################
up1 = cmod.UniqueProduct()
up1.category = cat1
up1.name = 'French Horn'
up1.brand = 'Allora'
up1.price = Decimal('1599.99')
up1.serial_number = 'fh001'
up1.path = '/static/homepage/media/images/instruments/brass/double_1.png'
up1.desc = "This special French Horn combines both amazing performance an affordable price. Specially designed for excellent response and tone."
up1.save()

pp28 = cmod.ProductPicture()
pp28.product = up1
pp28.path = '/static/homepage/media/images/instruments/brass/double_1.png'
pp28.save()

pp29 = cmod.ProductPicture()
Exemplo n.º 9
0
        [dir + 'french_horn_1.jpg', 'jpg', False],
        [dir + 'french_horn_2.jpg', 'jpg', False],
        [dir + 'french_horn_3.jpg', 'jpg', False],
    ], [
        "The French horn is a brass instrument made of tubing wrapped into a coil with a flared bell. Our horns are made from the finest materials so they are guaranteed to look and sound great."
    ]),
    ('Drums', 'percussion', 'Gammon', Decimal('189.99'), '908777', [
        [dir + 'drums.jpg', 'jpg', True],
        [dir + 'drums_1.jpg', 'jpg', False],
        [dir + 'drums_2.jpg', 'jpg', False],
        [dir + 'drums_3.jpg', 'jpg', False],
    ], [
        "Our drum sets are suitable for all ages and skill level. The sound quality is excellent, and the drums themselves are carefully crafted for your pleasure."
    ]),
):
    unique_product = cmod.UniqueProduct()
    unique_product.name = data[0]
    unique_product.category = cmod.Category.objects.get(
        codename__exact=data[1])
    unique_product.brand = data[2]
    unique_product.price = data[3]
    unique_product.serial_number = data[4]
    unique_product.description = data[6][0]
    unique_product.save()
    sh.add(user, unique_product)
    for img in data[5]:
        product_image = cmod.ProductImage()
        product_image.product = unique_product
        product_image.subdir = img[0]
        product_image.alttext = unique_product.name
        product_image.mimetype = img[1]
Exemplo n.º 10
0
# Create a category
cat4 = cmod.Category()
cat4.codename = 'ac'
cat4.name = 'Accessories'
cat4.save()

# Create a category
cat5 = cmod.Category()
cat5.codename = 'st'
cat5.name = 'Strings'
cat5.save()

# products = cmod.Product.objects.all()

# Create a Unique Product
p1 = cmod.UniqueProduct()
p1.product = p1
p1.serial_number = '1234asdf'
p1.name = 'Violin'
p1.category = cat5
p1.price = Decimal('250.99')
dList = [
    'Violin hand made in 1456', 'Played be Bach and Beethoved',
    'Korys favorite instrument'
]
p1.descriptionList = json.dumps(dList)
iList = [
    '/static/homepage/media/img/violin.jpg',
    '/static/homepage/media/img/violin2.png',
    '/static/homepage/media/img/violin3.jpg',
    '/static/homepage/media/img/thumbnail_violin.jpg'