Ticket #17517: 17517-2.diff

File 17517-2.diff, 5.8 KB (added by Florian Apolloner, 12 years ago)

replace -f/--file with -n/--name

  • django/core/management/templates.py

    diff --git a/django/core/management/templates.py b/django/core/management/templates.py
    index 0a6a3a8..1d26e97 100644
    a b class TemplateCommand(BaseCommand):  
    4848                    help='The file extension(s) to render (default: "py") '
    4949                         'Separate multiple extensions with commas, or use '
    5050                         '-e multiple times.'),
     51        make_option('--name', '-n', dest='files',
     52                    action='append', default=[],
     53                    help='The file name(s) to render '
     54                         'Separate multiple extensions with commas, or use '
     55                         '-n multiple times.')
    5156        )
    5257    requires_model_validation = False
    5358    # Can't import settings during this command, because they haven't
    class TemplateCommand(BaseCommand):  
    8994
    9095        extensions = tuple(
    9196            handle_extensions(options.get('extensions'), ignored=()))
     97        extra_files = []
     98        for file in options.get('files'):
     99            extra_files.extend(map(lambda x: x.strip(), file.split(',')))
    92100        if self.verbosity >= 2:
    93101            self.stdout.write("Rendering %s template files with "
    94102                              "extensions: %s\n" %
    95103                              (app_or_project, ', '.join(extensions)))
     104            self.stdout.write("Rendering %s template files with "
     105                              "filenames: %s\n" %
     106                              (app_or_project, ', '.join(extra_files)))
    96107
    97108        base_name = '%s_name' % app_or_project
    98109        base_subdir = '%s_template' % app_or_project
    class TemplateCommand(BaseCommand):  
    142153                # accidentally render Django templates files
    143154                with open(old_path, 'r') as template_file:
    144155                    content = template_file.read()
    145                 if filename.endswith(extensions):
     156                if filename.endswith(extensions) or filename in extra_files:
    146157                    template = Template(content)
    147158                    content = template.render(context)
    148159                with open(new_path, 'w') as new_file:
  • docs/ref/django-admin.txt

    diff --git a/docs/ref/django-admin.txt b/docs/ref/django-admin.txt
    index 4bde86c..a44bcff 100644
    a b creating the ``myapp`` app::  
    951951
    952952When Django copies the app template files, it also renders the files
    953953whose extension matches those passed with the ``--extension`` option (``py``
    954 by default) using the template engine. The :class:`template context
     954by default) and those files which names are passed with the ``--name`` option
     955using the template engine. The :class:`template context
    955956<django.template.Context>` used is:
    956957
    957958- Any option passed to the startapp command
    when creating the ``myproject`` project::  
    10131014
    10141015When Django copies the project template files, it will also render the files
    10151016whose extension matches those passed with the ``--extension`` option (``py``
    1016 by default) using the template engine. The :class:`template context
     1017by default) and those files which names are passed with the ``--name`` option
     1018using the template engine. The :class:`template context
    10171019<django.template.Context>` used is:
    10181020
    10191021- Any option passed to the startproject command
  • new file tests/regressiontests/admin_scripts/custom_templates/project_template/additional_dir/Procfile

    diff --git a/tests/regressiontests/admin_scripts/custom_templates/project_template/additional_dir/Procfile b/tests/regressiontests/admin_scripts/custom_templates/project_template/additional_dir/Procfile
    new file mode 100644
    index 0000000..032f0bc
    - +  
     1# some file for {{ project_name }} test project
     2 No newline at end of file
  • new file tests/regressiontests/admin_scripts/custom_templates/project_template/additional_dir/requirements.txt

    diff --git a/tests/regressiontests/admin_scripts/custom_templates/project_template/additional_dir/requirements.txt b/tests/regressiontests/admin_scripts/custom_templates/project_template/additional_dir/requirements.txt
    new file mode 100644
    index 0000000..032f0bc
    - +  
     1# some file for {{ project_name }} test project
     2 No newline at end of file
  • tests/regressiontests/admin_scripts/tests.py

    diff --git a/tests/regressiontests/admin_scripts/tests.py b/tests/regressiontests/admin_scripts/tests.py
    index 17a2ccb..3939825 100644
    a b class StartProject(LiveServerTestCase, AdminScriptTestCase):  
    14891489        self.assertNoOutput(err)
    14901490        self.assertTrue(os.path.isdir(testproject_dir))
    14911491        self.assertTrue(os.path.exists(os.path.join(testproject_dir, 'run.py')))
     1492
     1493    def test_custom_project_template(self):
     1494        "Make sure the startproject management command is able to render custom files"
     1495        template_path = os.path.join(test_dir, 'admin_scripts', 'custom_templates', 'project_template')
     1496        args = ['startproject', '--template', template_path, 'customtestproject', '-e', 'txt', '-n', 'Procfile']
     1497        testproject_dir = os.path.join(test_dir, 'customtestproject')
     1498
     1499        out, err = self.run_django_admin(args)
     1500        self.addCleanup(shutil.rmtree, testproject_dir)
     1501        self.assertNoOutput(err)
     1502        self.assertTrue(os.path.isdir(testproject_dir))
     1503        self.assertTrue(os.path.exists(os.path.join(testproject_dir, 'additional_dir')))
     1504        base_path = os.path.join(testproject_dir, 'additional_dir')
     1505        for f in ('Procfile', 'additional_file.py', 'requirements.txt'):
     1506            self.assertTrue(os.path.exists(os.path.join(base_path, f)))
     1507            with open(os.path.join(base_path, f)) as fh:
     1508                self.assertEqual(fh.read(),
     1509                    '# some file for customtestproject test project')
Back to Top