Move get_user_label to a module. Move user label text and separator to links modules.

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2018-09-16 21:16:07 -04:00
parent 51cf39f4d8
commit 654f2a1ad2
3 changed files with 14 additions and 10 deletions

View File

@@ -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,
)

View File

@@ -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)

View File

@@ -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