<script type="text/javascript" src="{{=URL('static', 'nicEdit/nicEditComplete.js')}}"></script>
<script type="text/javascript">
bkLib.onDomLoaded(function() {
new nicEditors.allTextAreas({
iconsPath :"{{=URL('static', 'nicEdit/nicEditorIcons.gif')}}",
buttonList : ['bold','italic','underline','strikeThrough','left', 'center',
'right', 'justify', 'ol', 'ul', 'fontSize', 'fontFormat', 'indent', 'outdent', 'upload'],
uploadURI : "{{=URL('default', 'nicedit_image_upload', args=page.url)}}",
})
});
</script>def nicedit_image_upload():
"""
Controller to upload images with nicedit
"""
from gluon.contrib.simplejson import dumps
import os
page_url = request.args[0]
pathname = os.path.join(request.folder,'static','images', 'pages_content', page_url)
if not os.path.exists(pathname):
os.mkdir(pathname)
pathfilename = os.path.join(pathname, request.vars.image.filename)
dest_file = open(pathfilename, 'wb')
try:
dest_file.write(request.vars.image.file.read())
finally:
dest_file.close()
#Make a thumbnail (max 600*600px) of the uploaded Image
try:
from PIL import Image
im = Image.open(pathfilename)
im.thumbnail((600,600),Image.ANTIALIAS)
im.save(pathfilename)
except:
pass
links_dict = {"original":URL('static', 'images/pages_content/'+page_url+'/'+request.vars.image.filename)}
set_dict = {"links" : links_dict}
upload_dict = {"upload" : set_dict}
return dumps(upload_dict)