Skip to content

Commit

Permalink
Only import pymongo when trying to connect to it
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandgeider committed Feb 23, 2025
1 parent 82781de commit 3d6e44c
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions wger/nutrition/management/commands/import-off-products.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

# Third Party
import requests
from pymongo import MongoClient

# wger
from wger.core.models import Language
Expand All @@ -28,7 +27,6 @@
)
from wger.nutrition.off import extract_info_from_off


logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -65,6 +63,13 @@ def add_arguments(self, parser):
)

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())}}):
Expand Down Expand Up @@ -128,13 +133,6 @@ def import_full_dump(self, languages: dict[str:int], destination: str):
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

Expand Down

0 comments on commit 3d6e44c

Please sign in to comment.