def new_product(request):
    noForwardedsInfo(request)
    context = {}

    if request.method == 'GET':
        form = ProductForm()
        context['form'] = form
        return render(request, 'dashboard_admin/new_product.html', context)
    else:
        form = ProductForm(request.POST, request.FILES)
        if form.is_valid():
            value = Utils.convertStringForNumber(request.POST.get('value'))
            product = Product()
            product.name = form.cleaned_data['name']
            product.description = form.cleaned_data['description']
            product.image = form.cleaned_data['image']
            product.value = value
            product.brand = form.cleaned_data['brand']
            product.category = form.cleaned_data['category']
            product.save()
            messages.success(request, "Novo Produto salvo com sucesso!")
        else:
            messages.warning(request,
                             "Por favor, preencha os campos corretamente!")
        context['form'] = form

        return HttpResponseRedirect(
            reverse('dashboard_admin:show_all_products'))
예제 #2
0
    def get_or_create_rate_chart(self, listing_id):
        try:
            rate_chart_map = ListingRateChartMap.objects.get(
                listing_id=listing_id)
            if rate_chart_map.rate_chart:
                return rate_chart_map.rate_chart
        except ListingRateChartMap.DoesNotExist:
            pass

        results = listing_solr_search('id:%s' % listing_id)
        if results and results.results and len(results.results) > 0:
            listing = results.results[0]
            product = Product()
            product.title = listing.get('title', '')
            product.description = listing.get('description', '')
            product.currency = listing.get('currency', 'inr')
            product.brand = self.get_other_brand('Other')
            product.model = ''
            product.category = self.get_other_category('Other')
            product.type = 'normal'
            product.status = 'unavailable'
            product.save()

            rate_chart = SellerRateChart()
            rate_chart.listing_id = listing_id
            rate_chart.product = product
            rate_chart.seller = self.get_seller(listing.get('userId', 0))
            rate_chart.status = 'unavailable'
            rate_chart.sku = listing.get('sku', '')
            rate_chart.condition = 'new'
            rate_chart.is_prefered = True
            rate_chart.list_price = Decimal(str(listing.get('mrp', 0)))
            rate_chart.offer_price = Decimal(str(listing.get('askingPrice',
                                                             0)))
            if rate_chart.offer_price > rate_chart.list_price:
                rate_chart.list_price = rate_chart.offer_price
            rate_chart.warranty = listing.get('warranty', '')
            rate_chart.gift_title = listing.get('gifts', '')
            rate_chart.shipping_charges = Decimal(
                str(listing.get('shippingCharges', '0.0')))
            rate_chart.shipping_duration = listing.get('shippingDuration',
                                                       '7-10 working days')
            rate_chart.availability = self.get_available_every_where()
            rate_chart.stock_status = 'notavailable'
            rate_chart.status = 'deleted'
            rate_chart.save()

            listing_rate_chart_map = ListingRateChartMap(listing_id=listing_id,
                                                         rate_chart=rate_chart)
            listing_rate_chart_map.save()

            return rate_chart

        return None
예제 #3
0
    def get_or_create_rate_chart(self, listing_id):
        try:
            rate_chart_map = ListingRateChartMap.objects.get(
                    listing_id = listing_id)
            if rate_chart_map.rate_chart:
                return rate_chart_map.rate_chart
        except ListingRateChartMap.DoesNotExist:
            pass

        results = listing_solr_search('id:%s' % listing_id)
        if results and results.results and len(results.results) > 0:
            listing = results.results[0]
            product = Product()
            product.title = listing.get('title','')
            product.description = listing.get('description','')
            product.currency = listing.get('currency','inr')
            product.brand = self.get_other_brand('Other')
            product.model = ''
            product.category = self.get_other_category('Other')
            product.type = 'normal'
            product.status = 'unavailable'
            product.save()

            rate_chart = SellerRateChart()
            rate_chart.listing_id = listing_id
            rate_chart.product = product
            rate_chart.seller = self.get_seller(listing.get('userId',0))
            rate_chart.status = 'unavailable'
            rate_chart.sku = listing.get('sku', '')
            rate_chart.condition = 'new'
            rate_chart.is_prefered = True
            rate_chart.list_price = Decimal(str(listing.get('mrp',0)))
            rate_chart.offer_price = Decimal(str(listing.get('askingPrice',0)))
            if rate_chart.offer_price > rate_chart.list_price:
                rate_chart.list_price = rate_chart.offer_price
            rate_chart.warranty = listing.get('warranty','')
            rate_chart.gift_title = listing.get('gifts','')
            rate_chart.shipping_charges = Decimal(str(listing.get('shippingCharges','0.0')))
            rate_chart.shipping_duration = listing.get('shippingDuration','7-10 working days')
            rate_chart.availability = self.get_available_every_where()
            rate_chart.stock_status = 'notavailable'
            rate_chart.status = 'deleted'
            rate_chart.save()

            listing_rate_chart_map = ListingRateChartMap(listing_id=listing_id, rate_chart=rate_chart)
            listing_rate_chart_map.save()

            return rate_chart

        return None
예제 #4
0
파일: feed.py 프로젝트: daasara/riba
    def create_master_product(self, data, sync, product=None, is_update=False):
        if not product:
            product = Product()
        product.title = data['cleaned_data']['title']
        product.description = data['cleaned_data']['detailed_desc'] or data['cleaned_data']['description']
        product.brand = data['cleaned_data']['brand']
        product.category = data['cleaned_data']['category']
        product.slug = slugify(product.title)[:150]
        product.model = data['cleaned_data']['model']
        product.moderate = True
        product.currency = data['cleaned_data'].get('currency','inr')
        product.type = data['cleaned_data'].get('product_type','normal')
        product.product_type = self.get_mapped_sku_type(data['cleaned_data'].get('sku_type',''))
        if data['cleaned_data'].get('video',''):
            product.video_embed = data['cleaned_data']['video']

        #If the category belongs to BLACKLIST_CATEGORIES, then set product.status = 'deactive'
        #else product.status = data['cleaned_data']['status']
        category = data['cleaned_data']['category']
        if str(category.ext_id) in getattr(settings, 'BLACKLIST_CATEGORIES', []):
            product.status = 'deactive'
        elif data['cleaned_data']['status'] in ['active','deactive','deleted']:
            product.status = data['cleaned_data']['status']

        product.save(using='default')
        product.productimage_set.using('default').all().delete()

        if self.download_images:
            # download the image
            for url in data['cleaned_data']['image_url']:
                try:
                    feedutils.attach_image_to_product(product,url)
                except Exception, e:
                    log.exception(
                            'Error adding image to product %s from %s: %s' % (
                                product.id, data['cleaned_data']['image_url'],
                                repr(e)))
예제 #5
0
    def handle(self, *args, **options):
        print("Add products")
        file_name = os.path.join(settings.BASE_DIR, 'termos.xls')
        book = xlrd.open_workbook(file_name)
        sh = book.sheet_by_index(0)
        print("{0} {1} {2}".format(sh.name, sh.nrows, sh.ncols))
        print("Cell D30 is {0}".format(sh.cell_value(rowx=29, colx=5)))

        _root, _ = Category.objects.get_or_create(name='_root',
                                                  slug='root',
                                                  parent=None)

        categories = set()
        products = []
        artikuls = []
        for rx in range(sh.nrows):
            if rx == 0:
                continue
            curr_cat = sh.cell_value(rowx=rx, colx=5)
            categories.add(curr_cat)
            product_name = sh.cell_value(rowx=rx, colx=1)
            product_artikul = sh.cell_value(rowx=rx, colx=0)
            img_url = sh.cell_value(rowx=rx, colx=15)
            price_opt = sh.cell_value(rowx=rx, colx=16)
            price = sh.cell_value(rowx=rx, colx=17)
            old_price = sh.cell_value(rowx=rx, colx=18)

            products.append({
                'name': product_name,
                'artikul': product_artikul,
                'img_url': img_url,
                'price_opt': price_opt,
                'price': price,
                'old_price': old_price,
                'category_name': curr_cat,
                'category_slug': slugify(curr_cat),
            })

        for category in categories:
            sl_curr_cat = slugify(category)
            ext_cat = Category.objects.filter(slug=sl_curr_cat).first()
            if not ext_cat:
                new_cat = Category()
                new_cat.name = category
                new_cat.slug = sl_curr_cat
                new_cat.parent = _root
                new_cat.save()

        for prod in products:
            # print(prod.get('name'))
            try:
                artikul = prod.get('artikul')
                ext_prod = Product.objects.filter(artikul=artikul).first()
                if not ext_prod:
                    need_category = Category.objects.filter(
                        slug=prod.get('category_slug')).first()
                    # print(need_category)
                    new_prod = Product()
                    new_prod.name = prod.get('name')
                    new_prod.slug = slugify(prod.get('name'))
                    new_prod.artikul = artikul
                    new_prod.category = need_category
                    new_prod.save()
                    print(new_prod.pk)
                else:
                    ext_prod.price_opt = prod.get('price_opt')
                    ext_prod.price = prod.get('price')
                    ext_prod.old_price = prod.get('old_price')
                    if not ext_prod.img:
                        ext_prod.img = self.add_image(prod.get('img_url'))
                    ext_prod.save()
            except Exception as e:
                print(str(e))
예제 #6
0
def process_request(request, p: m.Product=None):
    if request.user.is_superuser:
        if request.method == 'GET':
            if type(p) is m.BulkProduct:
                t = "1"
            elif type(p) is m.IndividualProduct:
                t = "2"
            elif type(p) is m.RentalProduct:
                t = "3"

            form = ProductForm(request, initial={
                'id': p.id,
                'type': t,
                'name': p.name,
                'price': p.price,
                'status': 'Active' if p.status == '1' else 'Inactive',
                'description': p.description,
                'category': p.category.name,
                'imageFile': m.ProductImage.objects.all().first().filename,
                # unique fields
                'unit': p.unit if type(p) is m.BulkProduct else None,
                'order_trigger': p.order_trigger if type(p) is m.BulkProduct else None,
                'order_quantity': p.order_quantity if type(p) is m.BulkProduct else None,
                'rental_period': p.rental_period if type(p) is m.RentalProduct else None,
                'retire_date': p.retire_date if type(p) is m.RentalProduct else None,
                })
        elif request.method == 'POST':
            form = ProductForm(request)

        if form.is_valid():
            p = m.Product.objects.get(id=int(request.dmp.urlparams[0]))

            # unbind images
            m.ProductImage.objects.filter(product_id=p.id).delete()

            p.name = form.cleaned_data.get('name')
            p.price = form.cleaned_data.get('price')
            p.status = form.cleaned_data.get('status')
            p.description = form.cleaned_data.get('description')
            p.category = form.cleaned_data.get('category')

            if form.cleaned_data.get('type') == '1':
                p.unit = form.cleaned_data.get('unit')
                p.order_trigger = form.cleaned_data.get('order_trigger')
                p.order_quantity = form.cleaned_data.get('order_quantity')
            if form.cleaned_data.get('type') == '2':
                pass
            if form.cleaned_data.get('type') == '3':
                p.rental_period = form.cleaned_data.get('rental_period')
                p.retire_date = form.cleaned_data.get('retire_date')

            p.save()

            myfiles = request.FILES.getlist('imageFile')
            fs = FileSystemStorage(location="catalog/media/products/")
            for myfile in myfiles:
                filename = fs.save(myfile.name, myfile)
                fs.url(filename)
                form.bind_images(myfile, p.id)

            return HttpResponseRedirect('/manager/')

        context = {
            'form': form,
            'id': p.id
        }

        return request.dmp.render('edit.html', context)
    else:
        return HttpResponseRedirect('/index/')