Ejemplo n.º 1
0
def collection_del(id):
    try:
        collection = Collection.get_by_id(id)
        collection.delete()
    except Exception as e:
        return ApiResult({"r": 1, "msg": str(e)})
    return ApiResult(dict())
Ejemplo n.º 2
0
def create_fake_collection(placeholder_dir, collection_data):
    image_dir = placeholder_dir / "products-list"
    background_img = image_dir / collection_data["image_name"]
    collection = Collection.get_or_create(
        title=collection_data["name"], background_img=str(background_img))[0]
    products = Product.query.limit(4)
    for product in products:
        ProductCollection.create(product_id=product.id,
                                 collection_id=collection.id)
    return collection
Ejemplo n.º 3
0
def collection_manage(id=None):
    if id:
        collection = Collection.get_by_id(id)
        form = CollectionForm(obj=collection)
    else:
        form = CollectionForm()
    if form.validate_on_submit():
        if not id:
            collection = Collection()
        collection.title = form.title.data
        collection.update_products(form.products.data)
        image = form.bgimg_file.data
        if image:
            background_img = image.filename
            upload_file = current_app.config["UPLOAD_DIR"] / background_img
            upload_file.write_bytes(image.read())
            collection.background_img = (
                current_app.config["UPLOAD_FOLDER"] + "/" + background_img
            )
        collection.save()
        return redirect(url_for("dashboard.collections"))
    products = Product.query.all()
    return render_template("product/collection.html", form=form, products=products)