From 0328032cbf9647ae6b18ae33a2e14a55e19de938 Mon Sep 17 00:00:00 2001 From: Vivian Guillen Date: Thu, 2 Jun 2016 18:57:01 -0700 Subject: [PATCH 01/22] Add bigger comments to better section the css --- .../static/sass/project.scss | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/static/sass/project.scss b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/static/sass/project.scss index e737d593..bbb2da28 100644 --- a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/static/sass/project.scss +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/static/sass/project.scss @@ -1,5 +1,10 @@ + // project specific CSS goes here +//////////////////////////////// + //Variables// +//////////////////////////////// + // Alert colors $white: #fff; @@ -9,6 +14,10 @@ $pink: #f2dede; $dark-pink: #eed3d7; $red: #b94a48; +//////////////////////////////// + //Alerts// +//////////////////////////////// + // bootstrap alert CSS, translated to the django-standard levels of // debug, info, success, warning, error @@ -24,6 +33,10 @@ $red: #b94a48; color: $red; } +//////////////////////////////// + //Navbar// +//////////////////////////////// + // This is a fix for the bootstrap4 alpha release @media (max-width: 47.9em) { @@ -42,6 +55,10 @@ $red: #b94a48; } } +//////////////////////////////// + //Django Toolbar// +//////////////////////////////// + // Display django-debug-toolbar. // See https://github.com/django-debug-toolbar/django-debug-toolbar/issues/742 // and https://github.com/pydanny/cookiecutter-django/issues/317 From 4b6707fe7bebbd849142fe8d75b42a3b5dbcf0ae Mon Sep 17 00:00:00 2001 From: Meghan Heintz Date: Fri, 3 Jun 2016 11:55:44 -0700 Subject: [PATCH 02/22] adding troubleshooting doc --- docs/troubleshooting.rst | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 docs/troubleshooting.rst diff --git a/docs/troubleshooting.rst b/docs/troubleshooting.rst new file mode 100644 index 00000000..fe121b9c --- /dev/null +++ b/docs/troubleshooting.rst @@ -0,0 +1,9 @@ +Troubleshooting +===================================== + +This page contains some advice about errors and problems commonly encountered during the development of Cookiecutter Django applications. + +#. If you get the error ``jinja2.exceptions.TemplateSyntaxError: Encountered unknown tag 'now'.`` , please upgrade your cookiecutter version to >= 1.4 (see issue # 528_ ) +#. ``project_slug`` must be a valid Python module name or you will have issues on imports. + +.. _528: https://github.com/pydanny/cookiecutter-django/issues/528#issuecomment-212650373 \ No newline at end of file From ecc81134dd552475c52cef749615b1356566811c Mon Sep 17 00:00:00 2001 From: Meghan Heintz Date: Fri, 3 Jun 2016 12:04:11 -0700 Subject: [PATCH 03/22] Adding troubleshotting to index --- docs/index.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/index.rst b/docs/index.rst index beafb44c..aa88fe24 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -25,6 +25,7 @@ Contents: deployment-on-heroku deployment-with-docker faq + troubleshooting Indices and tables ================== From a751fbcf9fa9717dc68db0bb8fad84cb79aac123 Mon Sep 17 00:00:00 2001 From: Meghan Heintz Date: Fri, 3 Jun 2016 12:11:54 -0700 Subject: [PATCH 04/22] moving warnings from readme to troubleshooting --- README.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 14dcf207..df192efc 100644 --- a/README.rst +++ b/README.rst @@ -14,9 +14,11 @@ Cookiecutter Django Powered by Cookiecutter_, Cookiecutter Django is a framework for jumpstarting production-ready Django projects quickly. +See Troubleshooting_ for common errors and obstacles. + .. _cookiecutter: https://github.com/audreyr/cookiecutter -**Warning**: if you get the error "jinja2.exceptions.TemplateSyntaxError: Encountered unknown tag 'now'." , please upgrade your cookiecutter version to >= 1.4 (see issue # 528_ ) +.. _Troubleshooting: https://cookiecutter-django.readthedocs.io/en/latest/troubleshooting.html .. _528: https://github.com/pydanny/cookiecutter-django/issues/528#issuecomment-212650373 @@ -99,8 +101,6 @@ You'll be prompted for some values. Provide them, then a Django project will be **Warning**: After this point, change 'Daniel Greenfeld', 'pydanny', etc to your own information. -**Warning**: project_slug must be a valid Python module name or you will have issues on imports. - Answer the prompts with your own desired options_. For example:: Cloning into 'cookiecutter-django'... From 97ddd3da1b626d3815bdc9fac89fc3ccf6da625a Mon Sep 17 00:00:00 2001 From: Vivian Guillen Date: Fri, 3 Jun 2016 12:22:57 -0700 Subject: [PATCH 05/22] Fix navbar right top corner issue --- .../{{cookiecutter.project_slug}}/static/sass/project.scss | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/static/sass/project.scss b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/static/sass/project.scss index bbb2da28..54632b2d 100644 --- a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/static/sass/project.scss +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/static/sass/project.scss @@ -39,6 +39,10 @@ $red: #b94a48; // This is a fix for the bootstrap4 alpha release +.navbar { + border-radius: 0px; +} + @media (max-width: 47.9em) { .navbar-nav .nav-item { display: inline-block; From 6885547b6ae2bb606ed13eb4a11f9abf6939fa83 Mon Sep 17 00:00:00 2001 From: mjsisley Date: Fri, 3 Jun 2016 12:50:23 -0700 Subject: [PATCH 06/22] Adding documentation for debugging with Docker (#575) * Adding documentation for debugging with Docker * Add -f dev.yml --- docs/developing-locally-docker.rst | 42 ++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/docs/developing-locally-docker.rst b/docs/developing-locally-docker.rst index 03e9221c..85aef9c6 100644 --- a/docs/developing-locally-docker.rst +++ b/docs/developing-locally-docker.rst @@ -141,3 +141,45 @@ If you want to run the stack in detached mode (in the background), use the ``-d` :: $ docker-compose -f dev.yml up -d + +Debugging +~~~~~~~~~~~~~ + +ipdb +""""" + +If you are using the following within your code to debug: + +:: + + import ipdb; ipdb.set_trace() + +Then you may need to run the following for it to work as desired: + +:: + + $ docker-compose run -f dev.yml --service-ports django + +django-debug-toolbar +"""""""""""""""""""" + +In order for django-debug-toolbar to work with docker you need to add your docker-machine ip address (the output of `Get the IP ADDRESS`_) to INTERNAL_IPS in local.py + + +.. May be a better place to put this, as it is not Docker specific. + +You may need to add the following to your css in order for the django-debug-toolbar to be visible (this applies whether Docker is being used or not): + +.. code-block:: css + + /* Override Bootstrap 4 styling on Django Debug Toolbar */ + #djDebug[hidden], #djDebug [hidden] { + display: block !important; + } + + #djDebug [hidden][style='display: none;'] { + display: none !important; + } + + + From 65b3de002c7f31838e8b6d786a54515d08673c82 Mon Sep 17 00:00:00 2001 From: Daniel Roy Greenfeld Date: Fri, 3 Jun 2016 12:52:52 -0700 Subject: [PATCH 07/22] Added @mjsisley to the contributor list --- CHANGELOG.md | 4 ++++ CONTRIBUTORS.rst | 2 ++ 2 files changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f849153..1b9bb5e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All enhancements and patches to Cookiecutter Django will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +##[2016-06-03] +### Added +- Documentation for debugging with Docker (@mjsisley) + ##[2016-06-02] ### Added - Added better instructions for installing postgres on Mac OS X (@dot2dotseurat ) diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index 4e0bc3bc..5a0ab6eb 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -97,6 +97,7 @@ Listed in alphabetical order. Matt Menzenski `@menzenski`_ Matt Warren `@mfwarren`_ Meghan Heintz `@dot2dotseurat`_ + mjsisley `@mjsisley`_ mozillazg `@mozillazg`_ Pablo `@oubiga`_ Raphael Pierzina `@hackebrot`_ @@ -160,6 +161,7 @@ Listed in alphabetical order. .. _@MathijsHoogland: https://github.com/MathijsHoogland .. _@menzenski: https://github.com/menzenski .. _@mfwarren: https://github.com/mfwarren +.. _@mjsisley: https://github.com/mjsisley .. _@mozillazg: https://github.com/mozillazg .. _@originell: https://github.com/originell .. _@oubiga: https://github.com/oubiga From daf98aea428174f7576363b60494a07dcbacc38d Mon Sep 17 00:00:00 2001 From: Meghan Heintz Date: Fri, 3 Jun 2016 14:02:51 -0700 Subject: [PATCH 08/22] Adding Apache 2 License option (#578) * Adding Apache 2 License option * changed order of liences availble --- cookiecutter.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cookiecutter.json b/cookiecutter.json index 8fe7010a..686b8fd6 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -22,5 +22,5 @@ "use_heroku": "n", "use_grunt": "n", "use_angular": "n", - "open_source_license": ["MIT", "BSD", "Not open source"] + "open_source_license": ["MIT", "BSD", "Apache Software License 2.0", "Not open source"] } From 1efe3f6caf66351ec6b914ca115865834f4b2f04 Mon Sep 17 00:00:00 2001 From: Daniel Roy Greenfeld Date: Fri, 3 Jun 2016 14:05:08 -0700 Subject: [PATCH 09/22] Tracking more work by @dot2dotseurat --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b9bb5e6..9657565b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ##[2016-06-03] ### Added - Documentation for debugging with Docker (@mjsisley) +- Apache 2 License option in `cookiecutter.json` (@dot2dotseurat) ##[2016-06-02] ### Added From 36ac82b1cfbeedbdbcb081c9fe340a7a5f057e3f Mon Sep 17 00:00:00 2001 From: Daniel Roy Greenfeld Date: Fri, 3 Jun 2016 14:07:25 -0700 Subject: [PATCH 10/22] Removed angular2 --- README.rst | 1 - cookiecutter.json | 1 - .../{{cookiecutter.project_slug}}/templates/base.html | 6 +----- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/README.rst b/README.rst index df192efc..3e906217 100644 --- a/README.rst +++ b/README.rst @@ -131,7 +131,6 @@ Answer the prompts with your own desired options_. For example:: use_docker [y]: y use_heroku [n]: n use_grunt [n]: y - use_angular [n]: n Select open_source_license: 1 - MIT 2 - BSD diff --git a/cookiecutter.json b/cookiecutter.json index 686b8fd6..36aa3c30 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -21,6 +21,5 @@ "use_docker": "y", "use_heroku": "n", "use_grunt": "n", - "use_angular": "n", "open_source_license": ["MIT", "BSD", "Apache Software License 2.0", "Not open source"] } diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/templates/base.html b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/templates/base.html index b5469222..a1e2a5ac 100644 --- a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/templates/base.html +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/templates/base.html @@ -1,5 +1,5 @@ {% raw %}{% load staticfiles i18n %} - + @@ -23,10 +23,6 @@ {% endblock %} - {% endraw %}{% if cookiecutter.use_angular == "y" %}{% raw %}{% block angular %} - - {% endblock %}{% endraw %}{% endif %}{% raw %} - From ed11e05d09a56e8326e7c2dcaec7331bbfec6400 Mon Sep 17 00:00:00 2001 From: Daniel Roy Greenfeld Date: Fri, 3 Jun 2016 14:08:25 -0700 Subject: [PATCH 11/22] Finish removing Angular --- CHANGELOG.md | 3 +++ README.rst | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9657565b..088fb47a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Documentation for debugging with Docker (@mjsisley) - Apache 2 License option in `cookiecutter.json` (@dot2dotseurat) +### Deleted +- AngularJS (@pydanny) + ##[2016-06-02] ### Added - Added better instructions for installing postgres on Mac OS X (@dot2dotseurat ) diff --git a/README.rst b/README.rst index 3e906217..23fb79d6 100644 --- a/README.rst +++ b/README.rst @@ -28,7 +28,6 @@ Features * For Django 1.9 * Renders Django projects with 100% starting test coverage * Twitter Bootstrap_ v4.0.0 - alpha_ -* AngularJS_ * 12-Factor_ based settings via django-environ_ * Optimized development and production settings * Registration via django-allauth_ @@ -57,7 +56,6 @@ Optional Integrations .. _alpha: http://blog.getbootstrap.com/2015/08/19/bootstrap-4-alpha/ .. _Bootstrap: https://github.com/twbs/bootstrap -.. _AngularJS: https://github.com/angular/angular.js .. _django-environ: https://github.com/joke2k/django-environ .. _12-Factor: http://12factor.net/ .. _django-allauth: https://github.com/pennersr/django-allauth From 7610a7978a20ade7fecbc39ce01b2d2823598b55 Mon Sep 17 00:00:00 2001 From: Vivian Guillen Date: Fri, 3 Jun 2016 15:04:04 -0700 Subject: [PATCH 12/22] Add gulp with autoprefixing and minification for sass --- {{cookiecutter.project_slug}}/gulpfile.js | 52 ++++++++++++++++++++++ {{cookiecutter.project_slug}}/package.json | 34 +++++++++----- 2 files changed, 74 insertions(+), 12 deletions(-) create mode 100644 {{cookiecutter.project_slug}}/gulpfile.js diff --git a/{{cookiecutter.project_slug}}/gulpfile.js b/{{cookiecutter.project_slug}}/gulpfile.js new file mode 100644 index 00000000..6dddcf29 --- /dev/null +++ b/{{cookiecutter.project_slug}}/gulpfile.js @@ -0,0 +1,52 @@ + +//////////////////////////////// + //Setup// +//////////////////////////////// + +// Plugins +var gulp = require('gulp'), + pjson = require('./package.json'), + gutil = require('gulp-util'), + sass = require('gulp-sass'), + autoprefixer = require('gulp-autoprefixer'), + cssnano = require('gulp-cssnano'), + rename = require('gulp-rename'), + del = require('del'), + plumber = require('gulp-plumber'), + pixrem = require('gulp-pixrem'), + browserSync = require('browser-sync'); + + +// Relative paths function +var pathsConfig = function (appName) { + this.app = "./" + (appName || pjson.name); + + return { + app: this.app, + templates: this.app + '/templates', + css: this.app + '/static/css', + sass: this.app + '/static/sass', + fonts: this.app + '/static/fonts', + images: this.app + '/static/images', + js: this.app + '/static/js', + } +}; + +var paths = pathsConfig(); + +//////////////////////////////// + //Tasks// +//////////////////////////////// + +// Styles +gulp.task('styles', function() { + return gulp.src(paths.sass + '/project.scss', { style: 'expanded' }) + .pipe(sass().on('error', sass.logError)) + .pipe(plumber()) // It checks for errors + .pipe(autoprefixer({browsers: ['last 2 version']})) // Adds vendor prefixes + .pipe(pixrem()) // add fallbacks for rem units + .pipe(gulp.dest('./static/css/')) + .pipe(rename({ suffix: '.min' })) + .pipe(cssnano()) // Minifies the result + .pipe(gulp.dest('./static/css/')); +}); diff --git a/{{cookiecutter.project_slug}}/package.json b/{{cookiecutter.project_slug}}/package.json index 47cf6944..5c8b82d2 100644 --- a/{{cookiecutter.project_slug}}/package.json +++ b/{{cookiecutter.project_slug}}/package.json @@ -1,19 +1,29 @@ { - "name": "{{cookiecutter.project_slug}}", - "version": "{{ cookiecutter.version }}", + "name": "testing", + "version": "0.1.0", "dependencies": {}, "devDependencies": { - "grunt": "~0.4.5", - "grunt-contrib-watch": "~0.6.1", - "grunt-bg-shell": "~2.3.1", - "connect-livereload": "~0.3.2", - "time-grunt": "~1.2.1", - "load-grunt-tasks": "~3.2.0", - "grunt-sass": "~1.0.0", - "grunt-postcss": "~0.5.5", - "cssnano": "~2.1.0", "autoprefixer-core": "~5.2.1", - "pixrem": "~1.3.1" + "browser-sync": "^2.12.10", + "connect-livereload": "~0.3.2", + "cssnano": "~2.1.0", + "del": "^2.2.0", + "grunt": "~0.4.5", + "grunt-bg-shell": "~2.3.1", + "grunt-contrib-watch": "~0.6.1", + "grunt-postcss": "~0.5.5", + "grunt-sass": "~1.0.0", + "gulp": "^3.9.1", + "gulp-autoprefixer": "^3.1.0", + "gulp-cssnano": "^2.1.2", + "gulp-pixrem": "^1.0.0", + "gulp-plumber": "^1.1.0", + "gulp-rename": "^1.2.2", + "gulp-sass": "^2.3.1", + "gulp-util": "^3.0.7", + "load-grunt-tasks": "~3.2.0", + "pixrem": "~1.3.1", + "time-grunt": "~1.2.1" }, "engines": { "node": ">=0.8.0" From ffc83080c77ff866cf2c9e868d2100bd13890406 Mon Sep 17 00:00:00 2001 From: Emily C Date: Fri, 3 Jun 2016 15:23:00 -0700 Subject: [PATCH 13/22] initial commit --- docs/index.rst | 2 +- docs/my-favorite-cookie.rst | 100 ++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 docs/my-favorite-cookie.rst diff --git a/docs/index.rst b/docs/index.rst index aa88fe24..b7b3885d 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -14,7 +14,7 @@ Contents: .. toctree:: :maxdepth: 2 - + my-favorite-cookie project-generation-options developing-locally developing-locally-docker diff --git a/docs/my-favorite-cookie.rst b/docs/my-favorite-cookie.rst new file mode 100644 index 00000000..a6583352 --- /dev/null +++ b/docs/my-favorite-cookie.rst @@ -0,0 +1,100 @@ +************************************************ +Creating your first app with Cookiecutter-Django +************************************************ + +This tutorial will show you how to build a simple app using the `Cookiecutter Django `_ templating system. We'll be building a cookie polling app to determine the most popular flavor of cookie. + +Developers who have never used Django will learn the basics of creating a Django app; developers who are experienced with Django will learn how to set up a project within the Cookiecutter system. While many Django tutorials use the default SQLite database, Cookiecutter Django uses PostGres only, so we'll have you install and use that. + + +Dependencies +============ +This tutorial was written on Windows 10 using `git bash `_; alternate instructions for Mac OS and Linux will be provided when needed. Any Linux-style shell should work for the following commands. + +You should have your preferred versions of `Python `_ +and `Django `_ installed. Use the latest stable versions if you have no preference. + +You should have `Virtualenv `_ and `Cookiecutter `_ installed: + +.. code-block:: python + + $ pip install virtualenv + $ pip install cookiecutter + +You should also have `PostgreSQL `_ installed on your machine--just download and run the installer for your OS. The install menu will prompt you for a password, which you'll use when creating the project's database. + + +Instructions +============ + +1. **Setup** -- how to set up a virtual environment +2. **Cookiecutter** -- use Cookiecutter to initialize a project with your own customized information. +3. **Building the App** -- creating the My Favorite Cookie application. + +============ +1. Setup +============ + +Virtual Environment +""""""""""""""""""" + +Create a virtual environment for your project. Cookiecutter will install a bunch of dependencies for you automatically; using a virtualenv will prevent this from interfering with your other work. + +.. code-block:: python + + $ virtualenv c:/.virtualenvs/cookie_polls + +Replace ``c:/.virtualenvs`` with the path to your own ``.virtualenvs`` folder. + +Activate the virtual environment by calling ``source`` on the ``activate`` shell script . On Windows you'll call this from the virtualenv's ``scripts`` folder: + +.. code-block:: python + + $ source /path/to/.virtualenvs/cookie_polls/scripts/activate + +On other operating systems, it'll be found in the ``bin`` folder. + +.. code-block:: python + + $ source /path/to/.virtualenvs/cookie_polls/bin/activate + +You'll know the virtual environment is active because its name will appear in parentheses before the command prompt. When you're done with this project, you can leave the virtual environment with the ``deactivate`` command. + +.. code-block:: python + + (cookie_polls) + $ deactivate + + +Now you're ready to create your project using Cookiecutter. + + +=============== +2. Cookiecutter +=============== + +Django developers may be familiar with the ``startproject`` command, which initializes the directory structure and required files for a bare-bones Django project. While this is fine when you're just learning Django for the first time, it's not great for a real production app. Cookiecutter takes care of a lot of standard tasks for you, including installing software dependencies, setting up testing files, and including and organizing common libraries like Bootstrap and AngularJS. It also generates a software license and a README. + +Change directories into the folder where you want your project to live, and run ``cookiecutter`` followed by the URL of Cookiecutter's Github repo. + +.. code-block:: python + + $ cd /my/project/folder + (cookie_polls) + my/project/folder + $ cookiecutter https://github.com/pydanny/cookiecutter-django + +This will prompt you for a bunch of values specific to your project. Press "enter" without typing anything to use the default values, which are shown in [brackets] after the question. You can learn about all the different options `here, `_ but for now we'll use the defaults for everything but your name, your email, the project's name, and the project's description. + +.. code-block:: python + + project_name [project_name]: My Favorite Cookie + project_slug [My_Favorite_Cookie]: + author_name [Your Name]: Emily Cain + email [Your email]: contact@emcain.net + description [A short description of the project.]: Poll your friends to determine the most popular cookie. + +Then hit "enter" to use the default values for everything else. + + + From 87845bd81700d75b983ed7322f016e064ed6fa8f Mon Sep 17 00:00:00 2001 From: Audrey Roy Greenfeld Date: Fri, 3 Jun 2016 15:31:50 -0700 Subject: [PATCH 14/22] Temp quick fixes to improve developing-locally doc --- docs/developing-locally.rst | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/docs/developing-locally.rst b/docs/developing-locally.rst index 11985690..a7f0269f 100644 --- a/docs/developing-locally.rst +++ b/docs/developing-locally.rst @@ -9,20 +9,32 @@ The steps below will get you up and running with a local development environment * virtualenv * PostgreSQL -First make sure to create and activate a virtualenv_, then open a terminal at the project root and install the os dependencies:: +First make sure to create and activate a virtualenv_. - $ sudo ./install_os_dependencies.sh install +.. _virtualenv: http://docs.python-guide.org/en/latest/dev/virtualenvs/ Then install the requirements for your local development:: $ pip install -r requirements/local.txt -.. _virtualenv: http://docs.python-guide.org/en/latest/dev/virtualenvs/ - Then, create a PostgreSQL database with the following command, where `[project_slug]` is what value you entered for your project's `project_slug`:: $ createdb [project_slug] +You can now run the usual Django ``migrate`` and ``runserver`` commands:: + + $ python manage.py migrate + $ python manage.py runserver + +At this point you can take a break from setup and start getting to know the files in the project. + +But if you want to go further with setup, read on. + +(Note: the following sections still need to be revised) + +Setting Up Env Vars for Production +----------------------------------- + `Cookiecutter Django` uses the excellent `django-environ`_ package with its ``DATABASE_URL`` environment variable to simplify database configuration in your Django settings. Now all you have to do is rename env.example to .env and then compose a definition for ``DATABASE_URL`` as shown below and add it to the .env file: .. parsed-literal:: @@ -31,12 +43,8 @@ Then, create a PostgreSQL database with the following command, where `[project_s .. _django-environ: http://django-environ.readthedocs.io -You can now run the usual Django ``migrate`` and ``runserver`` commands:: - - $ python manage.py migrate - $ python manage.py runserver - -**Setup your email backend** +Setup your email backend +------------------------- django-allauth sends an email to verify users (and superusers) after signup and login (if they are still not verified). To send email you need to `configure your email backend`_ @@ -85,5 +93,3 @@ The base app will now run as it would with the usual ``manage.py runserver`` but To get live reloading to work you'll probably need to install an `appropriate browser extension`_ .. _appropriate browser extension: http://feedback.livereload.com/knowledgebase/articles/86242-how-do-i-install-and-use-the-browser-extensions- - -It's time to write the code!!! From 907b8ecfbda0e54b1cf535476b7127434db8585a Mon Sep 17 00:00:00 2001 From: Leonardo Date: Fri, 3 Jun 2016 16:07:27 -0700 Subject: [PATCH 15/22] Remove django-secure (#579) * Eliminate django-secure from requirements and settings files * Include secure defaults for django security middleware * Add settings required by SecurityMiddleware also remove django-secure in prod settings * Eliminate empty spaces generated on Jinja on config/settings/production.py --- .../config/settings/common.py | 2 +- .../config/settings/production.py | 48 +++++++++---------- .../requirements/base.txt | 1 - 3 files changed, 23 insertions(+), 28 deletions(-) diff --git a/{{cookiecutter.project_slug}}/config/settings/common.py b/{{cookiecutter.project_slug}}/config/settings/common.py index 3668b427..3e11ee43 100644 --- a/{{cookiecutter.project_slug}}/config/settings/common.py +++ b/{{cookiecutter.project_slug}}/config/settings/common.py @@ -53,7 +53,7 @@ INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS # MIDDLEWARE CONFIGURATION # ------------------------------------------------------------------------------ MIDDLEWARE_CLASSES = ( - # Make sure djangosecure.middleware.SecurityMiddleware is listed first + 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', diff --git a/{{cookiecutter.project_slug}}/config/settings/production.py b/{{cookiecutter.project_slug}}/config/settings/production.py index 80302bee..346bf7cb 100644 --- a/{{cookiecutter.project_slug}}/config/settings/production.py +++ b/{{cookiecutter.project_slug}}/config/settings/production.py @@ -29,40 +29,26 @@ from .common import * # noqa # Raises ImproperlyConfigured exception if DJANGO_SECRET_KEY not in os.environ SECRET_KEY = env('DJANGO_SECRET_KEY') + # This ensures that Django will be able to detect a secure connection # properly on Heroku. SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') - -# django-secure -# ------------------------------------------------------------------------------ -INSTALLED_APPS += ('djangosecure', ) -{% if cookiecutter.use_sentry == 'y' -%} +{%- if cookiecutter.use_sentry == 'y'-%} # raven sentry client # See https://docs.getsentry.com/hosted/clients/python/integrations/django/ INSTALLED_APPS += ('raven.contrib.django.raven_compat', ) -{%- endif %} -SECURITY_MIDDLEWARE = ( - 'djangosecure.middleware.SecurityMiddleware', -) -{% if cookiecutter.use_whitenoise == 'y' -%} +{% endif %} +{%- if cookiecutter.use_whitenoise == 'y' %} # Use Whitenoise to serve static files # See: https://whitenoise.readthedocs.io/ -WHITENOISE_MIDDLEWARE = ( - 'whitenoise.middleware.WhiteNoiseMiddleware', -) +WHITENOISE_MIDDLEWARE = ('whitenoise.middleware.WhiteNoiseMiddleware', ) MIDDLEWARE_CLASSES = WHITENOISE_MIDDLEWARE + MIDDLEWARE_CLASSES -{%- endif %} -{% if cookiecutter.use_sentry == 'y' -%} -RAVEN_MIDDLEWARE = ( - 'raven.contrib.django.raven_compat.middleware.SentryResponseErrorIdMiddleware', -) +{% endif %} +{%- if cookiecutter.use_sentry == 'y' -%} +RAVEN_MIDDLEWARE = ('raven.contrib.django.raven_compat.middleware.SentryResponseErrorIdMiddleware', ) MIDDLEWARE_CLASSES = RAVEN_MIDDLEWARE + MIDDLEWARE_CLASSES -{%- endif %} - -# Make sure djangosecure.middleware.SecurityMiddleware is listed first -MIDDLEWARE_CLASSES = SECURITY_MIDDLEWARE + MIDDLEWARE_CLASSES - -{% if cookiecutter.use_opbeat == 'y' -%} +{% endif %} +{%- if cookiecutter.use_opbeat == 'y' -%} # opbeat integration # See https://opbeat.com/languages/django/ INSTALLED_APPS += ('opbeat.contrib.django',) @@ -74,7 +60,13 @@ OPBEAT = { MIDDLEWARE_CLASSES = ( 'opbeat.contrib.django.middleware.OpbeatAPMMiddleware', ) + MIDDLEWARE_CLASSES -{%- endif %} +{% endif %} + +# SECURITY CONFIGURATION +# ------------------------------------------------------------------------------ +# See https://docs.djangoproject.com/en/1.9/ref/middleware/#module-django.middleware.security +# and https://docs.djangoproject.com/ja/1.9/howto/deployment/checklist/#run-manage-py-check-deploy + # set this to 60 seconds and then to 518400 when you can prove it works SECURE_HSTS_SECONDS = 60 SECURE_HSTS_INCLUDE_SUBDOMAINS = env.bool( @@ -82,9 +74,12 @@ SECURE_HSTS_INCLUDE_SUBDOMAINS = env.bool( SECURE_CONTENT_TYPE_NOSNIFF = env.bool( 'DJANGO_SECURE_CONTENT_TYPE_NOSNIFF', default=True) SECURE_BROWSER_XSS_FILTER = True -SESSION_COOKIE_SECURE = False +SESSION_COOKIE_SECURE = True SESSION_COOKIE_HTTPONLY = True SECURE_SSL_REDIRECT = env.bool('DJANGO_SECURE_SSL_REDIRECT', default=True) +CSRF_COOKIE_SECURE = True +CSRF_COOKIE_HTTPONLY = True +X_FRAME_OPTIONS = 'DENY' # SITE CONFIGURATION # ------------------------------------------------------------------------------ @@ -95,6 +90,7 @@ ALLOWED_HOSTS = env.list('DJANGO_ALLOWED_HOSTS', default=['{{cookiecutter.domain INSTALLED_APPS += ('gunicorn', ) + # STORAGE CONFIGURATION # ------------------------------------------------------------------------------ # Uploaded Media Files diff --git a/{{cookiecutter.project_slug}}/requirements/base.txt b/{{cookiecutter.project_slug}}/requirements/base.txt index f5e35acd..67a6fd6b 100644 --- a/{{cookiecutter.project_slug}}/requirements/base.txt +++ b/{{cookiecutter.project_slug}}/requirements/base.txt @@ -11,7 +11,6 @@ django==1.9.6 # Configuration django-environ==0.4.0 -django-secure==1.0.1 {% if cookiecutter.use_whitenoise == 'y' -%} whitenoise==3.0 {%- endif %} From c64027a5cfbe94d7056edb27723433f45bff7dee Mon Sep 17 00:00:00 2001 From: Daniel Roy Greenfeld Date: Fri, 3 Jun 2016 16:09:55 -0700 Subject: [PATCH 16/22] Add @xpostudio4 as a contributor --- CHANGELOG.md | 1 + CONTRIBUTORS.rst | 2 ++ 2 files changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 088fb47a..3038b6f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Deleted - AngularJS (@pydanny) +- django-secure (@xpostudio4) ##[2016-06-02] ### Added diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index 5a0ab6eb..99239b71 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -87,6 +87,7 @@ Listed in alphabetical order. Kevin Ndung'u `@kevgathuku`_ Krzysztof Szumny `@noisy`_ Krzysztof Żuraw `@krzysztofzuraw`_ + Leonardo Jimenez `@xpostudio4`_ Lin Xianyi `@iynaix`_ Luis Nell `@originell`_ Lukas Klein @@ -152,6 +153,7 @@ Listed in alphabetical order. .. _@ikkebr: https://github.com/ikkebr .. _@iynaix: https://github.com/iynaix .. _@jazztpt: https://github.com/jazztpt +.. _@xpostudio4: https://github.com/xpostudio4 .. _@juliocc: https://github.com/juliocc .. _@jvanbrug: https://github.com/jvanbrug .. _@ka7eh: https://github.com/ka7eh From fa89445f6668c7668937c3f6b1d93f10ef557206 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sul=C3=A9?= Date: Fri, 3 Jun 2016 16:35:10 -0700 Subject: [PATCH 17/22] Removing unnecessary version check #534 (#584) * Address issue #534 * missing comma added * remove unecesssary version check #534 --- cookiecutter.json | 3 ++- hooks/pre_gen_project.py | 4 +--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/cookiecutter.json b/cookiecutter.json index 36aa3c30..65879a69 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -21,5 +21,6 @@ "use_docker": "y", "use_heroku": "n", "use_grunt": "n", - "open_source_license": ["MIT", "BSD", "Apache Software License 2.0", "Not open source"] + "open_source_license": ["MIT", "BSD", "Apache Software License 2.0", "Not open source"], + "_cookiecutter_version": "Minimum cookiecutter version" } diff --git a/hooks/pre_gen_project.py b/hooks/pre_gen_project.py index 3dfc190a..9cd168bc 100644 --- a/hooks/pre_gen_project.py +++ b/hooks/pre_gen_project.py @@ -1,8 +1,6 @@ -import cookiecutter - project_slug = '{{ cookiecutter.project_slug }}' if hasattr(project_slug, 'isidentifier'): assert project_slug.isidentifier(), 'Project slug should be valid Python identifier!' -assert cookiecutter.__version__ > '1.3.0', 'Please upgrade your Cookiecutter installation' + From 700ee39be81dd5c0bf529a285ae75c79dd0fbba4 Mon Sep 17 00:00:00 2001 From: Daniel Roy Greenfeld Date: Fri, 3 Jun 2016 16:49:04 -0700 Subject: [PATCH 18/22] Added @suledev to contributors list --- CHANGELOG.md | 1 + CONTRIBUTORS.rst | 2 ++ 2 files changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3038b6f5..f6362f49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Added - Documentation for debugging with Docker (@mjsisley) - Apache 2 License option in `cookiecutter.json` (@dot2dotseurat) +- Removed unnecessary version check from `pre_gen_project.py` (@suledev) ### Deleted - AngularJS (@pydanny) diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index 99239b71..0f559e00 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -109,6 +109,7 @@ Listed in alphabetical order. stepmr `@stepmr`_ Sławek Ehlert `@slafs`_ Srinivas Nyayapati `@shireenrao`_ + Sule Marshall `@suledev`_ Taylor Baldwin Théo Segonds `@show0k`_ Tom Atkins `@knitatoms`_ @@ -174,6 +175,7 @@ Listed in alphabetical order. .. _@shireenrao: https://github.com/shireenrao .. _@slafs: https://github.com/slafs .. _@stepmr: https://github.com/stepmr +.. _@suledev: https://github.com/suledev .. _@Travistock: https://github.com/Tavistock .. _@trungdong: https://github.com/trungdong .. _@yunti: https://github.com/yunti From 8a925db024b114930eacd3caa1509496516183a3 Mon Sep 17 00:00:00 2001 From: Vivian Guillen Date: Fri, 3 Jun 2016 17:05:57 -0700 Subject: [PATCH 19/22] Add gulp alternative as a js task runner --- cookiecutter.json | 2 +- hooks/post_gen_project.py | 38 ++++++++++--- {{cookiecutter.project_slug}}/gulpfile.js | 65 ++++++++++++++++++++-- {{cookiecutter.project_slug}}/package.json | 21 ++++--- 4 files changed, 106 insertions(+), 20 deletions(-) diff --git a/cookiecutter.json b/cookiecutter.json index 8fe7010a..0536bfc9 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -20,7 +20,7 @@ "use_python2": "n", "use_docker": "y", "use_heroku": "n", - "use_grunt": "n", + "js_task_runner": ["Gulp", "Grunt", "None"], "use_angular": "n", "open_source_license": ["MIT", "BSD", "Not open source"] } diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index cffb052e..72abbfca 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -134,7 +134,25 @@ def remove_grunt_files(): """ Removes files needed for grunt if it isn't going to be used """ - for filename in ["Gruntfile.js", "package.json"]: + for filename in ["Gruntfile.js"]: + os.remove(os.path.join( + PROJECT_DIRECTORY, filename + )) + +def remove_gulp_files(): + """ + Removes files needed for grunt if it isn't going to be used + """ + for filename in ["gulpfile.js"]: + os.remove(os.path.join( + PROJECT_DIRECTORY, filename + )) + +def remove_packageJSON_file(): + """ + Removes files needed for grunt if it isn't going to be used + """ + for filename in ["package.json"]: os.remove(os.path.join( PROJECT_DIRECTORY, filename )) @@ -176,18 +194,24 @@ if '{{ cookiecutter.use_heroku }}'.lower() != 'y': if '{{ cookiecutter.use_docker }}'.lower() != 'y': remove_docker_files() -# 6. Removes all grunt files if it isn't going to be used -if '{{ cookiecutter.use_grunt }}'.lower() != 'y': +# 6. Removes all JS task manager files if it isn't going to be used +if '{{ cookiecutter.js_task_runner}}'.lower() == 'gulp': remove_grunt_files() +elif '{{ cookiecutter.js_task_runner}}'.lower() == 'grunt': + remove_gulp_files() +else: + remove_gulp_files() + remove_grunt_files() + remove_packageJSON_file() -# 7. Display a warning if use_docker and use_grunt are selected. Grunt isn't supported by our +# 7. Display a warning if use_docker and js task runner are selected. Grunt isn't supported by our # docker config atm. -if '{{ cookiecutter.use_grunt }}'.lower() == 'y' and '{{ cookiecutter.use_docker }}'.lower() == 'y': +if '{{ cookiecutter.js_task_runner }}'.lower() in ['grunt', 'gulp'] and '{{ cookiecutter.use_docker }}'.lower() == 'y': print( - "You selected to use docker and grunt. This is NOT supported out of the box for now. You " + "You selected to use docker and a JS task runner. This is NOT supported out of the box for now. You " "can continue to use the project like you normally would, but you will need to add a " - " grunt service to your docker configuration manually." + "js task runner service to your docker configuration manually." ) # 7. Display a warning if use_docker and use_mailhog are selected. Mailhog isn't supported by our diff --git a/{{cookiecutter.project_slug}}/gulpfile.js b/{{cookiecutter.project_slug}}/gulpfile.js index 6dddcf29..e5b0df9d 100644 --- a/{{cookiecutter.project_slug}}/gulpfile.js +++ b/{{cookiecutter.project_slug}}/gulpfile.js @@ -14,6 +14,10 @@ var gulp = require('gulp'), del = require('del'), plumber = require('gulp-plumber'), pixrem = require('gulp-pixrem'), + uglify = require('gulp-uglify'), + imagemin = require('gulp-imagemin'), + exec = require('gulp-exec'), + runSequence = require('run-sequence'), browserSync = require('browser-sync'); @@ -38,15 +42,66 @@ var paths = pathsConfig(); //Tasks// //////////////////////////////// -// Styles +// Styles autoprefixing and minification gulp.task('styles', function() { - return gulp.src(paths.sass + '/project.scss', { style: 'expanded' }) + return gulp.src(paths.sass + '/project.scss') .pipe(sass().on('error', sass.logError)) - .pipe(plumber()) // It checks for errors + .pipe(plumber()) // Checks for errors .pipe(autoprefixer({browsers: ['last 2 version']})) // Adds vendor prefixes .pipe(pixrem()) // add fallbacks for rem units - .pipe(gulp.dest('./static/css/')) + .pipe(gulp.dest(paths.css)) .pipe(rename({ suffix: '.min' })) .pipe(cssnano()) // Minifies the result - .pipe(gulp.dest('./static/css/')); + .pipe(gulp.dest(paths.css)); +}); + +// Javascript minification +gulp.task('scripts', function() { + return gulp.src(paths.js + '/project.js') + .pipe(plumber()) // Checks for errors + .pipe(uglify()) // Minifies the js + .pipe(rename({ suffix: '.min' })) + .pipe(gulp.dest(paths.js)); +}); + +// Image compression +gulp.task('imgCompression', function(){ + return gulp.src(paths.images + '/*') + .pipe(imagemin()) // Compresses PNG, JPEG, GIF and SVG images + .pipe(gulp.dest(paths.images)) +}); + +// Run django server +gulp.task('runServer', function() { + exec('python manage.py runserver', function (err, stdout, stderr) { + console.log(stdout); + console.log(stderr); + }); +}); + +// Browser sync server for live reload +gulp.task('browserSync', function() { + browserSync.init( + [paths.css + "/*.css", paths.js + "*.js", paths.templates + '*.html'], { + proxy: "localhost:8000" + }); +}); + +// Default task +gulp.task('default', function() { + runSequence(['styles', 'scripts', 'imgCompression'], 'runServer', 'browserSync'); +}); + +//////////////////////////////// + //Watch// +//////////////////////////////// + +// Watch +gulp.task('watch', ['default'], function() { + + gulp.watch(paths.sass + '/*.scss', ['styles']); + gulp.watch(paths.js + '/*.js', ['scripts']); + gulp.watch(paths.images + '/*', ['imgCompression']); + gulp.watch('templates/*.html'); + }); diff --git a/{{cookiecutter.project_slug}}/package.json b/{{cookiecutter.project_slug}}/package.json index 5c8b82d2..2be4b50c 100644 --- a/{{cookiecutter.project_slug}}/package.json +++ b/{{cookiecutter.project_slug}}/package.json @@ -1,29 +1,36 @@ { - "name": "testing", - "version": "0.1.0", + "name": "{{cookiecutter.project_slug}}", + "version": "{{ cookiecutter.version }}", "dependencies": {}, "devDependencies": { + {% if cookiecutter.js_task_runner == 'Grunt' %} "autoprefixer-core": "~5.2.1", - "browser-sync": "^2.12.10", "connect-livereload": "~0.3.2", "cssnano": "~2.1.0", - "del": "^2.2.0", "grunt": "~0.4.5", "grunt-bg-shell": "~2.3.1", "grunt-contrib-watch": "~0.6.1", "grunt-postcss": "~0.5.5", "grunt-sass": "~1.0.0", + "load-grunt-tasks": "~3.2.0", + "pixrem": "~1.3.1", + "time-grunt": "~1.2.1" + {% elif cookiecutter.js_task_runner == 'Gulp' %} + "browser-sync": "^2.12.10", + "del": "^2.2.0", "gulp": "^3.9.1", "gulp-autoprefixer": "^3.1.0", "gulp-cssnano": "^2.1.2", + "gulp-exec": "^2.1.2", + "gulp-imagemin": "^3.0.1", "gulp-pixrem": "^1.0.0", "gulp-plumber": "^1.1.0", "gulp-rename": "^1.2.2", "gulp-sass": "^2.3.1", + "gulp-uglify": "^1.5.3", "gulp-util": "^3.0.7", - "load-grunt-tasks": "~3.2.0", - "pixrem": "~1.3.1", - "time-grunt": "~1.2.1" + "run-sequence": "^1.2.1" + {% endif %} }, "engines": { "node": ">=0.8.0" From cda3cfc641d0ab66f4b4f86acc8cfc5747341824 Mon Sep 17 00:00:00 2001 From: Vivian Guillen Date: Fri, 3 Jun 2016 17:31:36 -0700 Subject: [PATCH 20/22] merge in @@viviangb #585 --- cookiecutter.json | 5 +- hooks/post_gen_project.py | 38 +++++-- {{cookiecutter.project_slug}}/gulpfile.js | 107 ++++++++++++++++++ {{cookiecutter.project_slug}}/package.json | 37 ++++-- .../static/sass/project.scss | 21 ++++ 5 files changed, 188 insertions(+), 20 deletions(-) create mode 100644 {{cookiecutter.project_slug}}/gulpfile.js diff --git a/cookiecutter.json b/cookiecutter.json index 65879a69..fb01784a 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -20,7 +20,6 @@ "use_python2": "n", "use_docker": "y", "use_heroku": "n", - "use_grunt": "n", - "open_source_license": ["MIT", "BSD", "Apache Software License 2.0", "Not open source"], - "_cookiecutter_version": "Minimum cookiecutter version" + "js_task_runner": ["Gulp", "Grunt", "None"], + "open_source_license": ["MIT", "BSD", "Apache Software License 2.0", "Not open source"] } diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index cffb052e..72abbfca 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -134,7 +134,25 @@ def remove_grunt_files(): """ Removes files needed for grunt if it isn't going to be used """ - for filename in ["Gruntfile.js", "package.json"]: + for filename in ["Gruntfile.js"]: + os.remove(os.path.join( + PROJECT_DIRECTORY, filename + )) + +def remove_gulp_files(): + """ + Removes files needed for grunt if it isn't going to be used + """ + for filename in ["gulpfile.js"]: + os.remove(os.path.join( + PROJECT_DIRECTORY, filename + )) + +def remove_packageJSON_file(): + """ + Removes files needed for grunt if it isn't going to be used + """ + for filename in ["package.json"]: os.remove(os.path.join( PROJECT_DIRECTORY, filename )) @@ -176,18 +194,24 @@ if '{{ cookiecutter.use_heroku }}'.lower() != 'y': if '{{ cookiecutter.use_docker }}'.lower() != 'y': remove_docker_files() -# 6. Removes all grunt files if it isn't going to be used -if '{{ cookiecutter.use_grunt }}'.lower() != 'y': +# 6. Removes all JS task manager files if it isn't going to be used +if '{{ cookiecutter.js_task_runner}}'.lower() == 'gulp': remove_grunt_files() +elif '{{ cookiecutter.js_task_runner}}'.lower() == 'grunt': + remove_gulp_files() +else: + remove_gulp_files() + remove_grunt_files() + remove_packageJSON_file() -# 7. Display a warning if use_docker and use_grunt are selected. Grunt isn't supported by our +# 7. Display a warning if use_docker and js task runner are selected. Grunt isn't supported by our # docker config atm. -if '{{ cookiecutter.use_grunt }}'.lower() == 'y' and '{{ cookiecutter.use_docker }}'.lower() == 'y': +if '{{ cookiecutter.js_task_runner }}'.lower() in ['grunt', 'gulp'] and '{{ cookiecutter.use_docker }}'.lower() == 'y': print( - "You selected to use docker and grunt. This is NOT supported out of the box for now. You " + "You selected to use docker and a JS task runner. This is NOT supported out of the box for now. You " "can continue to use the project like you normally would, but you will need to add a " - " grunt service to your docker configuration manually." + "js task runner service to your docker configuration manually." ) # 7. Display a warning if use_docker and use_mailhog are selected. Mailhog isn't supported by our diff --git a/{{cookiecutter.project_slug}}/gulpfile.js b/{{cookiecutter.project_slug}}/gulpfile.js new file mode 100644 index 00000000..e5b0df9d --- /dev/null +++ b/{{cookiecutter.project_slug}}/gulpfile.js @@ -0,0 +1,107 @@ + +//////////////////////////////// + //Setup// +//////////////////////////////// + +// Plugins +var gulp = require('gulp'), + pjson = require('./package.json'), + gutil = require('gulp-util'), + sass = require('gulp-sass'), + autoprefixer = require('gulp-autoprefixer'), + cssnano = require('gulp-cssnano'), + rename = require('gulp-rename'), + del = require('del'), + plumber = require('gulp-plumber'), + pixrem = require('gulp-pixrem'), + uglify = require('gulp-uglify'), + imagemin = require('gulp-imagemin'), + exec = require('gulp-exec'), + runSequence = require('run-sequence'), + browserSync = require('browser-sync'); + + +// Relative paths function +var pathsConfig = function (appName) { + this.app = "./" + (appName || pjson.name); + + return { + app: this.app, + templates: this.app + '/templates', + css: this.app + '/static/css', + sass: this.app + '/static/sass', + fonts: this.app + '/static/fonts', + images: this.app + '/static/images', + js: this.app + '/static/js', + } +}; + +var paths = pathsConfig(); + +//////////////////////////////// + //Tasks// +//////////////////////////////// + +// Styles autoprefixing and minification +gulp.task('styles', function() { + return gulp.src(paths.sass + '/project.scss') + .pipe(sass().on('error', sass.logError)) + .pipe(plumber()) // Checks for errors + .pipe(autoprefixer({browsers: ['last 2 version']})) // Adds vendor prefixes + .pipe(pixrem()) // add fallbacks for rem units + .pipe(gulp.dest(paths.css)) + .pipe(rename({ suffix: '.min' })) + .pipe(cssnano()) // Minifies the result + .pipe(gulp.dest(paths.css)); +}); + +// Javascript minification +gulp.task('scripts', function() { + return gulp.src(paths.js + '/project.js') + .pipe(plumber()) // Checks for errors + .pipe(uglify()) // Minifies the js + .pipe(rename({ suffix: '.min' })) + .pipe(gulp.dest(paths.js)); +}); + +// Image compression +gulp.task('imgCompression', function(){ + return gulp.src(paths.images + '/*') + .pipe(imagemin()) // Compresses PNG, JPEG, GIF and SVG images + .pipe(gulp.dest(paths.images)) +}); + +// Run django server +gulp.task('runServer', function() { + exec('python manage.py runserver', function (err, stdout, stderr) { + console.log(stdout); + console.log(stderr); + }); +}); + +// Browser sync server for live reload +gulp.task('browserSync', function() { + browserSync.init( + [paths.css + "/*.css", paths.js + "*.js", paths.templates + '*.html'], { + proxy: "localhost:8000" + }); +}); + +// Default task +gulp.task('default', function() { + runSequence(['styles', 'scripts', 'imgCompression'], 'runServer', 'browserSync'); +}); + +//////////////////////////////// + //Watch// +//////////////////////////////// + +// Watch +gulp.task('watch', ['default'], function() { + + gulp.watch(paths.sass + '/*.scss', ['styles']); + gulp.watch(paths.js + '/*.js', ['scripts']); + gulp.watch(paths.images + '/*', ['imgCompression']); + gulp.watch('templates/*.html'); + +}); diff --git a/{{cookiecutter.project_slug}}/package.json b/{{cookiecutter.project_slug}}/package.json index 47cf6944..2be4b50c 100644 --- a/{{cookiecutter.project_slug}}/package.json +++ b/{{cookiecutter.project_slug}}/package.json @@ -3,17 +3,34 @@ "version": "{{ cookiecutter.version }}", "dependencies": {}, "devDependencies": { - "grunt": "~0.4.5", - "grunt-contrib-watch": "~0.6.1", - "grunt-bg-shell": "~2.3.1", - "connect-livereload": "~0.3.2", - "time-grunt": "~1.2.1", - "load-grunt-tasks": "~3.2.0", - "grunt-sass": "~1.0.0", - "grunt-postcss": "~0.5.5", - "cssnano": "~2.1.0", + {% if cookiecutter.js_task_runner == 'Grunt' %} "autoprefixer-core": "~5.2.1", - "pixrem": "~1.3.1" + "connect-livereload": "~0.3.2", + "cssnano": "~2.1.0", + "grunt": "~0.4.5", + "grunt-bg-shell": "~2.3.1", + "grunt-contrib-watch": "~0.6.1", + "grunt-postcss": "~0.5.5", + "grunt-sass": "~1.0.0", + "load-grunt-tasks": "~3.2.0", + "pixrem": "~1.3.1", + "time-grunt": "~1.2.1" + {% elif cookiecutter.js_task_runner == 'Gulp' %} + "browser-sync": "^2.12.10", + "del": "^2.2.0", + "gulp": "^3.9.1", + "gulp-autoprefixer": "^3.1.0", + "gulp-cssnano": "^2.1.2", + "gulp-exec": "^2.1.2", + "gulp-imagemin": "^3.0.1", + "gulp-pixrem": "^1.0.0", + "gulp-plumber": "^1.1.0", + "gulp-rename": "^1.2.2", + "gulp-sass": "^2.3.1", + "gulp-uglify": "^1.5.3", + "gulp-util": "^3.0.7", + "run-sequence": "^1.2.1" + {% endif %} }, "engines": { "node": ">=0.8.0" diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/static/sass/project.scss b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/static/sass/project.scss index e737d593..54632b2d 100644 --- a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/static/sass/project.scss +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/static/sass/project.scss @@ -1,5 +1,10 @@ + // project specific CSS goes here +//////////////////////////////// + //Variables// +//////////////////////////////// + // Alert colors $white: #fff; @@ -9,6 +14,10 @@ $pink: #f2dede; $dark-pink: #eed3d7; $red: #b94a48; +//////////////////////////////// + //Alerts// +//////////////////////////////// + // bootstrap alert CSS, translated to the django-standard levels of // debug, info, success, warning, error @@ -24,8 +33,16 @@ $red: #b94a48; color: $red; } +//////////////////////////////// + //Navbar// +//////////////////////////////// + // This is a fix for the bootstrap4 alpha release +.navbar { + border-radius: 0px; +} + @media (max-width: 47.9em) { .navbar-nav .nav-item { display: inline-block; @@ -42,6 +59,10 @@ $red: #b94a48; } } +//////////////////////////////// + //Django Toolbar// +//////////////////////////////// + // Display django-debug-toolbar. // See https://github.com/django-debug-toolbar/django-debug-toolbar/issues/742 // and https://github.com/pydanny/cookiecutter-django/issues/317 From 38c6fb75ed86bfc20ad17e2e16a90ea02f62e499 Mon Sep 17 00:00:00 2001 From: Daniel Roy Greenfeld Date: Fri, 3 Jun 2016 17:39:13 -0700 Subject: [PATCH 21/22] Added @viviangb to contributors --- CHANGELOG.md | 1 + CONTRIBUTORS.rst | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f6362f49..bffc7689 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Documentation for debugging with Docker (@mjsisley) - Apache 2 License option in `cookiecutter.json` (@dot2dotseurat) - Removed unnecessary version check from `pre_gen_project.py` (@suledev) +- Add gulp alternative as a js task runner and fix navbar style issue (@viviangb and @xpostudio4) ### Deleted - AngularJS (@pydanny) diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index 0f559e00..d1d4f2f7 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -114,8 +114,9 @@ Listed in alphabetical order. Théo Segonds `@show0k`_ Tom Atkins `@knitatoms`_ Tom Offermann - Travis McNeill `@Travistock`_ @tavistock_esq + Travis McNeill `@Travistock`_ @tavistock_esq Vitaly Babiy + Vivian Guillen `@viviangb`_ Yaroslav Halchenko ========================== ============================ ============== @@ -178,6 +179,7 @@ Listed in alphabetical order. .. _@suledev: https://github.com/suledev .. _@Travistock: https://github.com/Tavistock .. _@trungdong: https://github.com/trungdong +.. _@viviangb: httpsL//github.com/viviangb .. _@yunti: https://github.com/yunti .. _@zcho: https://github.com/zcho .. _@noisy: https://github.com/noisy From fc67ecf17431de8e879f07334e312e5259f599ed Mon Sep 17 00:00:00 2001 From: Audrey Roy Greenfeld Date: Fri, 3 Jun 2016 18:12:18 -0700 Subject: [PATCH 22/22] Remove use_angular option again --- cookiecutter.json | 1 - 1 file changed, 1 deletion(-) diff --git a/cookiecutter.json b/cookiecutter.json index 2240a7d0..fb01784a 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -20,7 +20,6 @@ "use_python2": "n", "use_docker": "y", "use_heroku": "n", - "use_angular": "n", "js_task_runner": ["Gulp", "Grunt", "None"], "open_source_license": ["MIT", "BSD", "Apache Software License 2.0", "Not open source"] }