refactor underscore handeling into function

This commit is contained in:
Matthias 2021-11-01 22:33:56 +01:00
parent 78d9e906da
commit 61d3ea6293
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076

View File

@ -290,6 +290,17 @@ def split_model(model):
return model, app
def split_permission(app, perm):
"""split permission string into permission and model"""
permission_name, *model = perm.split('_')
# handle models that have underscores
if len(model) > 1:
app += '_' + '_'.join(model[:-1])
perm = permission_name + '_' + model[-1:][0]
model = model[-1:][0]
return perm, model
def update_group_roles(group, debug=False):
"""
@ -393,13 +404,7 @@ def update_group_roles(group, debug=False):
(app, perm) = permission_string.split('.')
# split up the permissions -> handle models with underscores
permission_name, *model = perm.split('_')
# handle models that have
if len(model) > 1:
app += '_' + '_'.join(model[:-1])
perm = permission_name + '_' + model[-1:][0]
model = model[-1:][0]
perm, model = split_permission(app, perm)
try:
content_type = ContentType.objects.get(app_label=app, model=model)