Update tasks.py (#6446)

* Update tasks.py

- Exclude temporary settings when exporting data

* Remove duplicate code
This commit is contained in:
Oliver 2024-02-07 23:26:51 +11:00 committed by GitHub
parent 22af3e2f59
commit 59c78460c8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -504,20 +504,28 @@ def export_records(
with open(tmpfile, 'r') as f_in:
data = json.loads(f_in.read())
data_out = []
if include_permissions is False:
for entry in data:
if 'model' in entry:
# Clear out any permissions specified for a group
if entry['model'] == 'auth.group':
entry['fields']['permissions'] = []
model_name = entry.get('model', None)
# Clear out any permissions specified for a user
if entry['model'] == 'auth.user':
entry['fields']['user_permissions'] = []
# Ignore any temporary settings (start with underscore)
if model_name in ['common.inventreesetting', 'common.inventreeusersetting']:
if entry['fields'].get('key', '').startswith('_'):
continue
if model_name == 'auth.group':
entry['fields']['permissions'] = []
if model_name == 'auth.user':
entry['fields']['user_permissions'] = []
data_out.append(entry)
# Write the processed data to file
with open(filename, 'w') as f_out:
f_out.write(json.dumps(data, indent=2))
f_out.write(json.dumps(data_out, indent=2))
print('Data export completed')