Consolidate common app's template tags.
This commit is contained in:
@@ -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)
|
||||
53
mayan/apps/common/templatetags/common_tags.py
Normal file
53
mayan/apps/common/templatetags/common_tags.py
Normal 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)
|
||||
@@ -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)
|
||||
@@ -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')
|
||||
@@ -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__
|
||||
@@ -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)
|
||||
Reference in New Issue
Block a user