Ticket #18277: ticket18277.diff

File ticket18277.diff, 3.5 KB (added by quinode, 3 years ago)

Code and documentation patch

  • django/core/management/templates.py

    From aa25e5bf1223039bf9100db4ea2b7269455ce1b7 Mon Sep 17 00:00:00 2001
    From: Dominique Guardiola <dguardiola@quinode.fr>
    Date: Mon, 7 May 2012 11:10:49 +0200
    Subject: [PATCH] --add_context option in start project command to allow what
     was intended in the documentation
    
    ---
     django/core/management/templates.py |   17 ++++++++++++++---
     1 files changed, 14 insertions(+), 3 deletions(-)
    
    diff --git a/django/core/management/templates.py b/django/core/management/templates.py
    index 735e29a..9fc49cc 100644
    a b class TemplateCommand(BaseCommand): 
    5151                    action='append', default=[],
    5252                    help='The file name(s) to render. '
    5353                         'Separate multiple extensions with commas, or use '
    54                          '-n multiple times.')
     54                         '-n multiple times.'),
     55        make_option('--add_context', '-a', dest='add_context',
     56                    action='append', default=[],
     57                    help='A key:value parameter to be rendered in the template.'
     58                         'Separate multiple variables with commas, like this:'
     59                         '-a foo:bar,one:two or use -a multiple times.')
    5560        )
    5661    requires_model_validation = False
    5762    # Can't import settings during this command, because they haven't
    class TemplateCommand(BaseCommand): 
    110115        base_subdir = '%s_template' % app_or_project
    111116        base_directory = '%s_directory' % app_or_project
    112117
    113         context = Context(dict(options, **{
     118        added_context = {
    114119            base_name: name,
    115120            base_directory: top_dir,
    116         }))
     121        }
     122
     123        # adding optional template variables passed in the command
     124        for param in options['add_context'][0].split(','):
     125            added_context[str(param.split(':')[0])] = param.split(':')[1]
     126
     127        context = Context(dict(options, **added_context))
    117128
    118129        # Setup a stub settings environment for template rendering
    119130        from django.conf import settings
  • docs/ref/django-admin.txt

    -- 
    1.7.8.3
    
    From 2b74195fae34138ab39cbd97819dbae8fd6e2901 Mon Sep 17 00:00:00 2001
    From: Dominique Guardiola <dguardiola@quinode.fr>
    Date: Mon, 7 May 2012 11:26:44 +0200
    Subject: [PATCH] doc modification
    
    ---
     docs/ref/django-admin.txt |    4 ++--
     1 files changed, 2 insertions(+), 2 deletions(-)
    
    diff --git a/docs/ref/django-admin.txt b/docs/ref/django-admin.txt
    index 0ea8252..093619b 100644
    a b through the template engine: the files whose extensions match the 
    909909with the ``--name`` option. The :class:`template context
    910910<django.template.Context>` used is:
    911911
    912 - Any option passed to the startapp command
     912- Any option passed to the startapp command through the ``--add_context`` option
    913913- ``app_name`` -- the app name as passed to the command
    914914- ``app_directory`` -- the full path of the newly created app
    915915
    through the template engine: the files whose extensions match the 
    972972with the ``--name`` option. The :class:`template context
    973973<django.template.Context>` used is:
    974974
    975 - Any option passed to the startproject command
     975- Any option passed to the startproject command through the ``--add_context`` option
    976976- ``project_name`` -- the project name as passed to the command
    977977- ``project_directory`` -- the full path of the newly created project
    978978- ``secret_key`` -- a random key for the :setting:`SECRET_KEY` setting
Back to Top