-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make updated project template work with local_settings.py.template
- Loading branch information
Showing
7 changed files
with
52 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
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 |
---|---|---|
|
@@ -8,6 +8,7 @@ syntax: glob | |
.DS_Store | ||
.coverage | ||
.idea | ||
local_settings.py | ||
build | ||
dist | ||
*.egg-info | ||
|
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 |
---|---|---|
@@ -1,26 +1,68 @@ | ||
from shutil import move | ||
import django | ||
from django.core.management import CommandError | ||
from os import path | ||
|
||
from django.core.management.commands.startproject import Command as BaseCommand | ||
from django.utils.crypto import get_random_string | ||
import os | ||
|
||
import mezzanine | ||
|
||
|
||
class Command(BaseCommand): | ||
help = BaseCommand.help.replace("Django", "Mezzanine") | ||
|
||
def handle(self, project_name=None, target=None, *args, **options): | ||
"""Overridden to provide a template value for nevercache_key. The | ||
method is copied verbatim from startproject.Command.""" | ||
def handle(self, *args, **options): | ||
|
||
# Overridden to provide a template value for nevercache_key. The | ||
# method is copied verbatim from startproject.Command.""" | ||
chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)' | ||
options['nevercache_key'] = get_random_string(50, chars) | ||
|
||
super(Command, self).handle(project_name, target, **options) | ||
# Indicate that local_settings.py.template should be rendered | ||
options['files'] = ['local_settings.py.template'] | ||
|
||
super(Command, self).handle(*args, **options) | ||
|
||
if django.VERSION < (1, 8): | ||
project_name, target = args + (None,) * max(0, 2 - len(args)) | ||
else: | ||
project_name, target = options.pop('name'), options.pop('directory') | ||
|
||
project_dir = self.get_project_directory(project_name, target) | ||
project_app_dir = os.path.join(project_dir, project_name) | ||
|
||
# Now rename "local_settings.py.template" to "local_settings.py" | ||
move(os.path.join(project_app_dir, "local_settings.py.template"), | ||
os.path.join(project_app_dir, "local_settings.py")) | ||
|
||
def get_project_directory(self, name, target): | ||
"""This code is copied verbatim from Django's TemplateCommand.handle(), | ||
but with the directory creation commented out.""" | ||
|
||
# if some directory is given, make sure it's nicely expanded | ||
if target is None: | ||
top_dir = path.join(os.getcwd(), name) | ||
# try: | ||
# os.makedirs(top_dir) | ||
# except OSError as e: | ||
# if e.errno == errno.EEXIST: | ||
# message = "'%s' already exists" % top_dir | ||
# else: | ||
# message = e | ||
# raise CommandError(message) | ||
else: | ||
top_dir = os.path.abspath(path.expanduser(target)) | ||
if not os.path.exists(top_dir): | ||
raise CommandError("Destination directory '%s' does not " | ||
"exist, please create it first." % top_dir) | ||
|
||
return top_dir | ||
|
||
def handle_template(self, template, subdir): | ||
"""Use Mezzanine's project template by default. The method of picking | ||
the default directory is copied from Django's TemplateCommand.""" | ||
if template is None: | ||
return path.join(mezzanine.__path__[0], subdir) | ||
return super(Command, self).handle(template, subdir) | ||
return super(Command, self).handle_template(template, subdir) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,5 @@ | |
*.db | ||
.DS_Store | ||
.coverage | ||
/local_settings.py | ||
local_settings.py | ||
/static |
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 |
---|---|---|
|
@@ -4,7 +4,7 @@ syntax: glob | |
*.db | ||
.DS_Store | ||
.coverage | ||
local_settings.py | ||
|
||
syntax: regexp | ||
^static/ | ||
^local_settings.py |
File renamed without changes.