def item_add(request): if request.method == 'POST': form = ItemForm(request, request.POST, request.FILES, prefix="item") if form.is_valid(): item = form.save(commit=False) item.shop = request.shop item.save() item.update_latest_item() for img in request.FILES.getlist('file'): image = ImageItem() image.item = item image.image.save(img.name,img) request.flash['message'] = unicode(_("Item successfully added.")) request.flash['severity'] = "success" return HttpResponseRedirect(reverse('inventory_items')) else: form = ItemForm(request, prefix="item") form_category = MarketCategoryForm(prefix="category") form_sub_category = MarketSubCategoryForm(request, prefix="sub_category") form_session = AuctionSessionForm(prefix="session") sessions = AuctionSession.objects.filter(shop = request.shop) return render_to_response('store_admin/inventory/item_add.html', {'form': form, 'form_category': form_category, 'form_sub_category': form_sub_category, 'form_session': form_session, 'sessions': sessions, }, RequestContext(request))
def item_add(request): shop = request.shop items_plan_limit = shop.plan().concurrent_store_items if shop.total_items() >= items_plan_limit: request.flash['message'] = "You have reached the limit of items that can hold simultaneously." request.flash['severity'] = "error" return HttpResponseRedirect(reverse('inventory_items')) if request.method == 'POST': form = ItemForm(request, request.POST, request.FILES, prefix="item") if form.is_valid(): item = form.save(commit=False) item.shop = request.shop item.save() Item.update_latest_item(shop) for img in request.FILES.getlist('file'): image = ImageItem() image.item = item image.image.save(img.name,img) request.flash['message'] = unicode(_("Item successfully added.")) request.flash['severity'] = "success" return HttpResponseRedirect(reverse('inventory_items')) else: form = ItemForm(request, prefix="item") form_category = MarketCategoryForm(prefix="category") form_sub_category = MarketSubCategoryForm(request, prefix="sub_category") form_session = AuctionSessionForm(prefix="session") sessions = AuctionSession.objects.filter(shop = request.shop) return render_to_response('for_sale/item_add.html', {'form': form, 'form_category': form_category, 'form_sub_category': form_sub_category, 'form_session': form_session, 'sessions': sessions, }, RequestContext(request))
def get_image(self): import httplib2 from urlparse import urlparse try: name = urlparse(self.url).path.split('/')[-1] http = httplib2.Http() status, content = http.request(self.url) response = status["status"] if response == "200": imageItem = ImageItem(item=self.item) imageItem.image.save(name, ContentFile(content), save=True) else: logging.error("Could not charge image %s. status=%s" % (name, response)) except Exception,e: logging.error("Could not charge image %s. %s" % (name, e))
def add_img(request, item_id): try: item = get_object_or_404(Item, pk=item_id, shop=request.shop) data = [] if request.method == 'POST': limit = request.shop.get_limit('pictures_per_item') total = ImageItem.objects.filter(item=item).count() f = request.FILES.get('files') if f and not (total >= limit): image = ImageItem(item=item) image.image.save(f.name, f) item.save() data = [{ 'name': f.name, 'url': image.image.url, 'size': image.image.size, 'thumbnail_url': image.image.url_100x100, 'delete_url': reverse('del_item_image', args=[image.id]), 'delete_type': "DELETE", 'url_set_primary': reverse('set_forsale_primary_picture', args=[item_id, image.id]) }] else: data = [{'error': 'You have reach the limit of pictures per item allowed by your plan!'}] else: for image in item.imageitem_set.all(): data.append({ 'name': image.image.name, 'url': image.image.url, 'size': image.image.size, 'thumbnail_url': image.image.url_100x100, 'delete_url': reverse('del_item_image', args=[image.id]), 'delete_type': "DELETE", 'is_primary': image.primary_picture, 'url_set_primary': reverse('set_forsale_primary_picture', args=[item_id, image.id]) }) response = JSONResponse(data, {}, response_mimetype(request)) response['Content-Disposition'] = 'inline; filename=files.json' return response except Exception, ex: logging.exception(str(ex))