コード例 #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
        )
コード例 #2
0
ファイル: create.py プロジェクト: mizozobu/INTEX-II
 def commit(self):
     # unique fields
     if self.cleaned_data.get('type') == '1':
         p = m.BulkProduct()
         p.unit = self.cleaned_data.get('unit')
         p.order_trigger = self.cleaned_data.get('order_trigger')
         p.order_quantity = self.cleaned_data.get('order_quantity')
     if self.cleaned_data.get('type') == '2':
         p = m.IndividualProduct()
         p.product_id = ''.join([
             random.choice(
                 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789012345678901234567890123456789'
             ) for j in range(6)
         ])
     if self.cleaned_data.get('type') == '3':
         p = m.RentalProduct()
         p.product_id = ''.join([
             random.choice(
                 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789012345678901234567890123456789'
             ) for j in range(6)
         ])
         p.rental_period = self.cleaned_data.get('rental_period')
         p.retire_date = self.cleaned_data.get('retire_date')
     p.name = self.cleaned_data.get('name')
     p.price = self.cleaned_data.get('price')
     p.status = self.cleaned_data.get('status')
     p.description = self.cleaned_data.get('description')
     p.category = self.cleaned_data.get('category')
     p.save()
     return p.id
コード例 #3
0
    def commit(self):

        if self.cleaned_data.get('type') == 'BulkProduct':
            product = cmod.BulkProduct()
            product.category = self.cleaned_data.get('category')
            product.type = self.cleaned_data.get('type')
            product.name = self.cleaned_data.get('name')
            product.description = self.cleaned_data.get('description')
            product.price = self.cleaned_data.get('price')
            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')

        elif self.cleaned_data.get('type') == 'IndividualProduct':
            product = cmod.IndividualProduct()
            product.category = self.cleaned_data.get('category')
            product.type = self.cleaned_data.get('type')
            product.name = self.cleaned_data.get('name')
            product.description = self.cleaned_data.get('description')
            product.price = self.cleaned_data.get('price')
            product.itmeID = self.cleaned_data.get('itmeID')

        elif self.cleaned_data.get('type') == 'RentalProduct':
            product = cmod.RentalProduct()
            product.category = self.cleaned_data.get('category')
            product.type = self.cleaned_data.get('type')
            product.name = self.cleaned_data.get('name')
            product.description = self.cleaned_data.get('description')
            product.price = self.cleaned_data.get('price')
            product.itmeID = self.cleaned_data.get('itmeID')
            product.max_rental_days = self.cleaned_data.get('max_rental_days')
            product.retire_date = self.cleaned_data.get('retire_date')

        product.save()
コード例 #4
0
ファイル: products.py プロジェクト: jacerm/IS413CHFProject
def create(request):
    form = CreateForm()
    if request.method == 'POST':
        form = CreateForm(request.POST)
        if form.is_valid():
            if form.cleaned_data.get('product_type') == 'Rental_Product':
                product = cmod.RentalProduct()
                product.name = form.cleaned_data.get('name')
                product.description = form.cleaned_data.get('description')
                product.image = form.cleaned_data.get('image')
                product.status = form.cleaned_data['status']

            elif form.cleaned_data.get('product_type') == 'Individual_Product':
                product = cmod.IndividualProduct()
                product.name = form.cleaned_data.get('name')
                product.description = form.cleaned_data.get('description')
                product.image = form.cleaned_data.get('image')
                product.creator = form.cleaned_data['creator']

            elif form.cleaned_data.get('product_type') == 'Bulk_Product':
                product = cmod.BulkProduct()
                product.name = form.cleaned_data.get('name')
                product.description = form.cleaned_data.get('description')
                product.image = form.cleaned_data.get('image')
                product.quantity = form.cleaned_data['quantity']

            product.save()
            return HttpResponseRedirect('/catalog/products/')

    template_vars = {
        'form': form,
    }
    return dmp_render_to_response(request, 'products.create.html',
                                  template_vars)
コード例 #5
0
ファイル: edit.py プロジェクト: jareddb/411_413Repo
    def commit(self, product):
        """Process the form action"""

        type_choice = self.cleaned_data.get('type')
        if self.new:
            if type_choice == 'BulkProduct':
                saveProduct = cmod.BulkProduct()
            elif type_choice == 'RentalProduct':
                saveProduct = cmod.RentalProduct()
            else:
                saveProduct = cmod.IndividualProduct()
        else:
            saveProduct = cmod.Product.objects.get(
                id=self.cleaned_data.get('id'))

        if type_choice == 'BulkProduct':
            saveProduct.quantity = self.cleaned_data.get('quantity')
        if type_choice == 'RentalProduct':
            saveProduct.max_rental_days = self.cleaned_data.get(
                'max_rental_days')
            saveProduct.retire_date = self.cleaned_data.get('retire_date')

        saveProduct.name = self.cleaned_data.get('name')
        saveProduct.status = self.cleaned_data.get('status')
        saveProduct.description = self.cleaned_data.get('description')
        saveProduct.category = self.cleaned_data.get('category')
        saveProduct.price = self.cleaned_data.get('price')
        saveProduct.save()
コード例 #6
0
    def commit(self, request):
        '''Process the form action'''
        # get specific product info
        if self.cleaned_data['type'] == 'BulkProduct':
            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')

        if self.cleaned_data['type'] == 'IndividualProduct':
            product = cmod.IndividualProduct()
            product.pid = self.cleaned_data.get('pid')

        if self.cleaned_data['type'] == 'RentalProduct':
            product = cmod.RentalProduct()
            product.pid = self.cleaned_data.get('pid')
            product.retire_date = self.cleaned_data.get('retire_date')
            product.max_rental_days = self.cleaned_data.get('max_rental_days')

        # get the common product info
        product.name = self.cleaned_data.get('name')
        product.description = self.cleaned_data.get('description')
        product.price = self.cleaned_data.get('price')
        product.category = self.cleaned_data.get('category')
        product.status = self.cleaned_data.get('status')

        # save to database
        product.save()
コード例 #7
0
ファイル: create.py プロジェクト: jakefairbairn/fomo
    def commit(self):
        '''Process the form action'''

        #create product and set fields for individual products
        if self.cleaned_data['type'] == "IndividualProduct":
            prod = amod.IndividualProduct()
            prod.pid = self.cleaned_data['pid']

        #create product and set fields for bulk products
        elif self.cleaned_data['type'] == "BulkProduct":
            prod = amod.BulkProduct()
            prod.quantity = self.cleaned_data['quantity']
            prod.reorder_trigger = self.cleaned_data['reorder_trigger']
            prod.reorder_quantity = self.cleaned_data['reorder_quantity']

        #create product and set fields for rental products
        elif self.cleaned_data['type'] == "RentalProduct":
            prod = amod.RentalProduct()
            prod.pid = self.cleaned_data['pid']
            prod.max_rental_days = self.cleaned_data['max_rental_days']
            prod.retire_date = self.cleaned_data['retire_date']

        #set the common fields for all products
        prod.name = self.cleaned_data['name']
        prod.status = self.cleaned_data['status']
        prod.description = self.cleaned_data['description']
        prod.price = self.cleaned_data['price']
        prod.category = self.cleaned_data['category']

        #save the updated data for the objects
        prod.save()
コード例 #8
0
ファイル: tests_1.py プロジェクト: Akokixav/Sprint_3
    def test_product_picture(self):
        """Test the foreign key picture to products"""
        #creates a category
        cat3 = cmod.Category()
        cat3.code = 'string'
        cat3.name = 'String Instruments'
        cat3.save()

        # Creates a bulk product
        bp1 = cmod.BulkProduct()
        bp1.category = cat3
        bp1.name = 'Guitar Strings'
        bp1.brand = 'Gibson'
        bp1.price = Decimal('9.99')
        bp1.quantity = 40
        bp1.reorder_trigger = 10
        bp1.reorder_quantity = 35
        bp1.save()

        #Creates a picture and is a foreign key to the bulk product
        pic1 = cmod.ProductPicture()
        pic1.product = bp1
        pic1.path = 'catalog/media/product_images/gibsonStrings.jpg'
        pic1.altText = 'Guitar Strings1'
        pic1.imageType = 'jpg'
        pic1.save()

        #pull back off of the database
        product1 = cmod.Product.objects.get(id=1)
        picture1path = product1.pictures.all()[0].path
        picture2path = bp1.pictures.all()[0].path
        self.assertEqual(picture1path, picture2path)
コード例 #9
0
ファイル: create.py プロジェクト: jonathanpauda/FOMO
    def commit(self):
       if self.cleaned_data.get('type')=='BulkProduct':
           p1 = cmod.BulkProduct()
           p1.status = self.cleaned_data.get('status')
           p1.name = self.cleaned_data.get('name')
           p1.description = self.cleaned_data.get('description')
           p1.category = self.cleaned_data.get('category')
           p1.price = self.cleaned_data.get('price')
           p1.quantity = self.cleaned_data.get('quantity')
           p1.reorder_trigger = self.cleaned_data.get('reorder_trigger')
           p1.reorder_quantity = self.cleaned_data.get('reorder_quantity')

       elif self.cleaned_data.get('type')=='IndividualProduct':
           p1 = cmod.IndividualProduct()
           p1.status = self.cleaned_data.get('status')
           p1.name = self.cleaned_data.get('name')
           p1.description = self.cleaned_data.get('description')
           p1.category = self.cleaned_data.get('category')
           p1.price = self.cleaned_data.get('price')
           p1.pid = self.cleaned_data.get('pid')

       elif self.cleaned_data.get('type')=='RentalProduct':
           p1 = cmod.RentalProduct()
           p1.status = self.cleaned_data.get('status')
           p1.name = self.cleaned_data.get('name')
           p1.description = self.cleaned_data.get('description')
           p1.category = self.cleaned_data.get('category')
           p1.price = self.cleaned_data.get('price')
           p1.pid = self.cleaned_data.get('pid')
           p1.max_rental_days = self.cleaned_data.get('max_rental_days')
           p1.retire_date = self.cleaned_data.get('retire_date')
       p1.save()
コード例 #10
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()
コード例 #11
0
ファイル: products.py プロジェクト: dvnrsn/CHF
def create(request):
    '''Creates a product'''
    form = CreateForm()
    if request.method == 'POST':  # just submitted the form
        print('submitted form')
        form = CreateForm(request.POST)
        if form.is_valid():
            if form.cleaned_data.get('product_type') == 'BP':
                p = mmod.BulkProduct()
                p.quantity = form.cleaned_data.get('quantity')
            elif form.cleaned_data.get('product_type') == 'IP':
                p = mmod.IndividualProduct()
                p.create_date = form.cleaned_data.get('create_date')
                p.creator = form.cleaned_data.get('creator')
            else:
                p = mmod.RentalProduct()
                p.purchase_date = form.cleaned_data.get('purchase')
                p.status = form.cleaned_data.get('status')

                # if form.cleaned_data.get('status') == 'current':
                #     p.status = 'Rentable'
                # elif form.cleaned_data.get('status') == 'damaged':
                #     p.status = 'Damaged'
                # elif form.cleaned_data.get('status') == 'retired':
                #     print('>>>>>> HERE ')
                #     p.status = 'No Longer Rentable'
                # else:
                #     p.status = 'Dirty'

                # mydict = dict(PRODUCT_TYPE_CHOICES)
                # mydict[""]
                # george = form.cleaned_data['status']
                # hey = mmod.RENTAL_STATUS_CHOICES(george)
                #
                # print('>>>>>>>' + hey)
                #
                # # Let's get the dictionary value of status
                #
                #
                # # george = mmod.RENTAL_STATUS_CHOICES_MAP(george)
                # # print('>>>>>>>' + george)

            p.name = form.cleaned_data.get('name')
            p.description = form.cleaned_data.get('description')
            p.image = form.cleaned_data.ge
            # def get_item(dictionary, key):
            #     return dictionary.get(key)
            # george = form.cleaned_data['status']
            # # mmod.RENTAL_STATUS_CHOICES|get_item:georget('image')
            p.category = mmod.Category.objects.get(id=1)
            p.save()
            return HttpResponseRedirect('/catalog/products')

    template_vars = {
        'form': form,
    }
    return dmp_render_to_response(request, 'products.create.html',
                                  template_vars)
コード例 #12
0
    def commit(self):
        ''' Save the product if it's new. Get the product and change it if it's edit.'''

        # Get all the generic data
        type = self.cleaned_data.get('Type')
        category = cmod.Category.objects.get(
            Name=self.cleaned_data.get('Category'))
        name = self.cleaned_data.get('Name')
        description = self.cleaned_data.get('Description')
        price = self.cleaned_data.get('Price')
        status = self.cleaned_data.get('Status')
        qty = self.cleaned_data.get('Quantity')
        reorderTrigger = self.cleaned_data.get('ReorderTrigger')
        reorderQuantity = self.cleaned_data.get('ReorderQuantity')
        itemID = self.cleaned_data.get('ItemID')
        maxRental = self.cleaned_data.get('MaxRental')
        retireDate = self.cleaned_data.get('RetireDate')

        # Create the product
        if type == 'BulkProduct':
            if self.product_id < 0:
                bProduct = cmod.BulkProduct()
            else:
                bProduct = self.product
            bProduct.new_object(name, description, category, price, status)
            bProduct.Quantity = qty
            bProduct.ReorderTrigger = reorderTrigger
            bProduct.ReorderQuantity = reorderQuantity

            bProduct.save()

        if type == 'IndividualProduct':
            if self.product_id < 0:
                iProduct = cmod.IndividualProduct()
            else:
                iProduct = self.product
            iProduct.new_object(name, description, category, price, status)
            iProduct.ItemID = itemID

            iProduct.save()

        if type == 'RentalProduct':
            if self.product_id < 0:
                rProduct = cmod.RentalProduct()
            else:
                rProduct = self.product
            rProduct.new_object(name, description, category, price, status)
            rProduct.ItemID = itemID
            rProduct.MaxRental = maxRental
            rProduct.RetireDate = retireDate

            rProduct.save()
コード例 #13
0
    def commit(self):

        if self.cleaned_data.get('TYPE_CHOICES') == '1':
            b1 = cmod.BulkProduct()

            b1.status = self.cleaned_data.get('status')
            b1.name = self.cleaned_data.get('name')
            b1.description = self.cleaned_data.get('description')
            b1.category = self.cleaned_data.get('category')
            b1.price = self.cleaned_data.get('price')

            b1.reorder_quantity = self.cleaned_data.get('reorder_quantity')
            b1.reorder_trigger = self.cleaned_data.get('reorder_trigger')
            b1.quantity = self.cleaned_data.get('quantity')

            b1.save()

        elif self.cleaned_data.get('TYPE_CHOICES') == '2':
            i1 = cmod.IndividualProduct()

            i1.status = self.cleaned_data.get('status')
            i1.name = self.cleaned_data.get('name')
            i1.description = self.cleaned_data.get('description')
            i1.category = self.cleaned_data.get('category')
            i1.price = self.cleaned_data.get('price')

            i1.pid = self.cleaned_data.get('pid')

            i1.save()

        elif self.cleaned_data.get('TYPE_CHOICES') == '3':
            r1 = cmod.RentalProduct()

            r1.status = self.cleaned_data.get('status')
            r1.name = self.cleaned_data.get('name')
            r1.description = self.cleaned_data.get('description')
            r1.category = self.cleaned_data.get('category')
            r1.price = self.cleaned_data.get('price')

            r1.pid = self.cleaned_data.get('pid')
            r1.max_rental_days = self.cleaned_data.get('max_rental_days')
            r1.retire_date = self.cleaned_data.get('retire_date')

            r1.save()
        else:
            pass
コード例 #14
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()
コード例 #15
0
    def commit(self):
        #self.cleaned_data.title

        if (self.cleaned_data.get('type') == 'IndividualProduct'):
            myProduct = cmod.IndividualProduct()
            myProduct.TITLE = self.cleaned_data.get('title')
            myProduct.status = self.cleaned_data.get('status')
            myProduct.name = self.cleaned_data.get('name')
            myProduct.description = self.cleaned_data.get('description')
            myProduct.category = self.cleaned_data.get('category')
            myProduct.price = self.cleaned_data.get('price')
            myProduct.pid = self.cleaned_data.get('pid')
            myProduct.save()

        elif (self.cleaned_data.get('type') == 'RentalProduct'):
            myProduct = cmod.RentalProduct()
            myProduct.TITLE = self.cleaned_data.get('title')
            myProduct.status = self.cleaned_data.get('status')
            myProduct.name = self.cleaned_data.get('name')
            myProduct.description = self.cleaned_data.get('description')
            myProduct.category = self.cleaned_data.get('category')
            myProduct.price = self.cleaned_data.get('price')
            myProduct.max_rental_days = self.cleaned_data.get(
                'max_rental_days')
            myProduct.retire_date = self.cleaned_data.get('retire_date')
            myProduct.save()

        else:
            myProduct = cmod.BulkProduct()
            myProduct.TITLE = self.cleaned_data.get('title')
            myProduct.status = self.cleaned_data.get('status')
            myProduct.name = self.cleaned_data.get('name')
            myProduct.description = self.cleaned_data.get('description')
            myProduct.category = self.cleaned_data.get('category')
            myProduct.price = self.cleaned_data.get('price')
            myProduct.quantity = self.cleaned_data.get('quantity')
            myProduct.reorder_trigger = self.cleaned_data.get(
                'reorder_trigger')
            myProduct.reorder_quantity = self.cleaned_data.get(
                'reorder_quantity')
            myProduct.save()

        HttpResponseRedirect('/catalog/templates/product.html')
コード例 #16
0
ファイル: createProduct.py プロジェクト: rem-rogers/FOMO
 def commit(self):
     type = self.cleaned_data.get('type')
     if type == 'IndividualProduct':
         self.product = cmod.IndividualProduct()
         self.product.create_date = self.cleaned_data.get('created_date')
         self.product.last_modified = self.cleaned_data.get('last_modified')
         self.product.name = self.cleaned_data.get('name')
         self.product.description = self.cleaned_data.get('description')
         self.product.status = self.cleaned_data.get('status')
         self.product.category = self.cleaned_data.get('category')
         self.product.price = self.cleaned_data.get('price')
         #unique
         self.product.pid = self.cleaned_data.get('pid')
     elif type == 'BulkProduct':
         self.product = cmod.BulkProduct()
         self.product.create_date = self.cleaned_data.get('created_date')
         self.product.last_modified = self.cleaned_data.get('last_modified')
         self.product.name = self.cleaned_data.get('name')
         self.product.description = self.cleaned_data.get('description')
         self.product.status = self.cleaned_data.get('status')
         self.product.category = self.cleaned_data.get('category')
         self.product.price = self.cleaned_data.get('price')
         # unique
         self.product.quantity = self.cleaned_data.get('quantity')
         self.product.reorder_trigger = self.cleaned_data.get(
             'reorder_trigger')
         self.product.reorder_quantity = self.cleaned_data.get(
             'reorder_quantity')
     elif type == 'RentalProduct':
         self.product = cmod.RentalProduct()
         self.product.create_date = self.cleaned_data.get('created_date')
         self.product.last_modified = self.cleaned_data.get('last_modified')
         self.product.name = self.cleaned_data.get('name')
         self.product.description = self.cleaned_data.get('description')
         self.product.status = self.cleaned_data.get('status')
         self.product.category = self.cleaned_data.get('category')
         self.product.price = self.cleaned_data.get('price')
         #unique
         self.product.pid = self.cleaned_data.get('pid')
         self.product.max_rental_days = self.cleaned_data.get(
             'max_rental_days')
         self.product.retire_date = self.cleaned_data.get('retire_date')
     self.product.save()
コード例 #17
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
コード例 #18
0
    def test_create_a_Bulk_Product(self):
        ## Will create a category and a Bulk 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
        cat4 = cmod.Category()
        cat4.codename = 'ac'
        cat4.name = 'Accessories'
        cat4.save()

        # Create a Bulk Product
        p3 = cmod.BulkProduct()
        p3.name = 'Sheet Music 1'
        p3.category = cat4
        p3.price = Decimal('9.50')
        p3.quantity = 20
        p3.reorder_trigger = 5
        p3.reorder_quantity = 30
        dList = ['Holy sheet music', 'From Beethoven to T-swizzle']
        p3.descriptionList = json.dumps(dList)
        iList = [
            '/static/homepage/media/img/sh1.jpg',
            '/static/homepage/media/img/sh2.jpg',
            '/static/homepage/media/img/sh3.png'
        ]
        p3.imgList = json.dumps(iList)
        p3.save()

        p4 = cmod.Product.objects.get(id=p3.id)
        self.assertEquals(p4.name, 'Sheet Music 1')
        self.assertEquals(p4.category, cat4)
        self.assertEquals(p4.price, Decimal('9.50'))
        self.assertEquals(p4.descriptionList, json.dumps(dList))
        self.assertEquals(p4.imgList, json.dumps(iList))
        self.assertEquals(p4.quantity, 20)
        self.assertEquals(p4.reorder_quantity, 30)
        self.assertEquals(p4.reorder_trigger, 5)
コード例 #19
0
    def commit(self):

        if self.cleaned_data.get('title') == 'BulkProduct':
            p = cmod.BulkProduct()
            p.quantity = self.cleaned_data['quantity']
            p.reorder_trigger = self.cleaned_data['reorder_trigger']
            p.reorder_quantity = self.cleaned_data['reorder_quantity']
        elif self.cleaned_data.get('title') == 'RentalProduct':
            p = cmod.RentalProduct()
            p.max_rental_days = self.cleaned_data['max_rental_days']
            p.retire_date = self.cleaned_data['retire_date']
            p.pid = self.cleaned_data['pid']
        elif self.cleaned_data.get('title') == 'IndividualProduct':
            p = cmod.IndividualProduct()
            p.pid = self.cleaned_data['pid']

        p.TITLE = self.cleaned_data['title']
        p.name = self.cleaned_data['name']
        p.description = self.cleaned_data['description']
        p.category = self.cleaned_data['category']
        p.price = self.cleaned_data['price']
        p.status = self.cleaned_data['status']
        p.save()
コード例 #20
0
 def commit(self):
     print(self.cleaned_data.get('type'))
     if self.cleaned_data.get('type') == 'BulkProduct':
         print('success')
         newProduct = cmod.BulkProduct()
         newProduct.name = self.cleaned_data.get('name')
         newProduct.category = self.cleaned_data.get('category')
         newProduct.description = self.cleaned_data.get('description')
         newProduct.price = self.cleaned_data.get('price')
         newProduct.status = self.cleaned_data.get('status')
         newProduct.quantity = self.cleaned_data.get('quantity')
         newProduct.reorder_trigger = self.cleaned_data.get(
             'reorder_trigger')
         newProduct.reorder_quantity = self.cleaned_data.get(
             'reorder_quantity')
         newProduct.save()
         print(newProduct.id)
     elif self.cleaned_data.get('type') == 'IndividualProduct':
         newProduct = cmod.IndividualProduct()
         newProduct.category = self.cleaned_data.get('category')
         newProduct.name = self.cleaned_data.get('name')
         newProduct.description = self.cleaned_data.get('description')
         newProduct.price = self.cleaned_data.get('price')
         newProduct.status = self.cleaned_data.get('status')
         newProduct.itemID = self.cleaned_data.get('itemID')
         newProduct.save()
     elif self.cleaned_data.get('type') == 'RentalProduct':
         newProduct = cmod.RentalProduct()
         newProduct.category = self.cleaned_data.get('category')
         newProduct.name = self.cleaned_data.get('name')
         newProduct.description = self.cleaned_data.get('description')
         newProduct.price = self.cleaned_data.get('price')
         newProduct.status = self.cleaned_data.get('status')
         newProduct.itemID = self.cleaned_data.get('itemID')
         newProduct.maxRental = self.cleaned_data.get('maxRental')
         newProduct.retireDate = self.cleaned_data.get('retireDate')
         newProduct.save()
コード例 #21
0
ファイル: edit.py プロジェクト: jareddb/411_413Repo
def process_request(request):
    try:
        product = cmod.Product.objects.get(id=request.urlparams[0])
        new = False
    except:
        product = cmod.BulkProduct(name='',
                                   status='A',
                                   description='',
                                   category=cmod.Category(name='Brass'),
                                   price=0)
        product.TITLE = 'Bulk'
        new = True

    if request.urlparams[0] == 'submit':
        new = False

    # process the form
    form = EditForm(request, product, new)
    if form.is_valid():
        form.commit(product)
        return HttpResponseRedirect('/manager/products')

    # render the template
    return request.dmp_render('edit.html', {'form': form})
コード例 #22
0
def create(request):
    form = createproduct_form()
    if request.method == "POST":
        form = createproduct_form(request.POST)
        if form.is_valid():
            if form.cleaned_data.get('productType') == 'indproduct':
                p = cmod.IndividualProduct()
                p.creationDate = form.cleaned_data.get('creationDate')
                p.customizationNotes = form.cleaned_data.get(
                    'customizationNotes')
            elif form.cleaned_data.get('productType') == 'bulkproduct':
                p = cmod.BulkProduct()
                p.currentBulkPrice = form.cleaned_data.get('currentBulkPrice')
                p.quantityAvailable = form.cleaned_data.get(
                    'quantityAvailable')
            elif form.cleaned_data.get('productType') == 'rentalprdoduct':
                p = cmod.RentalProduct()
                p.currentRentalRate = form.cleaned_data.get(
                    'currentRentalRate')
                p.available = form.cleaned_data.get('available')
            p.name = form.cleaned_data.get('name')
            p.description = form.cleaned_data.get('description')
            p.replacementValue = form.cleaned_data.get('replacementValue')
            p.photoFileName = form.cleaned_data.get('photoFileName')
            p.size = form.cleaned_data.get('size')
            p.weight = form.cleaned_data.get('weight')
            p.save()
            return HttpResponse('''
            <script>
                window.location.reload();
            </script>
            ''')
    template_vars = {
        'form': form,
    }
    return dmp_render_to_response(request, 'createproduct.html', template_vars)
コード例 #23
0
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()
#end of category creation

#Bulk Products
bp1 = cmod.BulkProduct()
bp1.category = cat3
bp1.name = 'Guitar Strings'
bp1.brand = 'Gibson'
bp1.price = Decimal('15.50')
bp1.quantity = 40
bp1.reorder_trigger = 10
bp1.reorder_quantity = 30
bp1.serial_number = 'jopih78'
bp1.save()

bp2 = cmod.BulkProduct()
bp2.category = cat1
bp2.name = 'Trumpet Mouthpiece'
bp2.brand = 'Yamaha'
bp2.price = Decimal('25.00')
コード例 #24
0
def commit(self):
    '''Process form action'''
    type = self.cleaned_data.get('type')
    # if type == 'BulkProduct':
    #     self.product = cmod.BulkProduct()
    #     # unique
    #     self.product.quantity = self.cleaned_data.get('quantity')
    #     self.product.reorder_trigger = self.cleaned_data.get('reorder_trigger')
    #     self.product.reorder_quantity = self.cleaned_data.get('reorder_quantity')
    # elif type == 'IndividualProduct':
    #     self.product = cmod.IndividualProduct()
    #     # unique
    #     self.product.pid = self.cleaned_data.get('pid')
    # elif type == 'RentalProduct':
    #     self.product = cmod.RentalProduct()
    #     # unique
    #     self.product.pid = self.cleaned_data.get('pid')
    #     self.product.max_rental_days = self.cleaned_data.get('max_rental_days')
    #     self.product.retire_date = self.cleaned_data.get('retire_date')
    #
    # # Generic product information
    # self.product.create_date = self.cleaned_data.get('created_date')
    # self.product.last_modified = self.cleaned_data.get('last_modified')
    # self.product.name = self.cleaned_data.get('name')
    # self.product.description = self.cleaned_data.get('description')
    # self.product.status = self.cleaned_data.get('status')
    # self.product.category = self.cleaned_data.get('category')
    # self.product.price = self.cleaned_data.get('price')

    # Save
    # self.product.save()

    # Try this way?
    if type == 'IndividualProduct':
        self.product = cmod.IndividualProduct()
        self.product.create_date = self.cleaned_data.get('create_date')
        self.product.last_modified = self.cleaned_data.get('last_modified')
        self.product.status = self.cleaned_data.get('status')
        self.product.name = self.cleaned_data.get('name')
        self.product.description = self.cleaned_data.get('description')
        self.product.category = self.cleaned_data.get('category')
        self.product.price = self.cleaned_data.get('price')
        #   unique fields
        self.product.pid = self.cleaned_data.get('pid')
    elif type == 'BulkProduct':
        self.product = cmod.BulkProduct()
        self.product.create_date = self.cleaned_data.get('create_date')
        self.product.last_modified = self.cleaned_data.get('last_modified')
        self.product.status = self.cleaned_data.get('status')
        self.product.name = self.cleaned_data.get('name')
        self.product.description = self.cleaned_data.get('description')
        self.product.category = self.cleaned_data.get('category')
        self.product.price = self.cleaned_data.get('price')
        #   unique fields
        self.product.quantity = self.cleaned_data.get('quantity')
        self.product.reorder_trigger = self.cleaned_data.get('reorder_trigger')
        self.product.reorder_quantity = self.cleaned_data.get('reorder_quantity')
    elif type == 'RentalProduct':
        self.product = cmod.RentalProduct()
        self.product.create_date = self.cleaned_data.get('create_date')
        self.product.last_modified = self.cleaned_data.get('last_modified')
        self.product.status = self.cleaned_data.get('status')
        self.product.name = self.cleaned_data.get('name')
        self.product.description = self.cleaned_data.get('description')
        self.product.category = self.cleaned_data.get('category')
        self.product.price = self.cleaned_data.get('price')
        #   unique fields
        self.product.pid = self.cleaned_data.get('pid')
        self.product.max_rental_days = self.cleaned_data.get('max_rental_days')
        self.product.retire_date = self.cleaned_data.get('retire_date')
    self.product.save()
コード例 #25
0
def edit(request):

    try:
        p = cmod.Product.objects.get(id=int(request.urlparams[0]))
    except cmod.Product.DoesNotExist as e:
        return HttpResponseRedirect('/catalog/products')

    if request.method != "POST":
        if request.urlparams[1] == 'indproduct':
            form = edit_form(
                initial={
                    'name': p.name,
                    'description': p.description,
                    'replacementValue': p.replacementValue,
                    'photoFileName': p.photoFileName,
                    'size': p.size,
                    'weight': p.weight,
                    'creationDate': p.creationDate,
                    'customizationNotes': p.customizationNotes,
                })
            ptype = 'indproduct'
        elif request.urlparams[1] == 'bulkproduct':
            form = edit_form(
                initial={
                    'name': p.name,
                    'description': p.description,
                    'replacementValue': p.replacementValue,
                    'photoFileName': p.photoFileName,
                    'size': p.size,
                    'weight': p.weight,
                    'currentBulkPrice': p.currentBulkPrice,
                    'quantityAvailable': p.quantityAvailable,
                })
            ptype = 'bulkproduct'
        elif request.urlparams[1] == 'rentalproduct':
            form = edit_form(
                initial={
                    'name': p.name,
                    'description': p.description,
                    'replacementValue': p.replacementValue,
                    'photoFileName': p.photoFileName,
                    'size': p.size,
                    'weight': p.weight,
                    'currentRentalRate': p.currentRentalRate,
                    'available': p.available,
                })
            ptype = 'rentalproduct'

    if request.method == "POST":
        form = edit_form(request.POST)
        if form.is_valid():
            if form.cleaned_data.get('productType') == 'indproduct':
                p = cmod.IndividualProduct()
                p.creationDate = form.cleaned_data.get('creationDate')
                p.customizationNotes = form.cleaned_data.get(
                    'customizationNotes')
            elif form.cleaned_data.get('productType') == 'bulkproduct':
                p = cmod.BulkProduct()
                p.currentBulkPrice = form.cleaned_data.get('currentBulkPrice')
                p.quantityAvailable = form.cleaned_data.get(
                    'quantityAvailable')
            elif form.cleaned_data.get('productType') == 'rentalproduct':
                p = cmod.RentalProduct()
                p.currentRentalRate = form.cleaned_data.get(
                    'currentRentalRate')
                p.available = form.cleaned_data.get('available')
            p.name = form.cleaned_data.get('name')
            p.description = form.cleaned_data.get('description')
            p.replacementValue = form.cleaned_data.get('replacementValue')
            p.photoFileName = form.cleaned_data.get('photoFileName')
            p.size = form.cleaned_data.get('size')
            p.weight = form.cleaned_data.get('weight')
            p.save()
            return HttpResponseRedirect('/catalog/products')
            # return HttpResponse('''
            # <script>
            #     window.location.reload();
            # </script>
            # ''')

    #products = cmod.Product.objects.all().order_by('last_name','first_name')
    template_vars = {
        'form': form,
        'productid': p.id,
        'ptype': ptype,
    }
    return dmp_render_to_response(request, 'editproduct.html', template_vars)
コード例 #26
0
    'Trumpet forged in the fires of Mount Doom', 'Isuldurs Bane',
    'The instrument to rule them all', 'It is shiny'
]
p3.descriptionList = json.dumps(dList)
iList = [
    '/static/homepage/media/img/trump1.jpg',
    '/static/homepage/media/img/trump2.jpg',
    '/static/homepage/media/img/trump3.png',
    '/static/homepage/media/img/trump4.png'
]
p3.imgList = json.dumps(iList)
p3.available = True
p3.save()

# Create a Bulk Product
p4 = cmod.BulkProduct()
p4.name = 'Sheet Music 1'
p4.category = cat4
p4.price = Decimal('9.50')
p4.quantity = 20
p4.reorder_trigger = 5
p4.reorder_quantity = 30
dList = ['Holy sheet music', 'From Beethoven to T-swizzle']
p4.descriptionList = json.dumps(dList)
iList = [
    '/static/homepage/media/img/sh1.jpg', '/static/homepage/media/img/sh2.jpg',
    '/static/homepage/media/img/sh3.png'
]
p4.imgList = json.dumps(iList)
p4.save()
コード例 #27
0
cat3.code = 'strings'
cat3.name = 'String Instruments'
cat3.save()

cat4 = cmod.Category()
cat4.code = 'accessory'
cat4.name = 'Accessories'
cat4.save()

cat5 = cmod.Category()
cat5.code = 'percussion'
cat5.name = 'Percussion Instruments'
cat5.save()

#Create Products
bp1 = cmod.BulkProduct()
bp1.category = cat4
bp1.name = 'Bassoon Reed'
bp1.brand = 'Singin Dog'
bp1.price = Decimal('33.99')
bp1.quantity = 20
bp1.reorder_trigger = 5
bp1.reorder_qty = 15
bp1.path = '/static/homepage/media/images/instruments/accessories/bassoon_reed.png'
bp1.desc = "The Singin' Dog Reed is designed for young students or beginners. Medium soft. Hand finished."
bp1.save()

pp1 = cmod.ProductPicture()
pp1.product = bp1
pp1.path = '/static/homepage/media/images/instruments/accessories/bassoon_reed.png'
pp1.save()
コード例 #28
0
# categories
print('Creating categories...')

categories = []
for catname in ('Instruments', 'Sheet Music', 'Electronics', 'Software',
                'Lesson Books'):
    c = cmod.Category()
    c.name = catname
    c.description = 'This is a category named {}'.format(catname)
    c.save()
    categories.append(c)

# products
print('Creating products...')
for i in range(1, 25):
    p = cmod.BulkProduct()
    p.name = 'unset'  # see image adding below
    p.description = 'unset'
    p.category = random.choice(categories)
    p.status = 'A'
    p.price = random.uniform(1, 1000)
    p.reorder_trigger = random.randint(5, 15)
    p.quantity = random.randint(p.reorder_trigger, 2 * p.reorder_trigger)
    p.reorder_quantity = p.reorder_trigger * 2
    p.save()
for i in range(1, 25):
    p = cmod.RentalProduct()
    p.name = 'unset'  # see image adding below
    p.description = 'unset'
    p.category = random.choice(categories)
    p.status = 'A'
コード例 #29
0
        [dir + 'violin_string_set.jpg', 'jpg', True],
        [dir + 'violin_string_set_1.jpg', 'jpg', False],
    ], [
        "The best quality violins come with the best strings possible but even the best strings in the world will need replacing throughout a violinist’s playing career. Our strings are great quality and guaranteed to produce excellent sound. "
    ]),
    ('Triangle', 'percussion', 'Squares Are For Squares', Decimal(
        '8.99'
    ), 15, 5, 10, [
        [dir + 'triangle.jpg', 'jpg', True],
        [dir + 'triangle_1.jpg', 'jpg', False],
        [dir + 'triangle_2.jpg', 'jpg', False],
    ], [
        "The coolest instrument around. Everyone can use a little more triangle in their life."
    ]),
):
    bulk_product = cmod.BulkProduct()
    bulk_product.name = data[0]
    bulk_product.category = cmod.Category.objects.get(codename__exact=data[1])
    bulk_product.brand = data[2]
    bulk_product.price = data[3]
    bulk_product.quantity = data[4]
    bulk_product.reorder_point = data[5]
    bulk_product.reorder_quantity = data[6]
    bulk_product.description = data[8][0]
    bulk_product.save()
    sh.add(user, bulk_product)
    for img in data[7]:
        product_image = cmod.ProductImage()
        product_image.product = bulk_product
        product_image.subdir = img[0]
        product_image.alttext = bulk_product.name