models.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #coding:utf-8
  2. #
  3. from django.db import models
  4. from DjangoUeditor.models import UEditorField
  5. from DjangoUeditor.commands import *
  6. def getImagePath(model_instance=None):
  7. if model_instance is None:
  8. return "aaa/"
  9. else:
  10. return "%s/" % model_instance.Name
  11. def getDescImagePath(model_instance=None):
  12. return "aaa/"
  13. class myBtn(UEditorButtonCommand):
  14. def onClick(self):
  15. return u"""
  16. alert("爽!");
  17. editor.execCommand(uiName);
  18. """
  19. def onExecuteAjaxCommand(self,state):
  20. if state=="success":
  21. return u"""
  22. alert("后面比较爽!"+xhr.responseText);
  23. """
  24. if state=="error":
  25. return u"""
  26. alert("讨厌,摸哪里去了!"+xhr.responseText);
  27. """
  28. class myCombo(UEditorComboCommand):
  29. def onSelect(self):
  30. return u"""
  31. alert("选择了!");
  32. """
  33. def get_items(self):
  34. items=[]
  35. for i in xrange(10):
  36. items.append({
  37. "label":"combo_%s" % i,
  38. "value":i
  39. })
  40. return items
  41. class Blog(models.Model):
  42. Name = models.CharField(u'姓名', max_length=100, blank=True)
  43. Description = UEditorField(u'描述', blank=True, toolbars="full", imagePath="cool/", settings={"a": 1},
  44. command=[myBtn(uiName="mybtn1", icon="d.png", title=u"1摸我", ajax_url="/ajaxcmd/"),
  45. myBtn(uiName="mybtn2",index=22, icon="d.png", title=u"2摸我", ajax_url="/ajaxcmd/"),
  46. myCombo(uiName="myCombo3",title=u"ccc",initValue="aaa")
  47. ])
  48. ImagePath = models.CharField(u'图片目录', max_length=100, blank=True)
  49. Content = UEditorField(u'内容', height=200, width=500, default='test', imagePath=getImagePath, toolbars="mini",
  50. filePath='bb/', blank=True, settings={"a": 2})