Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Only import pymongo when trying to connect to it

Roland Geider3d6e44c711ac
diff --git a/wger/nutrition/management/commands/import-off-products.py b/wger/nutrition/management/commands/import-off-products.py
index ffad7af79..cccef831a 100644
--- a/wger/nutrition/management/commands/import-off-products.py
+++ b/wger/nutrition/management/commands/import-off-products.py
@@ -18,7 +18,6 @@ import os
# Third Party
import requests
-from pymongo import MongoClient
# wger
from wger.core.models import Language
@@ -28,7 +27,6 @@ from wger.nutrition.management.products import (
)
from wger.nutrition.off import extract_info_from_off
-
logger = logging.getLogger(__name__)
@@ -65,6 +63,13 @@ class Command(ImportProductCommand):
)
def import_mongo(self, languages: dict[str:int]):
+ try:
+ # Third Party
+ from pymongo import MongoClient
+ except ImportError:
+ self.stdout.write('Please install pymongo, `pip install pymongo`')
+ return
+
client = MongoClient('mongodb://off:[email protected]', port=27017)
db = client.admin
for product in db.products.find({'lang': {'$in': list(languages.keys())}}):
@@ -128,13 +133,6 @@ class Command(ImportProductCommand):
tmp_folder.cleanup()
def handle(self, **options):
- try:
- # Third Party
- from pymongo import MongoClient
- except ImportError:
- self.stdout.write('Please install pymongo, `pip install pymongo`')
- return
-
if options['mode'] == 'insert':
self.mode = Mode.INSERT