-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finished 'initial loading' feature with tests and django command, close
- Loading branch information
Showing
9 changed files
with
259 additions
and
160 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
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
67 changes: 0 additions & 67 deletions
67
...iecutter.project_name }}/django-apps/project_utils/commands/management/emencia_initial.py
This file was deleted.
Oops, something went wrong.
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
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
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
39 changes: 39 additions & 0 deletions
39
...iecutter.project_name }}/django-apps/project_utils/management/commands/emencia_initial.py
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from django.core.management.base import CommandError, BaseCommand | ||
|
||
from cms.api import Page | ||
|
||
from ...initial_loader import InitialDataLoader | ||
|
||
|
||
class Command(BaseCommand): | ||
""" | ||
Initial data loader. | ||
""" | ||
help = ( | ||
"Populate site with initial data loaded from a JSON file." | ||
) | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument( | ||
"dump", | ||
metavar="FILEPATH", | ||
help="Filepath to the JSON file with structure to load." | ||
) | ||
|
||
def handle(self, *args, **options): | ||
self.stdout.write( | ||
self.style.SUCCESS("=== Loading initial data ===") | ||
) | ||
|
||
# Validate database is empty | ||
existing = Page.objects.all() | ||
if existing.count(): | ||
raise CommandError( | ||
"Initial data can only be loaded when the database is empty from any " | ||
"objects. You should (carefuly) use Django command 'flush' before." | ||
) | ||
|
||
self.stdout.write("* Opened JSON source: {}".format(options["dump"])) | ||
|
||
maker = InitialDataLoader() | ||
maker.load(options["dump"]) |
Oops, something went wrong.