Projet

Général

Profil

0007-manager-factorize-role-with-OU-display-code-67025.patch

Valentin Deniaud, 17 août 2022 11:43

Télécharger (2,45 ko)

Voir les différences:

Subject: [PATCH 7/8] manager: factorize role with OU display code (#67025)

 src/authentic2/manager/role_views.py | 6 ++----
 src/authentic2/manager/utils.py      | 7 +++++++
 src/authentic2/manager/widgets.py    | 5 +----
 3 files changed, 10 insertions(+), 8 deletions(-)
src/authentic2/manager/role_views.py
43 43

  
44 44
from . import forms, resources, tables, views
45 45
from .journal_views import BaseJournalView
46
from .utils import get_ou_count, has_show_username, label_from_user
46
from .utils import has_show_username, label_from_role, label_from_user
47 47

  
48 48
User = get_user_model()
49 49

  
......
879 879

  
880 880
    def get_choice(self, obj):
881 881
        if isinstance(obj, Role):
882
            text = str(obj)
883
            if obj.ou and get_ou_count() > 1:
884
                text = f'{obj.ou} - {obj}'
882
            text = label_from_role(obj)
885 883
            key = 'role-%s'
886 884
        elif isinstance(obj, User):
887 885
            text = label_from_user(obj)
src/authentic2/manager/utils.py
46 46
    return OrganizationalUnit.objects.count()
47 47

  
48 48

  
49
def label_from_role(role):
50
    label = str(role)
51
    if role.ou and get_ou_count() > 1:
52
        label = f'{role.ou} - {role}'
53
    return label
54

  
55

  
49 56
@GlobalCache(timeout=10)
50 57
def has_show_username():
51 58
    return not OrganizationalUnit.objects.filter(show_username=False).exists()
src/authentic2/manager/widgets.py
130 130
    ]
131 131

  
132 132
    def label_from_instance(self, obj):
133
        label = str(obj)
134
        if obj.ou and utils.get_ou_count() > 1:
135
            label = f'{obj.ou} - {obj}'
136
        return label
133
        return utils.label_from_role(obj)
137 134

  
138 135

  
139 136
class ChooseRoleWidget(SearchRoleWidgetMixin, SimpleModelSelect2Widget):
140
-