2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-29 20:16:44 +00:00

Merge pull request #2598 from SchrodingersGat/loaddata-skip-steps

Skips some specific steps when importing data
This commit is contained in:
Oliver 2022-02-03 16:29:02 +11:00 committed by GitHub
commit 0c1971bfbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 11 deletions

View File

@ -6,10 +6,16 @@ def isInTestMode():
Returns True if the database is in testing mode Returns True if the database is in testing mode
""" """
if 'test' in sys.argv: return 'test' in sys.argv
return True
return False
def isImportingData():
"""
Returns True if the database is currently importing data,
e.g. 'loaddata' command is performed
"""
return 'loaddata' in sys.argv
def canAppAccessDatabase(allow_test=False): def canAppAccessDatabase(allow_test=False):

View File

@ -12,6 +12,8 @@ from allauth.account.models import EmailAddress
import build.models import build.models
import InvenTree.helpers import InvenTree.helpers
import InvenTree.tasks import InvenTree.tasks
from InvenTree.ready import isImportingData
import part.models as part_models import part.models as part_models
@ -24,6 +26,10 @@ def check_build_stock(build: build.models.Build):
and send an email out to any subscribed users if stock is low. and send an email out to any subscribed users if stock is low.
""" """
# Do not notify if we are importing data
if isImportingData():
return
# Iterate through each of the parts required for this build # Iterate through each of the parts required for this build
lines = [] lines = []

View File

@ -13,6 +13,7 @@ from common.models import NotificationEntry
import InvenTree.helpers import InvenTree.helpers
import InvenTree.tasks import InvenTree.tasks
from InvenTree.ready import isImportingData
import part.models import part.models
@ -24,6 +25,10 @@ def notify_low_stock(part: part.models.Part):
Notify users who have starred a part when its stock quantity falls below the minimum threshold Notify users who have starred a part when its stock quantity falls below the minimum threshold
""" """
# Do not notify if we are importing data
if isImportingData():
return
# Check if we have notified recently... # Check if we have notified recently...
delta = timedelta(days=1) delta = timedelta(days=1)

View File

@ -8,6 +8,7 @@ from django.conf import settings
from maintenance_mode.core import set_maintenance_mode from maintenance_mode.core import set_maintenance_mode
from InvenTree.ready import isImportingData
from plugin import registry from plugin import registry
@ -19,13 +20,17 @@ class PluginAppConfig(AppConfig):
def ready(self): def ready(self):
if settings.PLUGINS_ENABLED: if settings.PLUGINS_ENABLED:
logger.info('Loading InvenTree plugins')
if not registry.is_loading: if isImportingData():
# this is the first startup logger.info('Skipping plugin loading for data import')
registry.collect_plugins() else:
registry.load_plugins() logger.info('Loading InvenTree plugins')
# drop out of maintenance if not registry.is_loading:
# makes sure we did not have an error in reloading and maintenance is still active # this is the first startup
set_maintenance_mode(False) registry.collect_plugins()
registry.load_plugins()
# drop out of maintenance
# makes sure we did not have an error in reloading and maintenance is still active
set_maintenance_mode(False)