예제 #1
0
파일: views.py 프로젝트: tesluk/basata_shop
def add_prod (request, tp_id): 
    tp = Product_type.objects.all().get(id=tp_id)
    pr = Product()
    pr.prod_type = tp
    pr.name = request.POST['name']
    pr.producer = request.POST['producer']
    pr.quantity = request.POST['quantity']
    pr.sdescription = request.POST['sdescr']
    if 'picture' in request.FILES:
        pr.picture = request.FILES['picture']
        if 'userfile' in request.FILES:
            pr.model = request.FILES['userfile']
            pr.save()
            new_name = 'Entities/static/products/models_' + str(tp.group.id) + '_' + str(tp.id) + '_' + str(pr.id) + '.dae'
            for i in range(2):   
                try:                    
                    os.rename(str(pr.model), new_name)
                    pr.model = new_name
                    break;
                except:
                    os.remove(new_name) 
        else: 
            pr.model = 'Entities/static/products/banana.dae';  

        pr.save() 
        typ = str(pr.picture).split('.') 
        new_name = 'Entities/static/products/img_' + str(tp.group.id) + '_' + str(tp.id) + '_' + str(pr.id)
        t = '.' + typ[len(typ) - 1] 
        add_picture(pr, new_name, t)
    else: 
        pr.picture = 'Entities/static/products/standart.png';  
  
    pr.save()
    price = Price()
    price.value = request.POST['price']
    price.product = pr
    price.date_init = datetime.today().date()
    price.save()       
    ch = Characteristic()
    chr_name = 'ch' + str(1) + '_name' 
    i = 1
    while chr_name in request.POST:
        ch = Characteristic()
        ch.product = pr;
        ch.name = request.POST[chr_name]
        ch.description = request.POST['ch' + str(i) + '_value']
        ch.save()
        i = i + 1
        chr_name = 'ch' + str(i) + '_name' 
       
    resize_picture(pr)           
    return HttpResponseRedirect('/products/' + str(tp.group.id) + '/' + str(tp.id) + '/')  
예제 #2
0
파일: views.py 프로젝트: tesluk/basata_shop
def add_char (request, pr_id):    
    pr = Product.objects.all().get(id=pr_id)
    pr.name = request.POST['name']
    pr.producer = request.POST['producer']
    pr.quantity = request.POST['quantity']
    pr.sdescription = request.POST['sdescr'] 
    if 'picture' in request.FILES:
        pr.picture = request.FILES['picture']
        pr.save()
        typ = str(pr.picture).split('.') 
        pt = Product_type.objects.all().get(id=pr.prod_type.id)
        new_name = 'Entities/static/products/img_' + str(pt.group.id) + '_' + str(pt.id) + '_' + str(pr.id)    
        t = '.' + typ[len(typ) - 1] 
        add_picture(pr, new_name, t)
    if 'userfile' in request.FILES:       
        pr.model = request.FILES['userfile']
        pr.save()
        new_name = 'Entities/static/products/models_' + str(tp.group.id) + '_' + str(tp.id) + '_' + str(pr.id) + '.dae'
        for i in range(2):
            try:
                os.rename(str(pr.model), new_name)
                pr.model = new_name
                break
            except:
                os.remove(new_name)  
    pr.save() 
    resize_picture(pr) 
    price = Price()
    price.value = request.POST['price']
    price.product = pr
    price.date_init = datetime.today().date()
    price.save()
    Characteristic.objects.filter(product=pr).delete()
    ch = Characteristic()
    chr_name = str(1) 
    i = 1
    while chr_name in request.POST:
        ch = Characteristic()
        ch.product = pr;
        ch.name = request.POST[chr_name]
        ch.description = request.POST[str(i + 100)]
        ch.save()
        i = i + 1
        chr_name = str(i)    
    return HttpResponseRedirect('/products/' + str(pr.prod_type.group.id) + '/' + str(pr.prod_type.id) + '/' + str(pr.id) + '/')