From 0135f4a0b4491a34e62fa6b5a21ae99a7ee9a8a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Harasimowicz?= Date: Fri, 3 Mar 2017 23:28:41 +0100 Subject: [PATCH 01/14] Removed requirements files in favor of Pipfile --- .gitignore | 5 +++-- Pipfile | 13 +++++++++++++ Pipfile.lock | 36 +++++++++++++++++++++++++++++++++++ requirements/_base.txt | 43 ------------------------------------------ requirements/local.txt | 19 ------------------- 5 files changed, 52 insertions(+), 64 deletions(-) create mode 100644 Pipfile create mode 100644 Pipfile.lock delete mode 100644 requirements/_base.txt delete mode 100644 requirements/local.txt diff --git a/.gitignore b/.gitignore index b2fe1df..f49a3c2 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ var/ *.egg-info/ .installed.cfg *.egg +.venv/ # PyInstaller # Usually these files are written by a python script from a template @@ -41,7 +42,7 @@ htmlcov/ .cache nosetests.xml coverage.xml -*,cover +*.cover # Translations *.mo @@ -61,4 +62,4 @@ target/ *.swp # Database specifics -*.sqlite \ No newline at end of file +*.sqlite diff --git a/Pipfile b/Pipfile new file mode 100644 index 0000000..c254b79 --- /dev/null +++ b/Pipfile @@ -0,0 +1,13 @@ +[[source]] +url = "https://pypi.org/" +verify_ssl = true + +[dev-packages] +django-extensions = "*" +Sphinx = "*" +django-debug-toolbar = "*" + +[packages] +Unipath = "*" +djangorestframework = ">=3.5" +django = ">=1.10" diff --git a/Pipfile.lock b/Pipfile.lock new file mode 100644 index 0000000..da9ccd5 --- /dev/null +++ b/Pipfile.lock @@ -0,0 +1,36 @@ +{ + "default": { + "Unipath": "==1.1", + "djangorestframework": "==3.5.4", + "Django": "==1.10.6", + "django": ">=1.10" + }, + "develop": { + "sqlparse": "==0.2.3", + "Sphinx": "==1.5.3", + "django-debug-toolbar": "==1.6", + "pytz": "==2016.10", + "docutils": "==0.13.1", + "snowballstemmer": "==1.2.1", + "Babel": "==2.3.4", + "alabaster": "==0.7.10", + "six": "==1.10.0", + "Django": "==1.10.6", + "django-extensions": "==1.7.7", + "Pygments": "==2.2.0", + "Jinja2": "==2.9.5", + "MarkupSafe": "==0.23", + "requests": "==2.13.0", + "imagesize": "==0.7.1" + }, + "_meta": { + "sources": [ + { + "url": "https://pypi.org/", + "verify_ssl": true + } + ], + "requires": {}, + "Pipfile-sha256": "4c10c26fef7fe6adf45dc8f2068ea0936a970fe3ffee0ea26252d45e89c0543d" + } +} \ No newline at end of file diff --git a/requirements/_base.txt b/requirements/_base.txt deleted file mode 100644 index 9f94d68..0000000 --- a/requirements/_base.txt +++ /dev/null @@ -1,43 +0,0 @@ -# Base requirements file. -# Place items here that should be installed in ALL environments. - -django==1.8 -djangorestframework==3.1.1 - -## Needed by the settings base module. Do not remove. -Unipath==1.1 -dj-database-url==0.3.0 - -##################################################### -# -# Below are some commonly used django apps, included -# here for convenience. -# Be sure to add version numbers here!!!! -# -##################################################### - -# Convenient utilities for Django Models -# https://github.com/carljm/django-model-utils -# django-model-utils - -# PostgreSQL Database Adapter -# psycopg2 - -# MySQL Database Adapter -# django-cymysql - -##################################################### -# -# Django REST Framework Addons -# Some usefull thir party addons to DRF -# -##################################################### - -# https://github.com/juanriaza/django-rest-framework-msgpack -# djangorestframework-msgpack - -# https://github.com/gizmag/drf-ujson-renderer -# drf_ujson - -# https://github.com/marcgibbons/django-rest-swagger -# django-rest-swagger \ No newline at end of file diff --git a/requirements/local.txt b/requirements/local.txt deleted file mode 100644 index fedeb02..0000000 --- a/requirements/local.txt +++ /dev/null @@ -1,19 +0,0 @@ -# Local requirements file. -# Place items here that should ONLY be installed in DEVELOPMENT environments. - -# include the base requirements file --r _base.txt - -django-debug-toolbar -django-extensions - -# For easy deployments -# http://docs.fabfile.org/en/latest/ -# Fabric - -# For building documentation -# http://sphinx-doc.org/ -Sphinx - -# For running tests -coverage \ No newline at end of file From 9d00894ca8bc28d37d911c035ecd9cc8b6032be7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Harasimowicz?= Date: Sat, 4 Mar 2017 00:17:05 +0100 Subject: [PATCH 02/14] Added cookie cutter templates --- cookiecutter.json | 5 +++++ .gitignore => {{cookiecutter.project_dir}}/.gitignore | 0 Pipfile => {{cookiecutter.project_dir}}/Pipfile | 1 + Pipfile.lock => {{cookiecutter.project_dir}}/Pipfile.lock | 3 ++- .../static}/media/.gitdirectory | 0 .../templates}/.gitdirectory | 0 .../tests}/__init__.py | 0 .../{{cookiecutter.apps_dir}}}/manage.py | 2 +- .../{{cookiecutter.project_name}}}/__init__.py | 0 .../{{cookiecutter.project_name}}/settings}/__init__.py | 0 .../{{cookiecutter.project_name}}}/settings/base.py | 8 ++++---- .../{{cookiecutter.project_name}}}/settings/local.py | 2 +- .../{{cookiecutter.project_name}}}/urls.py | 0 .../{{cookiecutter.project_name}}}/wsgi.py | 2 +- 14 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 cookiecutter.json rename .gitignore => {{cookiecutter.project_dir}}/.gitignore (100%) rename Pipfile => {{cookiecutter.project_dir}}/Pipfile (90%) rename Pipfile.lock => {{cookiecutter.project_dir}}/Pipfile.lock (87%) rename {static => {{cookiecutter.project_dir}}/static}/media/.gitdirectory (100%) rename {templates => {{cookiecutter.project_dir}}/templates}/.gitdirectory (100%) rename {apps/project_name => {{cookiecutter.project_dir}}/tests}/__init__.py (100%) rename {apps => {{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}}/manage.py (65%) rename {apps/project_name/settings => {{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/{{cookiecutter.project_name}}}/__init__.py (100%) rename {tests => {{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/{{cookiecutter.project_name}}/settings}/__init__.py (100%) rename {apps/project_name => {{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/{{cookiecutter.project_name}}}/settings/base.py (94%) rename {apps/project_name => {{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/{{cookiecutter.project_name}}}/settings/local.py (88%) rename {apps/project_name => {{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/{{cookiecutter.project_name}}}/urls.py (100%) rename {apps/project_name => {{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/{{cookiecutter.project_name}}}/wsgi.py (78%) diff --git a/cookiecutter.json b/cookiecutter.json new file mode 100644 index 0000000..4f10036 --- /dev/null +++ b/cookiecutter.json @@ -0,0 +1,5 @@ +{ + "apps_dir": "apps", + "project_dir": "my_project", + "project_name": "project" +} \ No newline at end of file diff --git a/.gitignore b/{{cookiecutter.project_dir}}/.gitignore similarity index 100% rename from .gitignore rename to {{cookiecutter.project_dir}}/.gitignore diff --git a/Pipfile b/{{cookiecutter.project_dir}}/Pipfile similarity index 90% rename from Pipfile rename to {{cookiecutter.project_dir}}/Pipfile index c254b79..30aca76 100644 --- a/Pipfile +++ b/{{cookiecutter.project_dir}}/Pipfile @@ -11,3 +11,4 @@ django-debug-toolbar = "*" Unipath = "*" djangorestframework = ">=3.5" django = ">=1.10" +dj-database-url = "*" diff --git a/Pipfile.lock b/{{cookiecutter.project_dir}}/Pipfile.lock similarity index 87% rename from Pipfile.lock rename to {{cookiecutter.project_dir}}/Pipfile.lock index da9ccd5..a05473d 100644 --- a/Pipfile.lock +++ b/{{cookiecutter.project_dir}}/Pipfile.lock @@ -2,6 +2,7 @@ "default": { "Unipath": "==1.1", "djangorestframework": "==3.5.4", + "dj-database-url": "*", "Django": "==1.10.6", "django": ">=1.10" }, @@ -31,6 +32,6 @@ } ], "requires": {}, - "Pipfile-sha256": "4c10c26fef7fe6adf45dc8f2068ea0936a970fe3ffee0ea26252d45e89c0543d" + "Pipfile-sha256": "48bd43b8013e6684ac4697b026a0abd34dd1745afb5bcf581b17029fa74255f4" } } \ No newline at end of file diff --git a/static/media/.gitdirectory b/{{cookiecutter.project_dir}}/static/media/.gitdirectory similarity index 100% rename from static/media/.gitdirectory rename to {{cookiecutter.project_dir}}/static/media/.gitdirectory diff --git a/templates/.gitdirectory b/{{cookiecutter.project_dir}}/templates/.gitdirectory similarity index 100% rename from templates/.gitdirectory rename to {{cookiecutter.project_dir}}/templates/.gitdirectory diff --git a/apps/project_name/__init__.py b/{{cookiecutter.project_dir}}/tests/__init__.py similarity index 100% rename from apps/project_name/__init__.py rename to {{cookiecutter.project_dir}}/tests/__init__.py diff --git a/apps/manage.py b/{{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/manage.py similarity index 65% rename from apps/manage.py rename to {{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/manage.py index 391dd88..90c0b7a 100644 --- a/apps/manage.py +++ b/{{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/manage.py @@ -3,7 +3,7 @@ import sys if __name__ == "__main__": - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{ project_name }}.settings") + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{cookiecutter.project_name}}.settings") from django.core.management import execute_from_command_line diff --git a/apps/project_name/settings/__init__.py b/{{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/{{cookiecutter.project_name}}/__init__.py similarity index 100% rename from apps/project_name/settings/__init__.py rename to {{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/{{cookiecutter.project_name}}/__init__.py diff --git a/tests/__init__.py b/{{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/{{cookiecutter.project_name}}/settings/__init__.py similarity index 100% rename from tests/__init__.py rename to {{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/{{cookiecutter.project_name}}/settings/__init__.py diff --git a/apps/project_name/settings/base.py b/{{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/{{cookiecutter.project_name}}/settings/base.py similarity index 94% rename from apps/project_name/settings/base.py rename to {{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/{{cookiecutter.project_name}}/settings/base.py index 3d2317a..196561f 100644 --- a/apps/project_name/settings/base.py +++ b/{{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/{{cookiecutter.project_name}}/settings/base.py @@ -27,7 +27,7 @@ def get_env_var(varname, default=None): MANAGERS = ADMINS DATABASES = { - 'default': dj_database_url.parse(get_env_var('{{ project_name|upper }}_DATABASE_URL')) + 'default': dj_database_url.parse(get_env_var('{{cookiecutter.project_name|upper}}_DATABASE_URL')) } # Local time zone for this installation. Choices can be found here: @@ -74,7 +74,7 @@ def get_env_var(varname, default=None): STATICFILES_DIRS = () # Make this unique, and don't share it with anybody. -SECRET_KEY = get_env_var('{{ project_name|upper }}_SECRET_KEY') +SECRET_KEY = get_env_var('{{cookiecutter.project_name|upper}}_SECRET_KEY') MIDDLEWARE_CLASSES = ( 'django.contrib.sessions.middleware.SessionMiddleware', @@ -87,10 +87,10 @@ def get_env_var(varname, default=None): 'django.middleware.security.SecurityMiddleware', ) -ROOT_URLCONF = '{{ project_name }}.urls' +ROOT_URLCONF = '{{cookiecutter.project_name}}.urls' # Python dotted path to the WSGI application used by Django's runserver. -WSGI_APPLICATION = '{{ project_name }}.wsgi.application' +WSGI_APPLICATION = '{{cookiecutter.project_name|upper}}.wsgi.application' TEMPLATES = [ { diff --git a/apps/project_name/settings/local.py b/{{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/{{cookiecutter.project_name}}/settings/local.py similarity index 88% rename from apps/project_name/settings/local.py rename to {{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/{{cookiecutter.project_name}}/settings/local.py index ed7a667..a59973b 100644 --- a/apps/project_name/settings/local.py +++ b/{{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/{{cookiecutter.project_name}}/settings/local.py @@ -32,7 +32,7 @@ def show_toolbar(request): DEBUG_TOOLBAR_CONFIG = { - 'SHOW_TOOLBAR_CALLBACK': "{{ project_name }}.settings.local.show_toolbar", + 'SHOW_TOOLBAR_CALLBACK': "{{cookiecutter.project_name}}.settings.local.show_toolbar", } diff --git a/apps/project_name/urls.py b/{{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/{{cookiecutter.project_name}}/urls.py similarity index 100% rename from apps/project_name/urls.py rename to {{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/{{cookiecutter.project_name}}/urls.py diff --git a/apps/project_name/wsgi.py b/{{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/{{cookiecutter.project_name}}/wsgi.py similarity index 78% rename from apps/project_name/wsgi.py rename to {{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/{{cookiecutter.project_name}}/wsgi.py index f817652..24e383e 100644 --- a/apps/project_name/wsgi.py +++ b/{{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/{{cookiecutter.project_name}}/wsgi.py @@ -11,6 +11,6 @@ from django.core.wsgi import get_wsgi_application -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{ project_name }}.settings") +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{cookiecutter.project_name}}.settings") application = get_wsgi_application() From e5977f3f6f31b1e4f5af266618df0da227d24f23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Harasimowicz?= Date: Sat, 4 Mar 2017 00:26:35 +0100 Subject: [PATCH 03/14] Fixed some template naming --- .../{{cookiecutter.project_name}}/settings/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/{{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/{{cookiecutter.project_name}}/settings/base.py b/{{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/{{cookiecutter.project_name}}/settings/base.py index 196561f..6de899c 100644 --- a/{{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/{{cookiecutter.project_name}}/settings/base.py +++ b/{{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/{{cookiecutter.project_name}}/settings/base.py @@ -90,7 +90,7 @@ def get_env_var(varname, default=None): ROOT_URLCONF = '{{cookiecutter.project_name}}.urls' # Python dotted path to the WSGI application used by Django's runserver. -WSGI_APPLICATION = '{{cookiecutter.project_name|upper}}.wsgi.application' +WSGI_APPLICATION = '{{cookiecutter.project_name}}.wsgi.application' TEMPLATES = [ { From 736c13e1a562ac859f70de6e8cf735874920acf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Harasimowicz?= Date: Sat, 4 Mar 2017 00:33:37 +0100 Subject: [PATCH 04/14] Fixing Django Debug Toolbar --- .../{{cookiecutter.project_name}}/settings/local.py | 2 ++ .../{{cookiecutter.project_name}}/urls.py | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/{{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/{{cookiecutter.project_name}}/settings/local.py b/{{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/{{cookiecutter.project_name}}/settings/local.py index a59973b..61be20b 100644 --- a/{{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/{{cookiecutter.project_name}}/settings/local.py +++ b/{{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/{{cookiecutter.project_name}}/settings/local.py @@ -35,5 +35,7 @@ def show_toolbar(request): 'SHOW_TOOLBAR_CALLBACK': "{{cookiecutter.project_name}}.settings.local.show_toolbar", } +DEBUG_TOOLBAR_PATCH_SETTINGS = False + INSTALLED_APPS += DEBUG_APPS diff --git a/{{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/{{cookiecutter.project_name}}/urls.py b/{{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/{{cookiecutter.project_name}}/urls.py index df17d83..5ae560b 100644 --- a/{{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/{{cookiecutter.project_name}}/urls.py +++ b/{{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/{{cookiecutter.project_name}}/urls.py @@ -1,3 +1,4 @@ +from django.conf import settings from django.conf.urls import include, url from django.contrib import admin @@ -8,3 +9,9 @@ url(r'^admin/', include(admin.site.urls)), ] + +if settings.DEBUG: + import debug_toolbar + urlpatterns += [ + url(r'^__debug__/', include(debug_toolbar.urls)), + ] From c723a9819f8686532455476c68e1e664be52e8c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Harasimowicz?= Date: Sat, 4 Mar 2017 00:38:42 +0100 Subject: [PATCH 05/14] Added Werkzeug to dev packages --- {{cookiecutter.project_dir}}/Pipfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/{{cookiecutter.project_dir}}/Pipfile b/{{cookiecutter.project_dir}}/Pipfile index 30aca76..5d64573 100644 --- a/{{cookiecutter.project_dir}}/Pipfile +++ b/{{cookiecutter.project_dir}}/Pipfile @@ -6,9 +6,10 @@ verify_ssl = true django-extensions = "*" Sphinx = "*" django-debug-toolbar = "*" +Werkzeug = "*" [packages] Unipath = "*" djangorestframework = ">=3.5" -django = ">=1.10" dj-database-url = "*" +django = ">=1.10" From 847f02e2c29836e96414d5457462156f791767ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Harasimowicz?= Date: Sat, 4 Mar 2017 17:07:04 +0100 Subject: [PATCH 06/14] Updated Pipfile.lock --- {{cookiecutter.project_dir}}/Pipfile.lock | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/{{cookiecutter.project_dir}}/Pipfile.lock b/{{cookiecutter.project_dir}}/Pipfile.lock index a05473d..32f09ad 100644 --- a/{{cookiecutter.project_dir}}/Pipfile.lock +++ b/{{cookiecutter.project_dir}}/Pipfile.lock @@ -2,9 +2,9 @@ "default": { "Unipath": "==1.1", "djangorestframework": "==3.5.4", - "dj-database-url": "*", + "django": ">=1.10", "Django": "==1.10.6", - "django": ">=1.10" + "dj-database-url": "==0.4.2" }, "develop": { "sqlparse": "==0.2.3", @@ -20,6 +20,7 @@ "django-extensions": "==1.7.7", "Pygments": "==2.2.0", "Jinja2": "==2.9.5", + "Werkzeug": "*", "MarkupSafe": "==0.23", "requests": "==2.13.0", "imagesize": "==0.7.1" @@ -32,6 +33,6 @@ } ], "requires": {}, - "Pipfile-sha256": "48bd43b8013e6684ac4697b026a0abd34dd1745afb5bcf581b17029fa74255f4" + "Pipfile-sha256": "8a40da91c51d4a1545f94ae936f4b4b4b31f8bf2c41c457659c6d5fb54064316" } } \ No newline at end of file From 1556526e190c3cf50e42e18e4ba75d169ef6f5ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Harasimowicz?= Date: Sat, 4 Mar 2017 22:16:15 +0100 Subject: [PATCH 07/14] Added selectable DB Engine/Backend. --- cookiecutter.json | 7 +++++-- {{cookiecutter.project_dir}}/Pipfile | 5 +++++ .../{{cookiecutter.apps_dir}}/manage.py | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/cookiecutter.json b/cookiecutter.json index 4f10036..3a68f9f 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -1,5 +1,8 @@ { "apps_dir": "apps", - "project_dir": "my_project", - "project_name": "project" + "project_name": "my_project", + "project_dir": "{{cookiecutter.project_name|replace(' ', '_')}}", + "secret_key": "FOR DEV ONLY - CHANGE ME", + "database_type": ["PostgreSQL", "MySQL", "SQLite", "Other"], + "database_url": "{{cookiecutter.database_type|lower}}://path_to_database" } \ No newline at end of file diff --git a/{{cookiecutter.project_dir}}/Pipfile b/{{cookiecutter.project_dir}}/Pipfile index 5d64573..2a33695 100644 --- a/{{cookiecutter.project_dir}}/Pipfile +++ b/{{cookiecutter.project_dir}}/Pipfile @@ -13,3 +13,8 @@ Unipath = "*" djangorestframework = ">=3.5" dj-database-url = "*" django = ">=1.10" +{% if cookiecutter.database_type == "MySQL" %} +mysqlclient = ">=1.3" +{% elif cookiecutter.database_type == "PostgreSQL" %} +psycopg2 = ">=2.7" +{% endif %} diff --git a/{{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/manage.py b/{{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/manage.py index 90c0b7a..fd402d4 100644 --- a/{{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/manage.py +++ b/{{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/manage.py @@ -3,7 +3,7 @@ import sys if __name__ == "__main__": - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{cookiecutter.project_name}}.settings") + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{cookiecutter.project_name}}.settings.local") from django.core.management import execute_from_command_line From 4d43a8ce09f50ceca9639edddd9d83434daface8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Harasimowicz?= Date: Sat, 4 Mar 2017 22:56:20 +0100 Subject: [PATCH 08/14] Fixed some Django warnings and updated Pipfile.lock --- {{cookiecutter.project_dir}}/Pipfile.lock | 4 ++-- .../{{cookiecutter.project_name}}/settings/local.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/{{cookiecutter.project_dir}}/Pipfile.lock b/{{cookiecutter.project_dir}}/Pipfile.lock index 32f09ad..628edcd 100644 --- a/{{cookiecutter.project_dir}}/Pipfile.lock +++ b/{{cookiecutter.project_dir}}/Pipfile.lock @@ -20,7 +20,7 @@ "django-extensions": "==1.7.7", "Pygments": "==2.2.0", "Jinja2": "==2.9.5", - "Werkzeug": "*", + "Werkzeug": "==0.11.15", "MarkupSafe": "==0.23", "requests": "==2.13.0", "imagesize": "==0.7.1" @@ -33,6 +33,6 @@ } ], "requires": {}, - "Pipfile-sha256": "8a40da91c51d4a1545f94ae936f4b4b4b31f8bf2c41c457659c6d5fb54064316" + "Pipfile-sha256": "c0db6c138ffd72f9a97b6d74b6ef4eda26b64b4020dde59af31b23fcdb8e5225" } } \ No newline at end of file diff --git a/{{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/{{cookiecutter.project_name}}/settings/local.py b/{{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/{{cookiecutter.project_name}}/settings/local.py index 61be20b..070fc12 100644 --- a/{{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/{{cookiecutter.project_name}}/settings/local.py +++ b/{{cookiecutter.project_dir}}/{{cookiecutter.apps_dir}}/{{cookiecutter.project_name}}/settings/local.py @@ -3,7 +3,7 @@ from .base import * -DEBUG = TEMPLATE_DEBUG = True +DEBUG = True # Send emails to the console EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' From ded9588ac6d7f5d6424f7ee8bde43909620f7c87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Harasimowicz?= Date: Sat, 4 Mar 2017 23:18:47 +0100 Subject: [PATCH 09/14] Initial tests framework --- .travis.yml | 14 ++++++++++++++ pytest.ini | 2 ++ tests/basic_tests.py | 30 ++++++++++++++++++++++++++++++ tox.ini | 20 ++++++++++++++++++++ 4 files changed, 66 insertions(+) create mode 100644 .travis.yml create mode 100644 pytest.ini create mode 100644 tests/basic_tests.py create mode 100644 tox.ini diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..94f3ed7 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,14 @@ +language: python + +python: 3.5 +env: + - TOXENV=py27 + - TOXENV=py33 + - TOXENV=py34 + - TOXENV=py35 + +install: + - pip install -U tox + +script: + - tox diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..ad16166 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,2 @@ +[pytest] +testpaths = tests/ \ No newline at end of file diff --git a/tests/basic_tests.py b/tests/basic_tests.py new file mode 100644 index 0000000..8d80316 --- /dev/null +++ b/tests/basic_tests.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +import os +from contextlib import contextmanager +from cookiecutter.utils import rmtree + + +@contextmanager +def temporary_project(cookies, *args, **kwargs): + """ + Delete the temporal directory that is created when executing the tests + :param cookies: pytest_cookies.Cookies + """ + result = cookies.bake(*args, **kwargs) + try: + yield result + finally: + rmtree(str(result.project)) + +def test_envrc(cookies): + """ + Test if the .envrc file was created successfully + """ + + extra_context = {'project_name': 'environ'} + + with temporary_project(cookies, extra_context=extra_context) as result: + envrc_file = result.project.join('.envrc') + lines = [x.strip() for x in envrc_file.readlines(cr=False)] + assert 'ENVIRON_SECRET_KEY' in lines + assert 'ENVIRON_DATABASE_URL' in lines \ No newline at end of file diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..817be0d --- /dev/null +++ b/tox.ini @@ -0,0 +1,20 @@ +[tox] +envlist = py27, py33, py34, py35, pypy +skipsdist = true + +[testenv] +whitelist_externals = bash +deps = + Django>=1.11 + pip + cookiecutter + pytest-cookies + pytest + tox + pytest-cov + watchdog + sh + flake8 + +commands = + py.test \ No newline at end of file From 4c5097e8513c9410087a20f515931374453e11c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Harasimowicz?= Date: Sat, 4 Mar 2017 23:20:58 +0100 Subject: [PATCH 10/14] Added Travis-CI badge --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 04a291e..e66eeb3 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ -# django-api-template +# django-api-template +[![Build Status](https://travis-ci.org/harnash/django_api_template.svg?branch=master)](https://travis-ci.org/harnash/django_api_template) + Django project template for building RESTful API services From 404201957f3dd30a2eceb6384df5d64f8a39c026 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Harasimowicz?= Date: Sat, 4 Mar 2017 23:22:57 +0100 Subject: [PATCH 11/14] Updated Django dependencies for tests --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 817be0d..1d51c08 100644 --- a/tox.ini +++ b/tox.ini @@ -5,7 +5,7 @@ skipsdist = true [testenv] whitelist_externals = bash deps = - Django>=1.11 + Django>=1.10 pip cookiecutter pytest-cookies From 163fbb6c75ffa38b654abd3279173c2a6bb36790 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Harasimowicz?= Date: Sat, 4 Mar 2017 23:28:48 +0100 Subject: [PATCH 12/14] Fixed test file name --- tests/{basic_tests.py => test_sample_projects.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/{basic_tests.py => test_sample_projects.py} (100%) diff --git a/tests/basic_tests.py b/tests/test_sample_projects.py similarity index 100% rename from tests/basic_tests.py rename to tests/test_sample_projects.py From a7dfc9f036505ac3f958973fb1a4dc320c7f39ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Harasimowicz?= Date: Sat, 4 Mar 2017 23:33:16 +0100 Subject: [PATCH 13/14] Fixing tests --- tests/test_sample_projects.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_sample_projects.py b/tests/test_sample_projects.py index 8d80316..95fe487 100644 --- a/tests/test_sample_projects.py +++ b/tests/test_sample_projects.py @@ -24,7 +24,7 @@ def test_envrc(cookies): extra_context = {'project_name': 'environ'} with temporary_project(cookies, extra_context=extra_context) as result: - envrc_file = result.project.join('.envrc') + envrc_file = result.project.join('environ', '.envrc') lines = [x.strip() for x in envrc_file.readlines(cr=False)] assert 'ENVIRON_SECRET_KEY' in lines assert 'ENVIRON_DATABASE_URL' in lines \ No newline at end of file From f38f94ff35b304c356a7eb660919350dbafacf10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Harasimowicz?= Date: Sat, 4 Mar 2017 23:43:25 +0100 Subject: [PATCH 14/14] Updated tests --- .gitignore | 2 ++ tests/test_sample_projects.py | 7 +++---- 2 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1c97fe3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.cache +__pycache__/ diff --git a/tests/test_sample_projects.py b/tests/test_sample_projects.py index 95fe487..4c874ef 100644 --- a/tests/test_sample_projects.py +++ b/tests/test_sample_projects.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -import os from contextlib import contextmanager from cookiecutter.utils import rmtree @@ -24,7 +23,7 @@ def test_envrc(cookies): extra_context = {'project_name': 'environ'} with temporary_project(cookies, extra_context=extra_context) as result: - envrc_file = result.project.join('environ', '.envrc') + envrc_file = result.project.join('.envrc') lines = [x.strip() for x in envrc_file.readlines(cr=False)] - assert 'ENVIRON_SECRET_KEY' in lines - assert 'ENVIRON_DATABASE_URL' in lines \ No newline at end of file + assert 'export ENVIRON_SECRET_KEY=FOR DEV ONLY - CHANGE ME' in lines + assert 'export ENVIRON_DATABASE_URL=postgresql://path_to_database' in lines \ No newline at end of file