Convert title calculation form to a template tag

Show the full title as a hover title even when truncated.

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2019-04-27 18:30:24 -04:00
parent 041464fc1c
commit 4f92bde7d7
4 changed files with 44 additions and 31 deletions

View File

@@ -180,6 +180,8 @@
Tesseract bug 1670
(https://github.com/tesseract-ocr/tesseract/issues/1670)
* Load only one language in the document properties form.
* Convert title calculation form to a template tag.
* Show the full title as a hover title even when truncated.
3.1.11 (2019-04-XX)
===================

View File

@@ -212,6 +212,8 @@ Other changes
Tesseract bug 1670
(https://github.com/tesseract-ocr/tesseract/issues/1670)
* Load only one language in the document properties form.
* Convert title calculation form to a template tag.
* Show the full title as a hover title even when truncated.
Removals
--------

View File

@@ -1,42 +1,15 @@
{% load i18n %}
{% load smart_settings_tags %}
{% load common_tags %}
{% smart_setting 'APPEARANCE_MAXIMUM_TITLE_LENGTH' as maximum_title_length %}
{% common_calculate_title as result %}
{% if not non_html_title %}
<h3>
<h3 title='{{ result.title_full }}'>
{% endif %}
{% if title %}
{{ title|truncatechars:maximum_title_length }}
{% else %}
{% if delete_view %}
{% trans 'Confirm delete' %}
{% else %}
{% if form %}
{% if object %}
{% blocktrans with object as object %}Edit: {{ object }}{% endblocktrans %}
{% else %}
{% trans 'Confirm' %}
{% endif %}
{% else %}
{% if read_only %}
{% blocktrans %}Details for: {{ object }}{% endblocktrans %}
{% else %}
{% if object %}
{% blocktrans with object as object %}Edit: {{ object }}{% endblocktrans %}
{% else %}
{% trans 'Create' %}
{% endif %}
{% endif %}
{% endif %}
{% endif %}
{% endif %}
{{ result.title }}
{% if not non_html_title %}
</h3>
{% if subtitle %}
<small>{{ subtitle }}</small>
{% endif %}

View File

@@ -3,11 +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.six import string_types
import mayan
from mayan.apps.appearance.settings import setting_max_title_length
from ..classes import Collection
from ..literals import MESSAGE_SQLITE_WARNING
@@ -16,6 +18,40 @@ from ..utils import check_for_sqlite, return_attrib
register = Library()
@register.simple_tag(takes_context=True)
def common_calculate_title(context):
if context.get('title'):
title_full = context.get('title')
title = truncatechars(
value=title_full, arg=setting_max_title_length.value
)
else:
if context.get('delete_view'):
title = _('Confirm delete')
title_full = title
else:
if context.get('form'):
if context.get('object'):
title = _('Edit %s') % context.get('object')
title_full = title
else:
title = _('Confirm')
title_full = title
else:
if context.get('read_only'):
title = _('Details for: %s') % context.get('object')
title_full = title
else:
if context.get('object'):
title = _('Edit: %s') % context.get('object')
title_full = title
else:
title = _('Create')
title_full = title
return {'title': title, 'title_full': title_full}
@register.simple_tag
def common_check_sqlite():
if check_for_sqlite():