def add_item_image(request, item_id): if request.method == 'POST': shop = request.shop item = get_object_or_404(Item, pk=item_id) limit = shop.get_limit('pictures_per_item') total = ImageItem.objects.filter(item=item).count() if total >= limit: logging.info("User reach the pictures per item plan limit") request.flash['message'] = "You have reach the limit of pictures per item allowed by your plan!" request.flash['severity'] = "error" else: form = ImageItemForm(request.POST, request.FILES) if form.is_valid(): img = form.save(commit=False) img.item = item img.save() request.flash['message'] = "Image successfully saved!" request.flash['severity'] = "success" else: logging.error(form.errors) request.flash['message'] = form.errors request.flash['severity'] = "error" return HttpResponseRedirect(reverse('item_details', args=[item_id])) else: raise Http404
def add_item_image(request, item_id): item = get_object_or_404(Item, pk=item_id) if request.method == 'POST': form = ImageItemForm(request.POST, request.FILES) if form.is_valid(): img = form.save(commit=False) img.item = item img.save() else: logging.error(form.errors) request.flash['message'] = form.errors request.flash['severity'] = "error" return HttpResponseRedirect(reverse('item_details', args=[item_id])) return HttpResponseRedirect(reverse('item_details', args=[item_id]))
def item_details(request, item_id): try: item = get_object_or_404(Item, pk=item_id) if item.shop != request.shop: raise Http404 image_form = ImageItemForm() params = {'item': item, 'image_form': image_form } return render_to_response('for_sale/item_details.html', params, RequestContext(request)) except Exception, e: logging.critical(e)