Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installer addons PoC #360

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions djangocms_installer/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ def parse(args):
'provided values')
parser.add_argument('--wizard', '-w', dest='wizard', action='store_true',
default=False, help='Run the configuration wizard')
parser.add_argument('--addons', '-a', dest='addons', action='append',
choices=list(data.ADDONS.keys()),
default=[], help='Add one of the selected addons')
parser.add_argument('--verbose', dest='verbose', action='store_true',
default=False,
help='Be more verbose and don\'t swallow subcommands output')
Expand Down Expand Up @@ -301,17 +304,16 @@ def parse(args):
else:
requirements.append('Django<{0}'.format(less_than_version(django_version)))

if django_version == '2.2':
requirements.extend(data.REQUIREMENTS['django-2.2'])
elif django_version == '2.1':
requirements.extend(data.REQUIREMENTS['django-2.1'])
elif django_version == '2.0':
requirements.extend(data.REQUIREMENTS['django-2.0'])
elif django_version == '1.11':
requirements.extend(data.REQUIREMENTS['django-1.11'])
requirements.extend(data.REQUIREMENTS['django-%s' % django_version])

requirements.extend(data.REQUIREMENTS['default'])

if args.addons:
for addon in args.addons:
requirements.extend(
data.ADDONS[addon]['requirements']['django-%s' % django_version]
)

setattr(args, 'requirements', '\n'.join(requirements).strip())

# Convenient shortcuts
Expand Down
46 changes: 46 additions & 0 deletions djangocms_installer/config/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,52 @@
],
}

ADDONS = {
'blog': {
'requirements': {
'django-1.11': [
'djangocms-blog',
],
'django-2.0': [
'djangocms-blog',
],
'django-2.1': [
'djangocms-blog',
],
'django-2.2': [
'djangocms-blog',
],
},
'installed_apps': [
'aldryn_apphooks_config',
'parler',
'taggit',
'taggit_autosuggest',
'meta',
'djangocms_blog',
'sortedm2m'
],
'settings': """
META_SITE_PROTOCOL = 'http'
META_USE_SITES = True
""",
'urls': [
'djangocms_blog.taggit_urls'
]

}
}
ADDONS_URLCONF = """
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals

from django.conf.urls import include, url

urlpatterns = [
%s
]
"""

TEMPLATES_1_8 = """
TEMPLATES = [
{{
Expand Down
6 changes: 6 additions & 0 deletions djangocms_installer/config/urls_i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
{'sitemaps': {'cmspages': CMSSitemap}}),
]

try:
from .urls_addons import urlpatterns as addons_urlpatterns
urlpatterns.extend(addons_urlpatterns)
except ImportError:
pass

urlpatterns += i18n_patterns(
url(r'^admin/', admin.site.urls), # NOQA
url(r'^', include('cms.urls')),
Expand Down
6 changes: 6 additions & 0 deletions djangocms_installer/config/urls_noi18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
{'sitemaps': {'cmspages': CMSSitemap}}),
]

try:
from .urls_addons import urlpatterns as addons_urlpatterns
urlpatterns.extend(addons_urlpatterns)
except ImportError:
pass

urlpatterns += [
url(r'^admin/', admin.site.urls), # NOQA
url(r'^', include('cms.urls')),
Expand Down
24 changes: 24 additions & 0 deletions djangocms_installer/django/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,25 @@ def copy_files(config_data):
shutil.copy(filename, os.path.join(config_data.project_path, '..'))


def patch_urls(config_data):

if not os.path.exists(config_data.urlconf_path):
sys.stderr.write(
'Error while creating target project, '
'please check the given urlconf: {0}\n'.format(config_data.urlconf_path)
)
return sys.exit(5)

addons_urlconf = os.path.join(os.path.dirname(config_data.urlconf_path), 'urls_addons.py')
addons_urls = [
"url(r'^', include('%s'))," % url
for addon in config_data.addons
for url in data.ADDONS[addon]['urls']
]
with open(addons_urlconf, 'w') as urlconf_fp:
urlconf_fp.write(data.ADDONS_URLCONF % ','.join(addons_urls))


def patch_settings(config_data):
"""
Modify the settings file created by Django injecting the django CMS
Expand Down Expand Up @@ -251,6 +270,11 @@ def _build_settings(config_data):
if not config_data.no_plugins:
apps.extend(vars.FILER_PLUGINS_3)

if config_data.addons:
for addon in config_data.addons:
apps.extend(data.ADDONS[addon]['installed_apps'])
text.append(data.ADDONS[addon]['settings'])

text.append('INSTALLED_APPS = [\n{0}{1}\n]'.format(
spacer, (',\n' + spacer).join(['\'{0}\''.format(var) for var in apps] +
['\'{0}\''.format(config_data.project_name)])
Expand Down
1 change: 1 addition & 0 deletions djangocms_installer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def execute():
django.create_project(config_data)
django.patch_settings(config_data)
django.copy_files(config_data)
django.patch_urls(config_data)
if not config_data.no_sync:
django.setup_database(config_data)
if config_data.starting_page:
Expand Down