mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
new command to cleanup old settings in db
This commit is contained in:
parent
369864574e
commit
2347f15c2e
40
InvenTree/InvenTree/management/commands/clean_settings.py
Normal file
40
InvenTree/InvenTree/management/commands/clean_settings.py
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
"""
|
||||||
|
Custom management command to cleanup old settings that are not defined anymore
|
||||||
|
"""
|
||||||
|
|
||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
"""
|
||||||
|
Cleanup old (undefined) settings in the database
|
||||||
|
"""
|
||||||
|
|
||||||
|
def handle(self, *args, **kwargs):
|
||||||
|
|
||||||
|
print("Collecting settings")
|
||||||
|
from common.models import InvenTreeSetting, InvenTreeUserSetting
|
||||||
|
|
||||||
|
# general settings
|
||||||
|
db_settings = InvenTreeSetting.objects.all()
|
||||||
|
model_settings = InvenTreeSetting.GLOBAL_SETTINGS
|
||||||
|
|
||||||
|
# check if key exist and delete if not
|
||||||
|
for setting in db_settings:
|
||||||
|
print(setting.key)
|
||||||
|
if setting.key not in model_settings:
|
||||||
|
setting.delete()
|
||||||
|
print(f"deleted setting '{setting.key}'")
|
||||||
|
|
||||||
|
# user settings
|
||||||
|
db_settings = InvenTreeUserSetting.objects.all()
|
||||||
|
model_settings = InvenTreeUserSetting.GLOBAL_SETTINGS
|
||||||
|
|
||||||
|
# check if key exist and delete if not
|
||||||
|
for setting in db_settings:
|
||||||
|
print(setting.key)
|
||||||
|
if setting.key not in model_settings:
|
||||||
|
setting.delete()
|
||||||
|
print(f"deleted user setting '{setting.key}'")
|
||||||
|
|
||||||
|
print("checked all settings")
|
Loading…
Reference in New Issue
Block a user