mirror of
https://github.com/django/django.git
synced 2024-12-22 17:16:24 +00:00
Fixed #24971 -- Made startapp generate an apps.py
This commit is contained in:
parent
c5eca74619
commit
e6dd7f995a
@ -0,0 +1 @@
|
||||
default_app_config = '{{ app_name }}.apps.{{ camel_case_app_name }}Config'
|
5
django/conf/app_template/apps.py
Normal file
5
django/conf/app_template/apps.py
Normal file
@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class {{ camel_case_app_name }}Config(AppConfig):
|
||||
name = '{{ app_name }}'
|
@ -98,10 +98,13 @@ class TemplateCommand(BaseCommand):
|
||||
base_name = '%s_name' % app_or_project
|
||||
base_subdir = '%s_template' % app_or_project
|
||||
base_directory = '%s_directory' % app_or_project
|
||||
camel_case_name = 'camel_case_%s_name' % app_or_project
|
||||
camel_case_value = ''.join(x for x in name.title() if x != '_')
|
||||
|
||||
context = Context(dict(options, **{
|
||||
base_name: name,
|
||||
base_directory: top_dir,
|
||||
camel_case_name: camel_case_value,
|
||||
'docs_version': get_docs_version(),
|
||||
'django_version': django.__version__,
|
||||
'unicode_literals': '' if six.PY3 else 'from __future__ import unicode_literals\n\n',
|
||||
|
@ -1094,8 +1094,13 @@ with the ``--name`` option. The :class:`template context
|
||||
options)
|
||||
- ``app_name`` -- the app name as passed to the command
|
||||
- ``app_directory`` -- the full path of the newly created app
|
||||
- ``camel_case_app_name`` -- the app name in camel case format
|
||||
- ``docs_version`` -- the version of the documentation: ``'dev'`` or ``'1.x'``
|
||||
|
||||
.. versionadded:: 1.9
|
||||
|
||||
``camel_case_app_name`` was added.
|
||||
|
||||
.. _render_warning:
|
||||
|
||||
.. warning::
|
||||
|
@ -275,6 +275,9 @@ Management Commands
|
||||
* The :djadmin:`createcachetable` command now has a ``--dry-run`` flag to
|
||||
print out the SQL rather than execute it.
|
||||
|
||||
* The :djadmin:`startapp` command creates an ``apps.py`` file and adds
|
||||
``default_app_config`` in ``__init__.py``.
|
||||
|
||||
Models
|
||||
^^^^^^
|
||||
|
||||
|
@ -592,6 +592,14 @@ class DjangoAdminSettingsDirectory(AdminScriptTestCase):
|
||||
self.addCleanup(shutil.rmtree, app_path)
|
||||
self.assertNoOutput(err)
|
||||
self.assertTrue(os.path.exists(app_path))
|
||||
with open(os.path.join(app_path, 'apps.py'), 'r') as f:
|
||||
content = f.read()
|
||||
self.assertIn("class SettingsTestConfig(AppConfig)", content)
|
||||
self.assertIn("name = 'settings_test'", content)
|
||||
with open(os.path.join(app_path, '__init__.py'), 'r') as f:
|
||||
content = f.read()
|
||||
expected_content = "default_app_config = 'settings_test.apps.SettingsTestConfig'"
|
||||
self.assertIn(expected_content, content)
|
||||
if not PY3:
|
||||
with open(os.path.join(app_path, 'models.py'), 'r') as fp:
|
||||
content = fp.read()
|
||||
|
Loading…
Reference in New Issue
Block a user