nephila / djangocms-installer

Console wizard to bootstrap django CMS projects
https://djangocms-installer.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
177 stars 78 forks source link

Correct white space and imports in settings.py generated by djangocms-installer #306

Closed cezar77 closed 6 years ago

cezar77 commented 7 years ago

The settings.py generated by djangocms-installer is not very well formed. There are 3 general issues that bother me:

1. The module os is imported twice.

The first 3 lines of settings.py are:

import os
gettext = lambda s: s
DATA_DIR = os.path.dirname(os.path.dirname(__file__))

After that a docstring follows and the following lines:

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

There is redundancy here. Also there should be preferably no code before the initial docstring.

2. The white space between the lines is irregular and occasionally to big.

After the comment:

# Application definition

there are 5 lines, then there is another line of code followed by 3 lines. Few lines later there is a comment as a prelude to the database configuration followed by 4 empty lines. The database configuration is instead found toward the end of the file.

3. The indentation of the constant TEMPLATES is malformed.

The indentation for TEMPLATES[0]['OPTIONS']['context_processors'] and TEMPLATES[0]['OPTIONS']['loaders'] is only 4 spaces (1 tab), where it should be 16 spaces (4 tabs). That should be obvious from the structure of the aforementioned constant.

For me it worked to change 2 lines in the function _build_settings in the file __init__.py in the directory django. That is the following block starting on line 263:


text.append(data.TEMPLATES_1_8.format(
     loaders=(',\n' + (spacer * 4)).join(['\'{0}\''.format(var) for var in vars.TEMPLATE_LOADERS]),
     processors=(',\n' + (spacer * 4)).join(['\'{0}\''.format(var) for var in processors]),
     dirs='os.path.join(BASE_DIR, \'{0}\', \'templates\'),'.format(config_data.project_name)
))

The changes are in bold. However I don't know if this would be a general solution.

yakky commented 7 years ago

The problem with settings.py formatting is that installer uses string replacing over the one generated by django-admin for improved compatibility with different django versions The TEMPLATES indentation should be now easy to fix as we don't need to support old syntax anymore, others might be more problematic If you want to propose improvements, feel free to open PRs

yakky commented 6 years ago

Fixed by #314 Thanks @cezar77 for reporting