Ticket #15095: createconfig.diff

File createconfig.diff, 1.3 KB (added by Frank Wiles, 14 years ago)

Patch

  • new file django/core/management/commands/createconfig.py

    diff --git a/django/core/management/commands/createconfig.py b/django/core/management/commands/createconfig.py
    new file mode 100644
    index 0000000..c98c2de
    - +  
     1import django
     2from django.core.management.base import copy_helper, CommandError, LabelCommand
     3from django.utils.importlib import import_module
     4import os
     5import re
     6from random import choice
     7
     8class Command(LabelCommand):
     9    help = "Generates a basic Django settings file."
     10    args = "/path/to/settings.py"
     11    label = 'path'
     12
     13    requires_model_validation = False
     14    # Can't import settings during this command, because they haven't
     15    # necessarily been created.
     16    can_import_settings = False
     17
     18    def handle_label(self, path, **options):
     19        # Create a random SECRET_KEY hash, and put it in the main settings.
     20        main_settings_file = os.path.join(django.__path__[0], 'conf', 'project_template', 'settings.py')
     21        settings_contents = open(main_settings_file, 'r').read()
     22        fp = open(path, 'w')
     23        secret_key = ''.join([choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for i in range(50)])
     24        settings_contents = re.sub(r"(?<=SECRET_KEY = ')'", secret_key + "'", settings_contents)
     25        fp.write(settings_contents)
     26        fp.close()
Back to Top