Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: tinymce route not working #506

Merged
merged 1 commit into from
Nov 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 72 additions & 72 deletions src/shopcube/modules/resource/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,75 +81,75 @@ def active_back_theme_css(active_theme):
return send_from_directory(theme_dir, "styles.css")


# @module_blueprint.route("/product/<filename>", methods=["GET"])
# def product_image(filename):

# # return theme_dir
# if filename == "default":
# return send_from_directory(
# os.path.join(current_app.config["BASE_DIR"], "static", "default"),
# "default_product.jpg",
# )
# return send_from_directory(
# current_app.config["UPLOADED_PRODUCTPHOTOS_DEST"], filename
# )


# # Handles javascript image uploads from tinyMCE
# @module_blueprint.route("/upload/tinymce/image", methods=["POST"])
# @login_required
# def upload_tinymce_image():
# # Kevin Foong
# file = request.files.get("file")
# if file:
# filename = file.filename.lower()
# fn, ext = filename.split(".")
# # truncate filename (excluding extension) to 30 characters
# fn = fn[:30]
# filename = fn + "." + ext
# if ext in ["jpg", "gif", "png", "jpeg"]:
# try:
# # everything looks good, save file
# img_fullpath = os.path.join(
# current_app.config["UPLOADED_PATH_IMAGE"], filename
# )
# file.save(img_fullpath)
# # get the file size to save to db
# file_size = os.stat(img_fullpath).st_size
# size = 160, 160
# # read image into pillow
# im = PILimage.open(img_fullpath)
# # get image dimension to save to db
# file_width, file_height = im.size
# # convert to thumbnail
# im.thumbnail(size)
# thumbnail = fn + "-thumb.jpg"
# tmb_fullpath = os.path.join(
# current_app.config["UPLOADED_PATH_THUMB"], thumbnail
# )
# # PNG is index while JPG needs RGB
# if not im.mode == "RGB":
# im = im.convert("RGB")
# # save thumbnail
# im.save(tmb_fullpath, "JPEG")

# # save to db
# img = Image(
# filename=filename,
# thumbnail=thumbnail,
# file_size=file_size,
# file_width=file_width,
# file_height=file_height,
# )
# db.session.add(img)
# db.session.commit()
# except OSError:
# output = make_response(404)
# output.headers["Error"] = "Cannot create thumbnail for " + filename
# return output
# return jsonify({"location": filename})

# # fail, image did not upload
# output = make_response(404)
# output.headers["Error"] = "Filename needs to be JPG, JPEG, GIF or PNG"
# return output
@module_blueprint.route("/product/<filename>", methods=["GET"])
def product_image(filename):

# return theme_dir
if filename == "default":
return send_from_directory(
os.path.join(current_app.config["BASE_DIR"], "static", "default"),
"default_product.jpg",
)
return send_from_directory(
current_app.config["UPLOADED_PRODUCTPHOTOS_DEST"], filename
)


# Handles javascript image uploads from tinyMCE
@module_blueprint.route("/upload/tinymce/image", methods=["POST"])
@login_required
def upload_tinymce_image():
# Kevin Foong
# file = request.files.get("file")
# if file:
# filename = file.filename.lower()
# fn, ext = filename.split(".")
# # truncate filename (excluding extension) to 30 characters
# fn = fn[:30]
# filename = fn + "." + ext
# if ext in ["jpg", "gif", "png", "jpeg"]:
# try:
# # everything looks good, save file
# img_fullpath = os.path.join(
# current_app.config["UPLOADED_PATH_IMAGE"], filename
# )
# file.save(img_fullpath)
# # get the file size to save to db
# file_size = os.stat(img_fullpath).st_size
# size = 160, 160
# # read image into pillow
# im = PILimage.open(img_fullpath)
# # get image dimension to save to db
# file_width, file_height = im.size
# # convert to thumbnail
# im.thumbnail(size)
# thumbnail = fn + "-thumb.jpg"
# tmb_fullpath = os.path.join(
# current_app.config["UPLOADED_PATH_THUMB"], thumbnail
# )
# # PNG is index while JPG needs RGB
# if not im.mode == "RGB":
# im = im.convert("RGB")
# # save thumbnail
# im.save(tmb_fullpath, "JPEG")

# # save to db
# img = Image(
# filename=filename,
# thumbnail=thumbnail,
# file_size=file_size,
# file_width=file_width,
# file_height=file_height,
# )
# db.session.add(img)
# db.session.commit()
# except OSError:
# output = make_response(404)
# output.headers["Error"] = "Cannot create thumbnail for " + filename
# return output
# return jsonify({"location": filename})

# # fail, image did not upload
# output = make_response(404)
# output.headers["Error"] = "Filename needs to be JPG, JPEG, GIF or PNG"
return ""