def get_uploads():
"""gets the images and other files from the uploads directory
and returns two lists of tuples in the form (name, path)
"""
images = [('none', '')]
others = [('none', '')]
uploads = os.listdir(os.path.join(app.root_path, app.config['UPLOAD_FOLDER']))
uploads.remove(".gitignore")
# sort by time last modified
uploads.sort(key=lambda filename: os.stat(os.path.join(app.root_path, app.config['UPLOAD_FOLDER'], filename)).st_mtime)
image_extensions = ["png", "jpg", "jpeg", "gif", "bmp"]
for upload in uploads[::-1]:
if '.' in upload and upload.rsplit('.', 1)[1].lower() in image_extensions:
images.append(('/uploads/' + upload, upload))
else:
others.append(('/uploads/' + upload, upload))
return images, others
# custom widget for rendering a TinyMCE input
评论列表
文章目录