-
-
Notifications
You must be signed in to change notification settings - Fork 653
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only import pymongo when trying to connect to it
- Loading branch information
1 parent
82781de
commit 3d6e44c
Showing
1 changed file
with
7 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,6 @@ | |
|
||
# Third Party | ||
import requests | ||
from pymongo import MongoClient | ||
|
||
# wger | ||
from wger.core.models import Language | ||
|
@@ -28,7 +27,6 @@ | |
) | ||
from wger.nutrition.off import extract_info_from_off | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
|
@@ -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())}}): | ||
|
@@ -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 | ||
|
||
|