plugin_ckeditor.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # -*- coding: utf-8 -*-
  2. import os
  3. from gluon import *
  4. def upload():
  5. (new_filename, old_filename, length,
  6. mime_type) = current.plugin_ckeditor.handle_upload()
  7. title = os.path.splitext(old_filename)[0]
  8. result = current.plugin_ckeditor.settings.table_upload.validate_and_insert(
  9. title=title,
  10. filename=old_filename,
  11. upload=new_filename,
  12. flength=length,
  13. mime_type=mime_type
  14. )
  15. text = ''
  16. url = URL(*current.plugin_ckeditor.settings.download_url,
  17. args=[new_filename])
  18. if not result.id:
  19. text = result.errors
  20. return dict(text=text, cknum=request.vars.CKEditorFuncNum, url=url)
  21. def browse():
  22. db = current.plugin_ckeditor.db
  23. table_upload = current.plugin_ckeditor.settings.table_upload
  24. browse_filter = current.plugin_ckeditor.settings.browse_filter
  25. set = db(table_upload.id>0)
  26. for key, val in browse_filter.items():
  27. if value[0] == '<':
  28. set = set(table_upload[key]<value[1:])
  29. elif value[0] == '>':
  30. set = set(table_upload[key]>value[1:])
  31. elif value[0] == '!':
  32. set = set(table_upload[key]!=value[1:])
  33. else:
  34. set = set(table_upload[key]==value)
  35. rows = set.select(orderby=table_upload.title)
  36. return dict(rows=rows, cknum=request.vars.CKEditorFuncNum)
  37. def delete():
  38. filename = request.args(0)
  39. if not filename:
  40. raise HTTP(401, 'Required argument filename missing.')
  41. db = current.plugin_ckeditor.db
  42. table_upload = current.plugin_ckeditor.settings.table_upload
  43. db(table_upload.upload == filename).delete()
  44. # delete the file from storage
  45. current.plugin_ckeditor.unlink(filename)