Example #1
0
def product_upload_image(key_id):
    product = Product.retrieve_by_id(key_id)
    if not product:
        return jsonify({"success": False, "msg": "Product id:%s not found" % key_id})

    upload_files = get_uploads(request, "image")
    if len(upload_files):
        blob_info = upload_files[0]
        if blob_info.size and ProductImage.is_image_type(blob_info.content_type):
            img = ProductImage.create(
                blob_info.key(),
                size=blob_info.size,
                filename=os.path.basename(blob_info.filename.replace("\\", "/")),
                content_type=blob_info.content_type,
            )
            if not len(product.images_list):
                img.is_master = True
            if img.get_cached_url():
                product.images_list.append(img)
                product.put()
        else:
            file_size = blob_info.size
            content_type = blob_info.content_type
            blob_info.delete()
            return jsonify(
                {"success": False, "msg": "Unknown error. File size: %s. File type: %s" % (file_size, content_type)}
            )
    else:
        return jsonify({"success": False, "msg": "Upload image not found."})
    return jsonify({"success": True, "msg": "Upload image complete."})
Example #2
0
def add_image(key_id):
    product = Product.retrieve_by_id(key_id)
    if not product:
        return redirect('pages.catalogue')

    upload_files = get_uploads(request, 'image')
    if len(upload_files):
        blob_info = upload_files[0]
        if blob_info.size and ProductImage.is_image_type(blob_info.content_type):
            img = ProductImage.create(
                blob_info.key(),
                size=blob_info.size,
                filename=os.path.basename(blob_info.filename.replace('\\','/')),
                content_type=blob_info.content_type)
            if not len(product.images_list):
                img.is_master = True
            if img.get_cached_url():
                product.images_list.append(img)
                product.put()
        else:
            blob_info.delete()
    return redirect(url_for('admin.product.edit_images', key_id=key_id))
Example #3
0
def product_upload_image(key_id):
    product = Product.retrieve_by_id(key_id)
    if not product:
        return jsonify({
            'success': False,
            'msg': 'Product id:%s not found' % key_id
        })

    upload_files = get_uploads(request, 'image')
    if len(upload_files):
        blob_info = upload_files[0]
        if blob_info.size and \
                ProductImage.is_image_type(blob_info.content_type):
            img = ProductImage.create(blob_info.key(),
                                      size=blob_info.size,
                                      filename=os.path.basename(
                                          blob_info.filename.replace(
                                              '\\', '/')),
                                      content_type=blob_info.content_type)
            if not len(product.images_list):
                img.is_master = True
            if img.get_cached_url():
                product.images_list.append(img)
                product.put()
        else:
            file_size = blob_info.size
            content_type = blob_info.content_type
            blob_info.delete()
            return jsonify({
                'success':
                False,
                'msg':
                "Unknown error. File size: %s. File type: %s" %
                (file_size, content_type)
            })
    else:
        return jsonify({'success': False, 'msg': 'Upload image not found.'})
    return jsonify({'success': True, 'msg': 'Upload image complete.'})
Example #4
0
def add_image(key_id):
    product = Product.retrieve_by_id(key_id)
    if not product:
        return redirect('pages.catalogue')

    upload_files = get_uploads(request, 'image')
    if len(upload_files):
        blob_info = upload_files[0]
        if blob_info.size and ProductImage.is_image_type(
                blob_info.content_type):
            img = ProductImage.create(blob_info.key(),
                                      size=blob_info.size,
                                      filename=os.path.basename(
                                          blob_info.filename.replace(
                                              '\\', '/')),
                                      content_type=blob_info.content_type)
            if not len(product.images_list):
                img.is_master = True
            if img.get_cached_url():
                product.images_list.append(img)
                product.put()
        else:
            blob_info.delete()
    return redirect(url_for('admin.product.edit_images', key_id=key_id))