Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Move populatedb command to a management command
Michał Ociepkaf1397f81dff3
diff --git a/saleor/product/management/__init__.py b/saleor/product/management/__init__.pynew file mode 100644index 0000000000..e69de29bb2diff --git a/saleor/product/management/commands/__init__.py b/saleor/product/management/commands/__init__.pynew file mode 100644index 0000000000..e69de29bb2diff --git a/saleor/product/management/commands/populatedb.py b/saleor/product/management/commands/populatedb.pynew file mode 100644index 0000000000..64ff0367d7--- /dev/null+++ b/saleor/product/management/commands/populatedb.py@@ -0,0 +1,21 @@+from os.path import exists, join++from django.core.management.base import BaseCommand, CommandError+from django.core.management import call_command++from utils.create_random_data import create_items+++class Command(BaseCommand):+ help = 'Populate database with test objects'+ BASE_DIR = r'saleor/static/placeholders/'+ required_dirs = [join(BASE_DIR, 'shirts'), join(BASE_DIR, 'bags')]++ def handle(self, *args, **options):+ if not all(exists(path) for path in self.required_dirs):+ msg = 'Directories %s with images are required.' % ', '.join(+ self.required_dirs)+ raise CommandError(msg)+ call_command('syncdb', interactive=False)+ for msg in create_items(self.BASE_DIR, 10):+ self.stdout.write(msg)diff --git a/setup.py b/setup.pyindex bbfbef27f4..276c2e2506 100755--- a/setup.py+++ b/setup.py@@ -4,23 +4,6 @@ import osos.environ.setdefault('DJANGO_SETTINGS_MODULE', 'saleor.settings')--class Command(Command):- user_options = []- initialize_options = lambda self: None- finalize_options = lambda self: None---class PopulateDatabase(Command):- description = "Populate database with test objects"-- def run(self):- from django.core.management import call_command- from utils.create_random_data import create_items- call_command('syncdb', interactive=True, migrate_all=True)- create_items('saleor/static/placeholders/', 10)--setup(name='saleor',author='Mirumee Software',@@ -56,8 +39,5 @@ setup('mock==1.0.1','purl>=0.4.1',],- test_suite='saleor.tests.suite',- cmdclass={- 'populatedb': PopulateDatabase- }+ test_suite='saleor.tests.suite')diff --git a/utils/create_random_data.py b/utils/create_random_data.pyindex 4d6816aab0..ecba673d9e 100644--- a/utils/create_random_data.py+++ b/utils/create_random_data.py@@ -128,5 +128,5 @@ def create_items(placeholder_dir, how_many=10):create_variant(bag)- print("Shirt - %s %s Variants" % (shirt, shirt.variants.count()))- print("Bag - %s %s Variants" % (bag, bag.variants.count()))+ yield "Shirt - %s %s Variants" % (shirt, shirt.variants.count())+ yield "Bag - %s %s Variants" % (bag, bag.variants.count())