mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Skips some specific steps when importing data
- We need to prevent certain operations from running when we are importing data - This is to prevent unique database constraints from being violated - Do not register plugins during data import - Do not launch notification events
This commit is contained in:
parent
eef15b13ec
commit
78b1c7a22b
@ -6,10 +6,16 @@ def isInTestMode():
|
||||
Returns True if the database is in testing mode
|
||||
"""
|
||||
|
||||
if 'test' in sys.argv:
|
||||
return True
|
||||
return 'test' in sys.argv
|
||||
|
||||
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):
|
||||
|
@ -12,6 +12,8 @@ from allauth.account.models import EmailAddress
|
||||
import build.models
|
||||
import InvenTree.helpers
|
||||
import InvenTree.tasks
|
||||
from InvenTree.ready import isImportingData
|
||||
|
||||
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.
|
||||
"""
|
||||
|
||||
# Do not notify if we are importing data
|
||||
if isImportingData():
|
||||
return
|
||||
|
||||
# Iterate through each of the parts required for this build
|
||||
|
||||
lines = []
|
||||
|
@ -13,6 +13,7 @@ from common.models import NotificationEntry
|
||||
|
||||
import InvenTree.helpers
|
||||
import InvenTree.tasks
|
||||
from InvenTree.ready import isImportingData
|
||||
|
||||
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
|
||||
"""
|
||||
|
||||
# Do not notify if we are importing data
|
||||
if isImportingData():
|
||||
return
|
||||
|
||||
# Check if we have notified recently...
|
||||
delta = timedelta(days=1)
|
||||
|
||||
|
@ -8,6 +8,7 @@ from django.conf import settings
|
||||
|
||||
from maintenance_mode.core import set_maintenance_mode
|
||||
|
||||
from InvenTree.ready import isImportingData
|
||||
from plugin import registry
|
||||
|
||||
|
||||
@ -19,13 +20,17 @@ class PluginAppConfig(AppConfig):
|
||||
|
||||
def ready(self):
|
||||
if settings.PLUGINS_ENABLED:
|
||||
logger.info('Loading InvenTree plugins')
|
||||
|
||||
if isImportingData():
|
||||
logger.info('Skipping plugin loading for data import')
|
||||
else:
|
||||
logger.info('Loading InvenTree plugins')
|
||||
|
||||
if not registry.is_loading:
|
||||
# this is the first startup
|
||||
registry.collect_plugins()
|
||||
registry.load_plugins()
|
||||
if not registry.is_loading:
|
||||
# this is the first startup
|
||||
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)
|
||||
# drop out of maintenance
|
||||
# makes sure we did not have an error in reloading and maintenance is still active
|
||||
set_maintenance_mode(False)
|
||||
|
Loading…
Reference in New Issue
Block a user