Consolidate common app's template tags.

This commit is contained in:
Roberto Rosario
2015-07-17 02:04:01 -04:00
parent fb824c6ee1
commit e421c8e382
15 changed files with 59 additions and 79 deletions

View File

@@ -1,10 +0,0 @@
from django.template import Library
from common.utils import return_attrib
register = Library()
@register.filter
def object_property(value, arg):
return return_attrib(value, arg)

View File

@@ -0,0 +1,53 @@
from __future__ import unicode_literals
from json import dumps
from django.conf import settings
from django.template import Context, Library
from django.template.loader import get_template
import mayan
from ..utils import return_attrib
register = Library()
@register.filter
def get_encoded_parameter(item, parameters_dict):
result = {}
for attrib_name, attrib in parameters_dict.items():
result[attrib_name] = return_attrib(item, attrib)
return dumps(result)
@register.filter
def make_non_breakable(value):
return value.replace('-', '\u2011')
@register.filter
def object_property(value, arg):
return return_attrib(value, arg)
@register.simple_tag
def project_name():
return settings.PROJECT_TITLE
@register.simple_tag
def project_version():
return mayan.__version__
@register.assignment_tag(takes_context=True)
def render_subtemplate(context, template_name, template_context):
"""
Renders the specified template with the mixed parent and
subtemplate contexts
"""
new_context = Context(context)
new_context.update(Context(template_context))
return get_template(template_name).render(new_context)

View File

@@ -1,14 +0,0 @@
from json import dumps
from django.template import Library
from ..utils import return_attrib
register = Library()
@register.filter
def get_encoded_parameter(item, parameters_dict):
result = {}
for attrib_name, attrib in parameters_dict.items():
result[attrib_name] = return_attrib(item, attrib)
return dumps(result)

View File

@@ -1,10 +0,0 @@
from __future__ import unicode_literals
from django.template import Library
register = Library()
@register.filter
def make_non_breakable(value):
return value.replace('-', '\u2011')

View File

@@ -1,16 +0,0 @@
from django.conf import settings
from django.template import Library
import mayan
register = Library()
@register.simple_tag
def project_name():
return settings.PROJECT_TITLE
@register.simple_tag
def project_version():
return mayan.__version__

View File

@@ -1,18 +0,0 @@
from __future__ import unicode_literals
from django.template import Context, Library
from django.template.loader import get_template
register = Library()
@register.assignment_tag(takes_context=True)
def render_subtemplate(context, template_name, template_context):
"""
Renders the specified template with the mixed parent and
subtemplate contexts
"""
new_context = Context(context)
new_context.update(Context(template_context))
return get_template(template_name).render(new_context)