Repository: nephila/djangocms-installer (python)

Issue:
I18n URL patterns regardless of I18n setting
I've just setup a project with 1.0.0rc1 & opted for I18n to be disabled, but the URLs get generated with i18n patterns, resulting in a 404 after I've logged in as it loads `/en/` for example.

Looks like the app needs two versions of `urls.py` for the two outcomes of the i18n setting. This looks like a simple change in `copy_files()` so I might fork the repo & try to resolve this.

Pull request:
Feature/non i18n urls
Fix for i18n url patterns (Fix #321) 

Patch:
diff --git a/.coveragerc b/.coveragerc
index de0cd46..c5d5d41 100644
--- a/.coveragerc
+++ b/.coveragerc
@@ -6,7 +6,8 @@ omit =
     djangocms_installer/__main__.py
     djangocms_installer/main.py
     djangocms_installer/compat.py
-    djangocms_installer/config/urls.py
+    djangocms_installer/config/urls_i18n.py
+    djangocms_installer/config/urls_noi18n.py
     djangocms_installer/config/settings.py
     tests/*
 
diff --git a/.gitignore b/.gitignore
index b89d245..e3c5857 100644
--- a/.gitignore
+++ b/.gitignore
@@ -19,6 +19,7 @@ develop-eggs
 lib
 lib64
 .eggs
+.venv
 
 # Installer logs
 pip-log.txt
diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst
index 64f7a15..0fb2426 100644
--- a/CONTRIBUTING.rst
+++ b/CONTRIBUTING.rst
@@ -3,7 +3,7 @@ Contributing
 ============
 
 Contributions are welcome, and they are greatly appreciated! Every
-little bit helps, and credit will always be given. 
+little bit helps, and credit will always be given.
 
 You can contribute in many ways:
 
@@ -36,7 +36,7 @@ is open to whoever wants to implement it.
 Write Documentation
 ~~~~~~~~~~~~~~~~~~~
 
-django CMS Installer could always use more documentation, whether as part of the 
+django CMS Installer could always use more documentation, whether as part of the
 official django CMS Installer docs, in docstrings, or even on the web in blog posts,
 articles, and such.
 
@@ -67,7 +67,7 @@ Ready to contribute? Here's how to set up `djangocms-installer` for local develo
     $ mkvirtualenv djangocms-installer
     $ cd djangocms-installer/
     $ python setup.py develop
-    $ pip install -r requirements_dev.txt
+    $ pip install -r requirements-test.txt
 
 the last one is to get the requirements including testing and development
 tools installed.
@@ -102,7 +102,7 @@ Before you submit a pull request, check that it meets these guidelines:
 2. If the pull request adds functionality, the docs should be updated. Put
    your new functionality into a function with a docstring, and add the
    feature to the list in README.rst.
-3. The pull request should work for Python 2.6, 2.7, and 3.3, and for PyPy. Check 
+3. The pull request should work for Python 2.6, 2.7, and 3.3, and for PyPy. Check
    https://travis-ci.org/nephila/djangocms-installer/pull_requests
    and make sure that the tests pass for all supported Python versions.
 
diff --git a/djangocms_installer/config/urls.py b/djangocms_installer/config/urls_i18n.py
similarity index 100%
rename from djangocms_installer/config/urls.py
rename to djangocms_installer/config/urls_i18n.py
diff --git a/djangocms_installer/config/urls_noi18n.py b/djangocms_installer/config/urls_noi18n.py
new file mode 100644
index 0000000..527a784
--- /dev/null
+++ b/djangocms_installer/config/urls_noi18n.py
@@ -0,0 +1,29 @@
+# -*- coding: utf-8 -*-
+from __future__ import absolute_import, print_function, unicode_literals
+
+from cms.sitemaps import CMSSitemap
+from django.conf import settings
+from django.conf.urls import include, url
+from django.contrib import admin
+from django.contrib.sitemaps.views import sitemap
+from django.contrib.staticfiles.urls import staticfiles_urlpatterns
+from django.views.static import serve
+
+admin.autodiscover()
+
+urlpatterns = [
+    url(r'^sitemap\.xml$', sitemap,
+        {'sitemaps': {'cmspages': CMSSitemap}}),
+]
+
+urlpatterns += [
+    url(r'^admin/', include(admin.site.urls)),  # NOQA
+    url(r'^', include('cms.urls')),
+]
+
+# This is only needed when using runserver.
+if settings.DEBUG:
+    urlpatterns = [
+        url(r'^media/(?P<path>.*)$', serve,
+            {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
+        ] + staticfiles_urlpatterns() + urlpatterns
diff --git a/djangocms_installer/django/__init__.py b/djangocms_installer/django/__init__.py
index 6c2ab74..1ca6854 100644
--- a/djangocms_installer/django/__init__.py
+++ b/djangocms_installer/django/__init__.py
@@ -117,7 +117,10 @@ def copy_files(config_data):
 
     :param config_data: configuration data
     """
-    urlconf_path = os.path.join(os.path.dirname(__file__), '../config/urls.py')
+    if config_data.i18n == 'yes':
+        urlconf_path = os.path.join(os.path.dirname(__file__), '../config/urls_i18n.py')
+    else:
+        urlconf_path = os.path.join(os.path.dirname(__file__), '../config/urls_noi18n.py')
     share_path = os.path.join(os.path.dirname(__file__), '../share')
     template_path = os.path.join(share_path, 'templates')
     if config_data.aldryn:  # pragma: no cover


Test patch:
diff --git a/tests/main.py b/tests/main.py
index 4560431..2b2a9df 100644
--- a/tests/main.py
+++ b/tests/main.py
@@ -168,3 +168,48 @@ class TestMain(IsolatedTestClass):
                     main.execute()
         self.assertTrue(os.path.exists(self.project_dir))
 
+    def test_i18n_urls(self):
+        base_dir = mkdtemp()
+        project_dir = os.path.join(base_dir, 'example_prj')
+        original_dir = os.getcwd()
+        os.chdir(base_dir)
+        with patch('sys.stdout', self.stdout):
+            with patch('sys.stderr', self.stderr):
+                sys.argv = ['main'] + ['--i18n=yes', 'example_prj']
+                main.execute()
+                self.assertTrue(
+                    os.path.exists(
+                        os.path.join(project_dir, 'example_prj', 'urls.py')
+                    )
+                )
+                with open(os.path.join(project_dir, 'example_prj', 'urls.py'),
+                          'r') as urls_file:
+                    urls = urls_file.read()
+                    self.assertTrue(
+                        urls.find('urlpatterns += i18n_patterns(') > -1
+                    )
+        os.chdir(original_dir)
+        rmtree(base_dir)
+
+    def test_noi18n_urls(self):
+        base_dir = mkdtemp()
+        project_dir = os.path.join(base_dir, 'example_prj')
+        original_dir = os.getcwd()
+        os.chdir(base_dir)
+        with patch('sys.stdout', self.stdout):
+            with patch('sys.stderr', self.stderr):
+                sys.argv = ['main'] + ['--i18n=no', 'example_prj']
+                main.execute()
+                self.assertTrue(
+                    os.path.exists(
+                        os.path.join(project_dir, 'example_prj', 'urls.py')
+                    )
+                )
+                with open(os.path.join(project_dir, 'example_prj', 'urls.py'),
+                          'r') as urls_file:
+                    urls = urls_file.read()
+                    self.assertTrue(
+                        urls.find('urlpatterns += i18n_patterns(') == -1
+                    )
+        os.chdir(original_dir)
+        rmtree(base_dir)