diff --git a/HISTORY.rst b/HISTORY.rst index 02799954e7..d7a82c830b 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -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) =================== diff --git a/docs/releases/3.2.rst b/docs/releases/3.2.rst index 8a447e0a04..d00878ade9 100644 --- a/docs/releases/3.2.rst +++ b/docs/releases/3.2.rst @@ -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 -------- diff --git a/mayan/apps/appearance/templates/appearance/calculate_form_title.html b/mayan/apps/appearance/templates/appearance/calculate_form_title.html index 8e152170ca..6c96b8c40a 100644 --- a/mayan/apps/appearance/templates/appearance/calculate_form_title.html +++ b/mayan/apps/appearance/templates/appearance/calculate_form_title.html @@ -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 %} -

+

{% 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 %}

- {% if subtitle %} {{ subtitle }} {% endif %} diff --git a/mayan/apps/common/templatetags/common_tags.py b/mayan/apps/common/templatetags/common_tags.py index 8b8d82f712..96ce512a27 100644 --- a/mayan/apps/common/templatetags/common_tags.py +++ b/mayan/apps/common/templatetags/common_tags.py @@ -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():