mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Update tasks.py (#6446)
* Update tasks.py - Exclude temporary settings when exporting data * Remove duplicate code
This commit is contained in:
parent
22af3e2f59
commit
59c78460c8
24
tasks.py
24
tasks.py
@ -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')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user