Complete prefixing template tags with app names

Additionally remove unused template tags.

Signed-off-by: Roberto Rosario <roberto.rosario@mayan-edms.com>
This commit is contained in:
Roberto Rosario
2019-11-17 01:59:17 -04:00
parent 820e997165
commit f1c704e3e1
24 changed files with 63 additions and 186 deletions
+3
View File
@@ -158,6 +158,9 @@
- Switch default installation to use two Redis - Switch default installation to use two Redis
databases. One for the message broker, and the databases. One for the message broker, and the
other to store task results. other to store task results.
- Complete the prefixing of template tags with the
app name.
- Remove unused template tags.
3.2.10 (2019-XX-XX) 3.2.10 (2019-XX-XX)
=================== ===================
@@ -56,18 +56,18 @@
{% endblock stylesheets %} {% endblock stylesheets %}
{% block content %} {% block content %}
{% project_information '__build_string__' as build_number %} {% common_project_information '__build_string__' as build_number %}
{% smart_setting 'COMMON_PROJECT_TITLE' as setting_project_title %} {% smart_setting 'COMMON_PROJECT_TITLE' as setting_project_title %}
{% project_information '__title__' as project_title %} {% common_project_information '__title__' as project_title %}
{% get_icon 'mayan.apps.common.icons.icon_documentation' as icon_documentation %} {% appearance_get_icon 'mayan.apps.common.icons.icon_documentation' as icon_documentation %}
{% get_icon 'mayan.apps.common.icons.icon_forum' as icon_forum %} {% appearance_get_icon 'mayan.apps.common.icons.icon_forum' as icon_forum %}
{% get_icon 'mayan.apps.common.icons.icon_social_facebook' as icon_social_facebook %} {% appearance_get_icon 'mayan.apps.common.icons.icon_social_facebook' as icon_social_facebook %}
{% get_icon 'mayan.apps.common.icons.icon_social_paypal' as icon_social_paypal %} {% appearance_get_icon 'mayan.apps.common.icons.icon_social_paypal' as icon_social_paypal %}
{% get_icon 'mayan.apps.common.icons.icon_social_twitter' as icon_social_twitter %} {% appearance_get_icon 'mayan.apps.common.icons.icon_social_twitter' as icon_social_twitter %}
{% get_icon 'mayan.apps.common.icons.icon_social_instagram' as icon_social_instagram %} {% appearance_get_icon 'mayan.apps.common.icons.icon_social_instagram' as icon_social_instagram %}
{% get_icon 'mayan.apps.common.icons.icon_source_code' as icon_source_code %} {% appearance_get_icon 'mayan.apps.common.icons.icon_source_code' as icon_source_code %}
{% get_icon 'mayan.apps.common.icons.icon_wiki' as icon_wiki %} {% appearance_get_icon 'mayan.apps.common.icons.icon_wiki' as icon_wiki %}
<div class="well"> <div class="well">
<h3 class="text-center">{{ setting_project_title }}</h3> <h3 class="text-center">{{ setting_project_title }}</h3>
@@ -79,25 +79,25 @@
{% endblocktrans %} {% endblocktrans %}
</p> </p>
{% endif %} {% endif %}
<p class="text-center">{% trans 'Version' %} {% project_information '__version__' %}</p> <p class="text-center">{% trans 'Version' %} {% common_project_information '__version__' %}</p>
{% if build_number %} {% if build_number %}
<p class='text-center'>{% blocktrans with build_number as build_number %}Build number: {{ build_number }}{% endblocktrans %}</p> <p class='text-center'>{% blocktrans with build_number as build_number %}Build number: {{ build_number }}{% endblocktrans %}</p>
{% endif %} {% endif %}
<p class="text-center"> <p class="text-center">
{% project_information '__description__' as project_description %} {% common_project_information '__description__' as project_description %}
{% trans project_description %} {% trans project_description %}
</p> </p>
<p class="text-center"> <p class="text-center">
<i class="fa fa-home"></i><a href="{% project_information '__website__' %}"> {% project_information '__website__' %}</a> <i class="fa fa-home"></i><a href="{% common_project_information '__website__' %}"> {% common_project_information '__website__' %}</a>
</p> </p>
<p class="text-center"> <p class="text-center">
{% project_information '__license__' as license_information %} {% common_project_information '__license__' as license_information %}
{% trans 'Released under the license:' %} {% trans license_information %} {% trans 'Released under the license:' %} {% trans license_information %}
</p> </p>
<p class="text-center mayan-edms-logo"><span class="icon-mayan-edms-logo"></span> {% project_information '__title__' %}</p> <p class="text-center mayan-edms-logo"><span class="icon-mayan-edms-logo"></span> {% common_project_information '__title__' %}</p>
<p class="text-center"> <p class="text-center">
{% blocktrans with project_title as project_title %} {% blocktrans with project_title as project_title %}
@@ -160,7 +160,7 @@
<div class="col-xs-12"> <div class="col-xs-12">
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-body"> <div class="panel-body">
{% project_information '__copyright__' %} {% common_project_information '__copyright__' %}
</div> </div>
</div> </div>
</div> </div>
@@ -17,7 +17,7 @@
{% else %} {% else %}
<div class="col-xs-12"> <div class="col-xs-12">
{% endif %} {% endif %}
{% render_subtemplate subtemplate.name subtemplate.context as rendered_subtemplate %} {% common_render_subtemplate subtemplate.name subtemplate.context as rendered_subtemplate %}
{{ rendered_subtemplate }} {{ rendered_subtemplate }}
</div> </div>
{% endfor %} {% endfor %}
@@ -77,13 +77,13 @@
{% endif %} {% endif %}
{% elif field|widget_type == 'select' %} {% elif field|widget_type == 'select' %}
{% if read_only %} {% if read_only %}
{{ field|get_choice_value }} {{ field|appearance_get_choice_value }}
{% else %} {% else %}
{% render_field field class+="form-control" %} {% render_field field class+="form-control" %}
{% endif %} {% endif %}
{% elif field|widget_type == 'selectmultiple' %} {% elif field|widget_type == 'selectmultiple' %}
{% if read_only %} {% if read_only %}
{{ field|get_choice_value }} {{ field|appearance_get_choice_value }}
{% else %} {% else %}
{% render_field field class+="form-control" %} {% render_field field class+="form-control" %}
{% endif %} {% endif %}
@@ -119,7 +119,7 @@
{% endif %} {% endif %}
<script> <script>
{% for script in form|get_form_media_js %} {% for script in form|appearance_get_form_media_js %}
$.getScript('{{ script }}'); $.getScript('{{ script }}');
{% endfor %} {% endfor %}
</script> </script>
@@ -53,7 +53,7 @@
{% endif %} {% endif %}
{% for column in extra_columns %} {% for column in extra_columns %}
<div class="text-center"><span class="list-extra-column-label">{{ column.name }}</span>: {{ object|object_property:column.attribute }}</div> <div class="text-center"><span class="list-extra-column-label">{{ column.name }}</span>: {{ object|common_object_property:column.attribute }}</div>
{% endfor %} {% endfor %}
{% if not hide_links %} {% if not hide_links %}
@@ -42,7 +42,7 @@
{% if source_column.help_text %} {% if source_column.help_text %}
<span data-toggle="tooltip" data-placement="bottom" title="{{ source_column.help_text }}"> <span data-toggle="tooltip" data-placement="bottom" title="{{ source_column.help_text }}">
{% get_icon icon_path='mayan.apps.navigation.icons.icon_source_column_help_text' %} {% appearance_get_icon icon_path='mayan.apps.navigation.icons.icon_source_column_help_text' %}
</span> </span>
{% endif %} {% endif %}
</span> </span>
@@ -66,7 +66,7 @@
{% if source_column.help_text %} {% if source_column.help_text %}
<span data-toggle="tooltip" data-placement="bottom" title="{{ source_column.help_text }}"> <span data-toggle="tooltip" data-placement="bottom" title="{{ source_column.help_text }}">
{% get_icon icon_path='mayan.apps.navigation.icons.icon_source_column_help_text' %} {% appearance_get_icon icon_path='mayan.apps.navigation.icons.icon_source_column_help_text' %}
</span> </span>
{% endif %} {% endif %}
</span> </span>
@@ -117,7 +117,7 @@
{% endif %} {% endif %}
{% for column in extra_columns %} {% for column in extra_columns %}
<td>{{ object|object_property:column.attribute }}</td> <td>{{ object|common_object_property:column.attribute }}</td>
{% endfor %} {% endfor %}
{% if not hide_links %} {% if not hide_links %}
@@ -13,10 +13,10 @@
<div class="cols-xs-12"> <div class="cols-xs-12">
{% endif %} {% endif %}
{% if subtemplate.form %} {% if subtemplate.form %}
{% render_subtemplate subtemplate.name subtemplate.context as rendered_subtemplate %} {% common_render_subtemplate subtemplate.name subtemplate.context as rendered_subtemplate %}
{{ rendered_subtemplate }} {{ rendered_subtemplate }}
{% else %} {% else %}
{% render_subtemplate subtemplate.name subtemplate.context as rendered_subtemplate %} {% common_render_subtemplate subtemplate.name subtemplate.context as rendered_subtemplate %}
{{ rendered_subtemplate }} {{ rendered_subtemplate }}
{% endif %} {% endif %}
</div> </div>
@@ -44,6 +44,6 @@
{% include 'dynamic_search/search_box.html' %} {% include 'dynamic_search/search_box.html' %}
{% render_dashboard 'main' %} {% dashboards_render_dashboard 'main' %}
{% endblock %} {% endblock %}
@@ -1,10 +1,8 @@
{% load i18n %} {% load i18n %}
{% load navigation_tags %}
{% load smart_settings_tags %}
{% load common_tags %} {% load common_tags %}
{% load navigation_tags %} {% load navigation_tags %}
{% load smart_settings_tags %}
{% spaceless %} {% spaceless %}
<div class="panel-group" id="accordion-sidebar" role="tablist" aria-multiselectable="true"> <div class="panel-group" id="accordion-sidebar" role="tablist" aria-multiselectable="true">
@@ -14,7 +12,7 @@
{% for link in link_group.links %} {% for link in link_group.links %}
{% with 'active' as li_class_active %} {% with 'active' as li_class_active %}
{% with ' ' as link_classes %} {% with ' ' as link_classes %}
{% if link|get_type == "<class 'mayan.apps.navigation.classes.Menu'>" %} {% if link|common_get_type == "<class 'mayan.apps.navigation.classes.Menu'>" %}
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingOne"> <div class="panel-heading" role="tab" id="headingOne">
<h4 class="panel-title"> <h4 class="panel-title">
@@ -7,13 +7,8 @@ from django.utils.translation import ugettext_lazy as _
register = Library() register = Library()
@register.simple_tag
def appearance_icon_render(icon_class, enable_shadow=False):
return icon_class.render(extra_context={'enable_shadow': enable_shadow})
@register.filter @register.filter
def get_choice_value(field): def appearance_get_choice_value(field):
try: try:
return dict(field.field.choices)[field.value()] return dict(field.field.choices)[field.value()]
except TypeError: except TypeError:
@@ -23,10 +18,15 @@ def get_choice_value(field):
@register.filter @register.filter
def get_form_media_js(form): def appearance_get_form_media_js(form):
return [form.media.absolute_path(path) for path in form.media._js] return [form.media.absolute_path(path) for path in form.media._js]
@register.simple_tag @register.simple_tag
def get_icon(icon_path): def appearance_get_icon(icon_path):
return import_string(dotted_path=icon_path).render() return import_string(dotted_path=icon_path).render()
@register.simple_tag
def appearance_icon_render(icon_class, enable_shadow=False):
return icon_class.render(extra_context={'enable_shadow': enable_shadow})
@@ -7,6 +7,14 @@ from ..models import AutoAdminSingleton
register = Library() register = Library()
@register.inclusion_tag('autoadmin/credentials.html')
def autoadmin_partial():
try:
return {'autoadmin_properties': AutoAdminSingleton.objects.get()}
except AutoAdminSingleton.DoesNotExist:
return {'autoadmin_properties': None}
@register.simple_tag(takes_context=True) @register.simple_tag(takes_context=True)
def autoadmin_properties(context): def autoadmin_properties(context):
try: try:
@@ -15,11 +23,3 @@ def autoadmin_properties(context):
context['autoadmin_properties'] = None context['autoadmin_properties'] = None
return '' return ''
@register.inclusion_tag('autoadmin/credentials.html')
def autoadmin_partial():
try:
return {'autoadmin_properties': AutoAdminSingleton.objects.get()}
except AutoAdminSingleton.DoesNotExist:
return {'autoadmin_properties': None}
-41
View File
@@ -12,47 +12,6 @@ from django.utils.translation import ugettext
from .settings import setting_home_view from .settings import setting_home_view
@python_2_unicode_compatible
class Collection(object):
_registry = []
@classmethod
def get_all(cls):
return sorted(cls._registry, key=lambda entry: entry._order)
def __init__(
self, label, icon_class=None, link=None, queryset=None, model=None,
order=None
):
self._label = label
self._icon_class = icon_class
self._link = link
self._queryset = queryset
self._model = model
self._order = order or 99
self.__class__._registry.append(self)
def __str__(self):
return force_text(self.label)
def _get_children(self):
if self._queryset:
return self._queryset
else:
if self._model:
return self._model.objects.all()
def resolve(self):
self.children = self._get_children()
self.icon = self._icon
self.label = self._label
self.url = None
if self._link:
self.icon_class = getattr(self._link, 'icon_class', self._icon_class)
self.url = reverse(viewname=self._link.view, args=self._link.args)
return ''
@python_2_unicode_compatible @python_2_unicode_compatible
class ErrorLogNamespace(object): class ErrorLogNamespace(object):
def __init__(self, name, label=None): def __init__(self, name, label=None):
+4 -20
View File
@@ -1,7 +1,5 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from json import dumps
from django.template import Context, Library from django.template import Context, Library
from django.template.defaultfilters import truncatechars from django.template.defaultfilters import truncatechars
from django.template.loader import get_template from django.template.loader import get_template
@@ -12,7 +10,6 @@ from django.utils.translation import ugettext_lazy as _
import mayan import mayan
from mayan.apps.appearance.settings import setting_max_title_length from mayan.apps.appearance.settings import setting_max_title_length
from ..classes import Collection
from ..literals import MESSAGE_SQLITE_WARNING from ..literals import MESSAGE_SQLITE_WARNING
from ..utils import check_for_sqlite, return_attrib from ..utils import check_for_sqlite, return_attrib
@@ -70,36 +67,23 @@ def common_get_object_verbose_name(obj):
return type(obj) return type(obj)
@register.simple_tag
def get_collections():
return Collection.get_all()
@register.filter @register.filter
def get_encoded_parameter(item, parameters_dict): def common_get_type(value):
result = {}
for attrib_name, attrib in parameters_dict.items():
result[attrib_name] = return_attrib(item, attrib)
return dumps(result)
@register.filter
def get_type(value):
return force_text(type(value)) return force_text(type(value))
@register.filter @register.filter
def object_property(value, arg): def common_object_property(value, arg):
return return_attrib(value, arg) return return_attrib(value, arg)
@register.simple_tag @register.simple_tag
def project_information(attribute_name): def common_project_information(attribute_name):
return getattr(mayan, attribute_name) return getattr(mayan, attribute_name)
@register.simple_tag(takes_context=True) @register.simple_tag(takes_context=True)
def render_subtemplate(context, template_name, template_context): def common_render_subtemplate(context, template_name, template_context):
""" """
Renders the specified template with the mixed parent and Renders the specified template with the mixed parent and
subtemplate contexts subtemplate contexts
@@ -8,5 +8,5 @@ register = Library()
@register.simple_tag(takes_context=True) @register.simple_tag(takes_context=True)
def render_dashboard(context, name): def dashboards_render_dashboard(context, name):
return Dashboard.get(name=name).render(request=context.request) return Dashboard.get(name=name).render(request=context.request)
@@ -10,7 +10,7 @@
{% for page in pages %} {% for page in pages %}
<img <img
alt="{% trans 'Document page image preview' %}" alt="{% trans 'Document page image preview' %}"
src="{% get_api_image_url page width=width height=height %}" style="width: 100%;" src="{% documents_get_api_image_url page width=width height=height %}" style="width: 100%;"
/> />
{% endfor %} {% endfor %}
{% endblock %} {% endblock %}
@@ -7,12 +7,12 @@
<span class="spinner-container text-primary" <span class="spinner-container text-primary"
style="height: {% if display_full_height %}100%{% else %}{{ display_height|default:150 }}px{% endif %}; display: block;" style="height: {% if display_full_height %}100%{% else %}{{ display_height|default:150 }}px{% endif %}; display: block;"
> >
{% get_icon 'mayan.apps.documents.icons.icon_document_image_loading' %} {% appearance_get_icon 'mayan.apps.documents.icons.icon_document_image_loading' %}
</span> </span>
<img <img
alt="{% trans 'Document image' %}" alt="{% trans 'Document image' %}"
class="thin_border {{ image_classes }}" class="thin_border {{ image_classes }}"
data-url="{% get_api_image_url instance width=image_width height=image_height zoom=image_zoom rotation=image_rotation %}" data-url="{% documents_get_api_image_url instance width=image_width height=image_height zoom=image_zoom rotation=image_rotation %}"
src="#" src="#"
style="{% if image_max_height %}max-height: {{ image_max_height }}; {% endif %}" style="{% if image_max_height %}max-height: {{ image_max_height }}; {% endif %}"
/> />
@@ -7,7 +7,7 @@
{% else %} {% else %}
data-caption="<a class='a-caption' href='{{ instance.get_absolute_url }}'>{{ instance }} <i class='fa fa-external-link-alt'></i></a>" data-caption="<a class='a-caption' href='{{ instance.get_absolute_url }}'>{{ instance }} <i class='fa fa-external-link-alt'></i></a>"
{% endif %} {% endif %}
href="{% get_api_image_url instance width=size_preview_width height=size_preview_height %}" href="{% documents_get_api_image_url instance width=size_preview_width height=size_preview_height %}"
data-type="image" data-type="image"
{% if gallery_name %}data-fancybox="{{ gallery_name }}"{% endif %} {% if gallery_name %}data-fancybox="{{ gallery_name }}"{% endif %}
> >
@@ -6,5 +6,5 @@ register = Library()
@register.simple_tag @register.simple_tag
def get_api_image_url(obj, **kwargs): def documents_get_api_image_url(obj, **kwargs):
return obj.get_api_image_url(**kwargs) return obj.get_api_image_url(**kwargs)
@@ -3,7 +3,7 @@
{% load search_tags %} {% load search_tags %}
{% load smart_settings_tags %} {% load smart_settings_tags %}
{% get_search_models as search_models %} {% search_get_search_models as search_models %}
{% smart_setting global_name="SEARCH_DISABLE_SIMPLE_SEARCH" as setting_disable_simple_search %} {% smart_setting global_name="SEARCH_DISABLE_SIMPLE_SEARCH" as setting_disable_simple_search %}
{% if setting_disable_simple_search %} {% if setting_disable_simple_search %}
@@ -8,5 +8,5 @@ register = Library()
@register.simple_tag @register.simple_tag
def get_search_models(): def search_get_search_models():
return SearchModel.all() return SearchModel.all()
-20
View File
@@ -1,20 +0,0 @@
from __future__ import unicode_literals
from django import forms
class MultiItemForm(forms.Form):
def __init__(self, *args, **kwargs):
actions = kwargs.pop('actions', [])
if actions:
actions.insert(0, ['', '---'])
super(MultiItemForm, self).__init__(*args, **kwargs)
self.fields['action'].choices = actions
action = forms.ChoiceField(
label='', required=False, widget=forms.widgets.Select(
attrs={'class': 'select-auto-submit'}
)
)
@@ -1,7 +1,7 @@
{% load common_tags %} {% load common_tags %}
{% load navigation_tags %} {% load navigation_tags %}
{% if link|get_type == "<class 'mayan.apps.navigation.classes.Menu'>" %} {% if link|common_get_type == "<class 'mayan.apps.navigation.classes.Menu'>" %}
<li class="dropdown"> <li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="true"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="true">
{% if link.icon_class %}{{ link.icon_class.render }}{% endif %} {% if link.icon_class %}{{ link.icon_class.render }}{% endif %}
@@ -2,52 +2,11 @@ from __future__ import unicode_literals
from django.template import Library from django.template import Library
from ..classes import Link, Menu, SourceColumn from ..classes import Menu, SourceColumn
from ..forms import MultiItemForm
register = Library() register = Library()
@register.simple_tag()
def get_link(name):
return Link.get(name)
@register.simple_tag()
def get_menu(name):
return Menu.get(name)
@register.simple_tag(takes_context=True)
def get_menu_links(context, name, source=None, sort_results=None):
return Menu.get(name).resolve(context=context, source=source, sort_results=sort_results)
@register.simple_tag(takes_context=True)
def get_menus_links(context, names, source=None, sort_results=None):
result = []
for name in names.split(','):
for links in Menu.get(name=name).resolve(context=context, sort_results=sort_results):
if links:
result.append(links)
return result
@register.simple_tag(takes_context=True)
def get_multi_item_links_form(context, object_list):
actions = []
for link_set in Menu.get('multi item').resolve(context=context, source=object_list[0], sort_results=True):
for link in link_set['links']:
if hasattr(link, 'url'):
actions.append((link.url, link.text))
form = MultiItemForm(actions=actions)
context.update({'multi_item_form': form, 'multi_item_actions': actions})
return ''
@register.simple_tag(takes_context=True) @register.simple_tag(takes_context=True)
def navigation_get_sort_field_querystring(context, column): def navigation_get_sort_field_querystring(context, column):
return column.get_sort_field_querystring(context=context) return column.get_sort_field_querystring(context=context)
@@ -108,12 +67,6 @@ def navigation_resolve_menus(context, names, source=None, sort_results=None):
return result return result
@register.simple_tag(takes_context=True)
def resolve_link(context, link):
# This can be used to resolve links or menus too
return link.resolve(context=context)
@register.simple_tag(takes_context=True) @register.simple_tag(takes_context=True)
def navigation_source_column_resolve(context, column): def navigation_source_column_resolve(context, column):
if column: if column:
@@ -33,7 +33,7 @@
{% block content %} {% block content %}
<div class="cropper-main"> <div class="cropper-main">
<img id="cropper-img" src="{% get_api_image_url obj=content_object maximum_layer_order=layer.order %}"> <img id="cropper-img" src="{% documents_get_api_image_url obj=content_object maximum_layer_order=layer.order %}">
</div> </div>
<br> <br>