コード例 #1
0
    def add_auction(cls, request):
        if request.method == "POST":
            form = AuctionForm(request.POST, request.FILES)
            if form.is_valid():
                base_item = BaseItem()
                base_item.name = form.cleaned_data["name"]
                base_item.save()
                base_item.categories = form.cleaned_data["categories"]
                base_item.description = form.cleaned_data["description"]
                base_item.thumb = form.cleaned_data["thumb"]
                base_item.is_active = True

                image = Image()
                image.image = form.cleaned_data["image"]
                image.save()

                base_item.images.add(Image.objects.get(pk=image.pk))
                base_item.save()

                auction = AuctionItem()
                auction.base = base_item
                auction.start_date = form.cleaned_data["start_date"]
                auction.planned_close_date = form.cleaned_data[
                    "planned_close_date"]
                auction.start_price = form.cleaned_data["start_price"]
                auction.current_price = auction.start_price
                auction.reserve_price = form.cleaned_data["reserve_price"]
                auction.properties = "{}"

                current_user = ShopUser.objects.get(user__pk=request.user.pk)
                auction.created_by = current_user

                auction.save()

                return HttpResponseRedirect("/aukcje/%s/" % str(auction.pk))
            else:
                return render_to_response(
                    "auction_add.html", {'form': form},
                    context_instance=RequestContext(request))
        else:
            form = AuctionForm()
            return render_to_response("auction_add.html", {'form': form},
                                      context_instance=RequestContext(request))
コード例 #2
0
ファイル: views.py プロジェクト: kpiszczek/ubershop
    def add_auction(cls, request):
        if request.method == "POST":
            form = AuctionForm(request.POST, request.FILES)
            if form.is_valid():
                base_item = BaseItem()
                base_item.name = form.cleaned_data["name"]
                base_item.save()
                base_item.categories = form.cleaned_data["categories"]
                base_item.description = form.cleaned_data["description"]
                base_item.thumb = form.cleaned_data["thumb"]
                base_item.is_active = True

                image = Image()
                image.image = form.cleaned_data["image"]
                image.save()

                base_item.images.add(Image.objects.get(pk=image.pk))
                base_item.save()

                auction = AuctionItem()
                auction.base = base_item
                auction.start_date = form.cleaned_data["start_date"]
                auction.planned_close_date = form.cleaned_data[
                    "planned_close_date"]
                auction.start_price = form.cleaned_data["start_price"]
                auction.current_price = auction.start_price
                auction.reserve_price = form.cleaned_data["reserve_price"]
                auction.properties = "{}"

                current_user = ShopUser.objects.get(user__pk=request.user.pk)
                auction.created_by = current_user

                auction.save()

                return HttpResponseRedirect("/aukcje/%s/" % str(auction.pk))
            else:
                return render_to_response("auction_add.html", {'form': form},
                                          context_instance=RequestContext(request))
        else:
            form = AuctionForm()
            return render_to_response("auction_add.html", {'form': form},
                                      context_instance=RequestContext(request))
コード例 #3
0
ファイル: views.py プロジェクト: kpiszczek/ubershop
 def add_item(cls, request): 
     if request.method == 'POST':
         form = EshopItemForm(request.POST)
         if form.is_valid():
             #nowy BaseItem
             base_name = request.POST['name']
             base_category_name = request.POST['category']
             base_category = Category.objects.get(pk=base_category_name)
             #properties konstrukcja Json
             json = '{'
             properties = [[request.POST['properties1'], request.POST['pname1']], [request.POST['properties2'], request.POST['pname2']], [request.POST['properties3'], request.POST['pname3']], [request.POST['properties4'], request.POST['pname4']],
                           [request.POST['properties5'], request.POST['pname5']], [request.POST['properties6'], request.POST['pname6']]]
             i=0
             for property in properties:
                 if property[0]:
                     if i<len(properties) and i>0:
                         json = json + ',\r\n'
                     i = i+1
                     json = json + '"' + property[1] + '":"' + property[0] +'"'
                     
             json = json +'}'
                 
             #
             base_description = request.POST['description']
             base_thumb = request.FILES.get('thumb')
             base_is_active = request.POST['is_active']
             #
             new_base = BaseItem(name=base_name, properties=json, description=base_description, thumb=base_thumb, is_active=base_is_active)
             new_base.save()
             
             #images
             image1 = request.FILES.get('image1')
             new_image1 = Image(image=image1)
             if image1:                    
                 new_image1.save()
                 new_base.images.add(new_image1)
             image2 = request.FILES.get('image2')
             new_image2 = Image(image=image2)
             if image2:                    
                 new_image2.save()
                 new_base.images.add(new_image2)
             image3 = request.FILES.get('image3')
             new_image3 = Image(image=image3)
             if image3:
                 new_image3.save()
                 new_base.images.add(new_image3)
             
             #dodaj kategorie i obrazy 
             new_base.categories.add(base_category)                
             new_base.save()
             #nowy EshopItem
             price = request.POST['price']
             is_on_sale = request.POST.get('is_on_sale', False)
             discount_price = request.POST.get('discount_price')
             availiability_status_name = request.POST['availiability_status']
             availiability_status = AvailiabilityStatus.objects.get(pk=availiability_status_name)
             current_stock = request.POST['current_stock']
             
             new_eshopitem = EShopItem(price=price, is_on_sale=is_on_sale, discount_price=discount_price, availiability_status=availiability_status, current_stock=current_stock, base=new_base)
             new_eshopitem.save()
             return HttpResponseRedirect("/manager/sklep/")
     else:
         form = EshopItemForm(initial={"discount_price":0})
     return render_to_response('backpanel_new_item.html', 
                               {'form': form}, 
                               context_instance=RequestContext(request))
コード例 #4
0
ファイル: views.py プロジェクト: kpiszczek/ubershop
    def add_item(cls, request):
        if request.method == 'POST':
            form = EshopItemForm(request.POST)
            if form.is_valid():
                #nowy BaseItem
                base_name = request.POST['name']
                base_category_name = request.POST['category']
                base_category = Category.objects.get(pk=base_category_name)
                #properties konstrukcja Json
                json = '{'
                properties = [
                    [request.POST['properties1'], request.POST['pname1']],
                    [request.POST['properties2'], request.POST['pname2']],
                    [request.POST['properties3'], request.POST['pname3']],
                    [request.POST['properties4'], request.POST['pname4']],
                    [request.POST['properties5'], request.POST['pname5']],
                    [request.POST['properties6'], request.POST['pname6']]
                ]
                i = 0
                for property in properties:
                    if property[0]:
                        if i < len(properties) and i > 0:
                            json = json + ',\r\n'
                        i = i + 1
                        json = json + '"' + property[1] + '":"' + property[
                            0] + '"'

                json = json + '}'

                #
                base_description = request.POST['description']
                base_thumb = request.FILES.get('thumb')
                base_is_active = request.POST['is_active']
                #
                new_base = BaseItem(name=base_name,
                                    properties=json,
                                    description=base_description,
                                    thumb=base_thumb,
                                    is_active=base_is_active)
                new_base.save()

                #images
                image1 = request.FILES.get('image1')
                new_image1 = Image(image=image1)
                if image1:
                    new_image1.save()
                    new_base.images.add(new_image1)
                image2 = request.FILES.get('image2')
                new_image2 = Image(image=image2)
                if image2:
                    new_image2.save()
                    new_base.images.add(new_image2)
                image3 = request.FILES.get('image3')
                new_image3 = Image(image=image3)
                if image3:
                    new_image3.save()
                    new_base.images.add(new_image3)

                #dodaj kategorie i obrazy
                new_base.categories.add(base_category)
                new_base.save()
                #nowy EshopItem
                price = request.POST['price']
                is_on_sale = request.POST.get('is_on_sale', False)
                discount_price = request.POST.get('discount_price')
                availiability_status_name = request.POST[
                    'availiability_status']
                availiability_status = AvailiabilityStatus.objects.get(
                    pk=availiability_status_name)
                current_stock = request.POST['current_stock']

                new_eshopitem = EShopItem(
                    price=price,
                    is_on_sale=is_on_sale,
                    discount_price=discount_price,
                    availiability_status=availiability_status,
                    current_stock=current_stock,
                    base=new_base)
                new_eshopitem.save()
                return HttpResponseRedirect("/manager/sklep/")
        else:
            form = EshopItemForm(initial={"discount_price": 0})
        return render_to_response('backpanel_new_item.html', {'form': form},
                                  context_instance=RequestContext(request))