Convert the title calculation into a template tag

Convert the calculate form title template into a template tag.
The result of the template tag is applied as the title property
of the <H3> HTML tag allowing users to view the full title on
mouse hover if the title was truncated.

Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
This commit is contained in:
Roberto Rosario
2018-12-16 01:04:11 -04:00
parent 3a6a250d1b
commit 727d2ecd71
5 changed files with 37 additions and 32 deletions

View File

@@ -4,7 +4,6 @@ import hashlib
from django.apps import apps
from django.db import models
from django.template import loader
from django.template.response import TemplateResponse
from django.urls import reverse
from django.utils.encoding import force_text, python_2_unicode_compatible

View File

@@ -3,10 +3,13 @@ from __future__ import unicode_literals
from json import dumps
from django.template import Context, Library
from django.template.defaultfilters import truncatechars
from django.template.loader import get_template
from django.utils.encoding import force_text
from django.utils.translation import ugettext_lazy as _
import mayan
from mayan.apps.appearance.settings import setting_max_title_length
from ..classes import Collection
from ..literals import MESSAGE_SQLITE_WARNING
@@ -58,3 +61,28 @@ def render_subtemplate(context, template_name, template_context):
new_context = Context(context.flatten())
new_context.update(Context(template_context))
return get_template(template_name).render(new_context.flatten())
@register.simple_tag(takes_context=True)
def common_calculate_title(context):
if context.get('title'):
return truncatechars(
value=context.get('title'), arg=setting_max_title_length.value
)
else:
if context.get('delete_view'):
return _('Confirm delete')
else:
if context.get('form'):
if context.get('object'):
return _('Edit %s') % context.get('object')
else:
return _('Confirm')
else:
if context.get('read_only'):
return _('Details for: %s') % context.get('object')
else:
if context.get('object'):
return _('Edit: %s') % context.get('object')
else:
return _('Create')