From 654f2a1ad25f99ccc98fb23a67fe071ed16270ce Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Sun, 16 Sep 2018 21:16:07 -0400 Subject: [PATCH] Move get_user_label to a module. Move user label text and separator to links modules. Signed-off-by: Roberto Rosario --- mayan/apps/common/apps.py | 13 +++---------- mayan/apps/common/links.py | 4 ++++ mayan/apps/common/utils.py | 7 +++++++ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/mayan/apps/common/apps.py b/mayan/apps/common/apps.py index c70585fc1b..bebc754dba 100644 --- a/mayan/apps/common/apps.py +++ b/mayan/apps/common/apps.py @@ -16,7 +16,6 @@ from django.utils.encoding import force_text from django.utils.translation import ugettext_lazy as _ from mayan.celery import app -from navigation.classes import Separator, Text from .handlers import ( handler_pre_initial_setup, handler_pre_upgrade, @@ -26,7 +25,8 @@ from .links import ( link_about, link_check_version, link_code, link_current_user_details, link_current_user_edit, link_current_user_locale_profile_edit, link_documentation, link_forum, link_license, link_object_error_list_clear, - link_packages_licenses, link_setup, link_support, link_tools + link_packages_licenses, link_setup, link_support, link_tools, + separator_user_label, text_user_label ) from .literals import DELETE_STALE_UPLOADS_INTERVAL, MESSAGE_SQLITE_WARNING @@ -84,13 +84,6 @@ class CommonApp(MayanAppConfig): name = 'common' verbose_name = _('Common') - @staticmethod - def get_user_label_text(context): - if not context['request'].user.is_authenticated: - return _('Anonymous') - else: - return context['request'].user.get_full_name() or context['request'].user - def ready(self): super(CommonApp, self).ready() if check_for_sqlite(): @@ -129,7 +122,7 @@ class CommonApp(MayanAppConfig): ) menu_user.bind_links( links=( - Text(text=CommonApp.get_user_label_text), Separator(), + separator_user_label, text_user_label, link_current_user_details, link_current_user_edit, link_current_user_locale_profile_edit, ) diff --git a/mayan/apps/common/links.py b/mayan/apps/common/links.py index 16fdcfe2d7..dbd6734a8f 100644 --- a/mayan/apps/common/links.py +++ b/mayan/apps/common/links.py @@ -4,6 +4,7 @@ from django.apps import apps from django.utils.translation import ugettext_lazy as _ from navigation import Link +from navigation.classes import Separator, Text from .icons import ( icon_about, icon_check_version, icon_code, icon_current_user_details, @@ -13,6 +14,7 @@ from .icons import ( icon_packages_licenses, icon_setup, icon_support, icon_tools ) from .permissions_runtime import permission_error_log_view +from .utils import get_user_label_text def get_kwargs_factory(variable_name): @@ -103,3 +105,5 @@ link_support = Link( link_tools = Link( icon_class=icon_tools, text=_('Tools'), view='common:tools_list' ) +separator_user_label = Separator() +text_user_label = Text(text=get_user_label_text) diff --git a/mayan/apps/common/utils.py b/mayan/apps/common/utils.py index 8406efb1a1..2fd859b481 100644 --- a/mayan/apps/common/utils.py +++ b/mayan/apps/common/utils.py @@ -68,6 +68,13 @@ def encapsulate(function): return lambda: function +def get_user_label_text(context): + if not context['request'].user.is_authenticated: + return _('Anonymous') + else: + return context['request'].user.get_full_name() or context['request'].user + + def fs_cleanup(filename, file_descriptor=None, suppress_exceptions=True): """ Tries to remove the given filename. Ignores non-existent files