1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- # coding=utf-8
- __author__ = 'marcos.medeiros'
- from django import template
- from django.template import loader, Context
- import random
- from django.utils.safestring import mark_safe
- register = template.Library()
- @register.inclusion_tag('rapid/bare/list.html', takes_context=True)
- def crud_list(context):
- return context
- @register.inclusion_tag('rapid/bare/select.html', takes_context=True)
- def crud_select(context):
- return context
- @register.inclusion_tag('rapid/bare/detail.html', takes_context=True)
- def crud_view(context):
- return context
- @register.inclusion_tag('rapid/bare/update.html', takes_context=True)
- def crud_update(context):
- return context
- @register.inclusion_tag('rapid/bare/create.html', takes_context=True)
- def crud_create(context):
- return context
- @register.inclusion_tag('rapid/bare/delete.html', takes_context=True)
- def crud_delete(context):
- return context
- def random_name():
- s = "abcdefghijklmnopqrustuvwxyz"
- # noinspection PyUnusedLocal
- return "".join([random.choice(s) for x in range(30)])
- def render_to_javascript_string(template_name, context=None):
- context = context if context else {}
- t = loader.get_template(template_name)
- c = Context(context)
- txt = t.render(c)
- txt = txt.replace("\"", "\\\"")
- txt = txt.replace("\n", "\\n")
- return mark_safe(txt)
- @register.filter(name="jsid")
- def jsid(value):
- v = value.replace('"', "").replace("-", "_").replace("'", "")
- return v
- @register.filter(name="jsstr")
- def jsstr(txt):
- txt = txt.replace("\"", "\\\"")
- txt = txt.replace("\n", "\\n")
- return mark_safe(txt)
- @register.inclusion_tag('rapid/overlay/register.html')
- def register_overlay():
- overlay_text = render_to_javascript_string('rapid/overlay/text.html')
- return {'overlay_text': overlay_text}
- @register.inclusion_tag('rapid/overlay/call.html')
- def overlay(target_url, on_commit=None, on_close=None):
- if not on_commit:
- on_commit = 'function(){}'
- if not on_close:
- on_close = 'function(){}'
- return {
- 'target_url': target_url,
- 'on_commit': on_commit,
- 'on_close': on_close,
- }
|