apps: prevent modifications of __class__.base_columns (#46451)
base_columns is not an instance attribute anymore.
This commit is contained in:
parent
ad6a7eaecf
commit
6bdf330cf4
|
@ -16,6 +16,7 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import copy
|
||||
import logging
|
||||
|
||||
import django.apps
|
||||
|
@ -30,6 +31,7 @@ from authentic2.constants import AUTHENTICATION_EVENTS_SESSION_KEY
|
|||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class AppConfig(django.apps.AppConfig):
|
||||
name = 'authentic2_cut'
|
||||
|
||||
|
@ -224,25 +226,29 @@ class AppConfig(django.apps.AppConfig):
|
|||
if view.__class__.__name__ == 'UsersView':
|
||||
ou = view.search_form.cleaned_data['ou']
|
||||
sequence = list(table.sequence)
|
||||
base_columns = copy.deepcopy(type(table).base_columns)
|
||||
|
||||
if ou and ou.slug == 'usagers':
|
||||
for column_name in ['username', 'link']:
|
||||
if column_name in table.base_columns:
|
||||
del table.base_columns[column_name]
|
||||
if column_name in base_columns:
|
||||
del base_columns[column_name]
|
||||
if column_name in sequence:
|
||||
sequence.remove(column_name)
|
||||
sequence.remove('email')
|
||||
sequence.insert(2, 'email')
|
||||
table.base_columns['preferred_username'] = tables.Column(
|
||||
base_columns['preferred_username'] = tables.Column(
|
||||
accessor='attributes.preferred_username', verbose_name=u'Nom d\'usage')
|
||||
sequence.insert(2, 'preferred_username')
|
||||
table.base_columns['validated'] = tables.BooleanColumn(
|
||||
base_columns['validated'] = tables.BooleanColumn(
|
||||
accessor='attributes.validated', verbose_name=u'Validé')
|
||||
sequence += ['validated']
|
||||
else:
|
||||
del table.base_columns['link']
|
||||
del base_columns['link']
|
||||
sequence.remove('link')
|
||||
table.columns = tables.columns.BoundColumns(table)
|
||||
|
||||
table.base_columns = base_columns
|
||||
table.sequence = sequence
|
||||
table.columns = tables.columns.BoundColumns(table, base_columns)
|
||||
return table
|
||||
|
||||
def a2_hook_api_modify_serializer(self, view, serializer):
|
||||
|
|
Loading…
Reference in New Issue