rapid_crud.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. __author__ = 'marcos.medeiros'
  2. from django import template
  3. from django.template import loader, Context
  4. import random
  5. from django.utils.safestring import mark_safe
  6. register = template.Library()
  7. @register.inclusion_tag('rapid/bare/list.html', takes_context=True)
  8. def crud_list(context):
  9. return context
  10. @register.inclusion_tag('rapid/bare/select.html', takes_context=True)
  11. def crud_select(context):
  12. return context
  13. @register.inclusion_tag('rapid/bare/detail.html', takes_context=True)
  14. def crud_view(context):
  15. return context
  16. @register.inclusion_tag('rapid/bare/update.html', takes_context=True)
  17. def crud_update(context):
  18. return context
  19. @register.inclusion_tag('rapid/bare/create.html', takes_context=True)
  20. def crud_create(context):
  21. return context
  22. @register.inclusion_tag('rapid/bare/delete.html', takes_context=True)
  23. def crud_delete(context):
  24. return context
  25. def random_name():
  26. s = "abcdefghijklmnopqrustuvwxyz"
  27. return "".join([random.choice(s) for x in xrange(30)])
  28. def render_to_javascript_string(template, context={}):
  29. t = loader.get_template(template)
  30. c = Context(context)
  31. str = t.render(c)
  32. str = str.replace("\"", "\\\"")
  33. str = str.replace("\n", "\\n")
  34. return mark_safe(str)
  35. @register.inclusion_tag('rapid/overlay/register.html')
  36. def register_overlay():
  37. overlay_text = render_to_javascript_string('rapid/overlay/text.html')
  38. return {'overlay_text': overlay_text}
  39. @register.inclusion_tag('rapid/overlay/call.html')
  40. def overlay(target_url, on_commit=None, on_close=None):
  41. if not on_commit:
  42. on_commit = 'function(){}'
  43. if not on_close:
  44. on_close = 'function(){}'
  45. return {
  46. 'target_url': target_url,
  47. 'on_commit': on_commit,
  48. 'on_close': on_close,
  49. }