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

Upgrade packages version. Add DRF, rest-auth, django-constance. #6

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@
"project_name": "project_name",
"repo_name": "{{ cookiecutter.project_name|replace(' ', '_') }}",
"python_version": ["2", "3.5", "3.6"],
"use_django_rest_framework": "n",
"use_postgresql": "y",
"use_postgis": "n",
"use_mysql": "n",
"use_celery": "n",
"use_allauth": "n",
"use_rest_auth": "n",
"use_redis": "n",
"use_rabbitmq": "n",
"use_supervisor": "n",
"use_apache": "n",
"use_nginx": "n",
"use_robots": "n",
"use_seo": "n"
"use_seo": "n",
"use_constance": "n"
}
5 changes: 4 additions & 1 deletion hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import random
import shutil

import time
from cookiecutter.config import DEFAULT_CONFIG

# Get the root project directory
Expand All @@ -30,6 +31,7 @@
# 'on your system. Falling back to Mersenne Twister.')
using_sysrandom = False


def get_random_string(
length=50,
allowed_chars='abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'):
Expand All @@ -52,7 +54,8 @@ def get_random_string(
time.time(),
settings.SECRET_KEY)).encode('utf-8')
).digest())
return ''.join(random.choice(allowed_chars) for i in range(length))
return ''.join(random.choice(allowed_chars) for _ in range(length))


def set_secret_key(setting_file_location):
# Open locals.py
Expand Down
4 changes: 2 additions & 2 deletions {{cookiecutter.repo_name}}/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{%- if cookiecutter.use_robots == "y" %}
{% if cookiecutter.use_robots == "y" %}
* ``./manage.py loaddata fixtures/robots_rules.json`` - default robots rules
{%- endif %}
{% endif %}
1 change: 0 additions & 1 deletion {{cookiecutter.repo_name}}/ansible/vagrant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@
- { role: redis, when: "redis == true" }
- { role: supervisor, when: "supervisor == true" }
- { role: app, when: "app == true" }

16 changes: 8 additions & 8 deletions {{cookiecutter.repo_name}}/ansible/vars/vagrant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ application_name: {{cookiecutter.repo_name}}
# Database settings.
db_user: "vagrant"
db_name: "{{ application_name }}"
db_password: ""
db_password: "vagrant"

# Application settings.
virtualenv_path: "/home/vagrant/venv"
Expand All @@ -20,11 +20,11 @@ django_settings: "config.settings"
python_version: {{ cookiecutter.python_version }}

# Services
mysql: {% if cookiecutter.use_mysql == "y" -%}true{% else %}no{%- endif %}
apache: {% if cookiecutter.use_apache == "y" -%}true{% else %}no{%- endif %}
nginx: {% if cookiecutter.use_nginx == "y" -%}true{% else %}no{%- endif %}
postgresql: {% if cookiecutter.use_postgresql == "y" or cookiecutter.use_postgis == "y" -%}true{% else %}no{%- endif %}
rabbitmq: {% if cookiecutter.use_rabbitmq == "y" -%}true{% else %}no{%- endif %}
redis: {% if cookiecutter.use_redis == "y" -%}true{% else %}no{%- endif %}
supervisor: {% if cookiecutter.use_supervisor == "y" -%}true{% else %}no{%- endif %}
mysql: {% if cookiecutter.use_mysql == "y" %}true{% else %}no{% endif %}
apache: {% if cookiecutter.use_apache == "y" %}true{% else %}no{% endif %}
nginx: {% if cookiecutter.use_nginx == "y" %}true{% else %}no{% endif %}
postgresql: {% if cookiecutter.use_postgresql == "y" or cookiecutter.use_postgis == "y" %}true{% else %}no{% endif %}
rabbitmq: {% if cookiecutter.use_rabbitmq == "y" %}true{% else %}no{% endif %}
redis: {% if cookiecutter.use_redis == "y" %}true{% else %}no{% endif %}
supervisor: {% if cookiecutter.use_supervisor == "y" %}true{% else %}no{% endif %}
app: true
76 changes: 57 additions & 19 deletions {{cookiecutter.repo_name}}/config/settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-

from __future__ import absolute_import, unicode_literals

import os
Expand All @@ -11,6 +10,8 @@
ROOT_DIR = environ.Path(__file__) - 2 # (/a/myfile.py - 2 = /)
APPS_DIR = ROOT_DIR.path('{{ cookiecutter.repo_name }}')

TEST_RUNNING = True if len(environ.sys.argv) > 1 and environ.sys.argv[1] == 'test' else False

env = environ.Env(
DJANGO_DEBUG=(bool, False),
DJANGO_SECRET_KEY=(str, 'CHANGEME!!!'),
Expand All @@ -24,17 +25,19 @@
DJANGO_EMAIL_BACKEND=(str, 'django.core.mail.backends.smtp.EmailBackend'),
DJANGO_SERVER_EMAIL=(str, 'root@localhost.com'),
{% if cookiecutter.use_celery == "y" %}
{% if cookiecutter.use_redis == "y" -%}
{%- if cookiecutter.use_redis == "y" %}
DJANGO_CELERY_BROKER_URL=(str, 'redis://localhost:6379/0'),
DJANGO_CELERY_BACKEND=(str, 'redis://localhost:6379/0'),
{% elif cookiecutter.use_rabbitmq == "y" -%}
{%- elif cookiecutter.use_rabbitmq == "y" %}
DJANGO_CELERY_BROKER_URL=(str, 'amqp://guest:guest@localhost:5672//'),
{% else -%}
{%- else %}
DJANGO_CELERY_BROKER_URL=(str, 'django://'),
{% endif -%}
{%- endif %}
DJANGO_CELERY_ALWAYS_EAGER=(bool, False),
{% endif %}
{%- endif %}

DJANGO_USE_DEBUG_TOOLBAR=(bool, False),
DJANGO_USE_DEBUG_PANEL=(bool, False),
DJANGO_TEST_RUN=(bool, False),

DJANGO_HEALTH_CHECK_BODY=(str, 'Success'),
Expand All @@ -43,7 +46,7 @@

environ.Env.read_env()

DEBUG = env.bool("DJANGO_DEBUG")
DEBUG = env.bool('DJANGO_DEBUG')

SECRET_KEY = env('DJANGO_SECRET_KEY')

Expand Down Expand Up @@ -84,11 +87,24 @@
{%- if cookiecutter.use_redis != "y" and cookiecutter.use_rabbitmq != "y" and cookiecutter.use_celery == "y" %}
'kombu.transport.django',
{%- endif %}
{% if cookiecutter.use_allauth == 'y' -%}
{%- if cookiecutter.use_allauth == 'y' %}
'allauth',
'allauth.account',
'allauth.socialaccount',
{%- endif %}
{%- if cookiecutter.use_constance == 'y' %}
'constance',
'constance.backends.database',
{%- endif %}
{%- if cookiecutter.use_django_rest_framework == "y" %}
'rest_framework',
'rest_framework.authtoken',
'corsheaders',
{%- endif %}
{%- if cookiecutter.use_allauth == 'y' and cookiecutter.use_rest_auth == "y" %}
'rest_auth',
'rest_auth.registration',
{%- endif %}
{%- if cookiecutter.use_robots == "y" %}
'robots',
{%- endif %}
Expand All @@ -110,7 +126,7 @@
AUTH_USER_MODEL = 'users.User'
ADMIN_URL = r'^admin/'

MIDDLEWARE_CLASSES = [
MIDDLEWARE = [
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
Expand Down Expand Up @@ -157,7 +173,7 @@
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
{%- if cookiecutter.use_seo == 'y' %}
{% if cookiecutter.use_seo == 'y' %}
'{{ cookiecutter.repo_name }}.seo.context_processors.get_page_meta_data',
{%- endif %}
],
Expand Down Expand Up @@ -186,23 +202,23 @@
{% if cookiecutter.use_celery == "y" %}
# celery settings
BROKER_URL = env('DJANGO_CELERY_BROKER_URL')
{% if cookiecutter.use_redis == "y" -%}
{%- if cookiecutter.use_redis == "y" %}
CELERY_BACKEND = env('DJANGO_CELERY_BACKEND')
{% endif -%}
{%- endif %}
CELERY_ALWAYS_EAGER = env.bool('DJANGO_CELERY_ALWAYS_EAGER')
{%- endif %}

AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
{% if cookiecutter.use_allauth == 'y' -%}
{%- if cookiecutter.use_allauth == 'y' %}
'allauth.account.auth_backends.AuthenticationBackend',
{%- endif %}
)
{% if cookiecutter.use_allauth == 'y' %}
{%- if cookiecutter.use_allauth == 'y' %}
ACCOUNT_AUTHENTICATION_METHOD = 'username'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = 'mandatory'
{%- endif %}
{% endif %}

{%- if cookiecutter.use_robots == 'y' %}
# Django-Robots
Expand Down Expand Up @@ -262,13 +278,16 @@
'release': raven.fetch_git_sha(str(ROOT_DIR)),
}

USE_DEBUG_TOOLBAR = env.bool('DJANGO_USE_DEBUG_TOOLBAR')
USE_DEBUG_TOOLBAR = env.bool('DJANGO_USE_DEBUG_TOOLBAR') if not TEST_RUNNING else False
USE_DEBUG_PANEL = env.bool('DJANGO_USE_DEBUG_PANEL') if not TEST_RUNNING else False
if USE_DEBUG_TOOLBAR:
MIDDLEWARE_CLASSES += [
'debug_toolbar.middleware.DebugToolbarMiddleware',
middleware = 'debug_panel.middleware.DebugPanelMiddleware' if USE_DEBUG_PANEL else 'debug_toolbar.middleware.DebugToolbarMiddleware' # noqa
MIDDLEWARE += [
middleware
]
INSTALLED_APPS += (
'debug_toolbar',
'debug_panel',
)
DEBUG_TOOLBAR_CONFIG = {
'DISABLE_PANELS': [
Expand Down Expand Up @@ -302,9 +321,28 @@
INSTALLED_APPS += (
'silk',
)
MIDDLEWARE_CLASSES += [
MIDDLEWARE += [
'silk.middleware.SilkyMiddleware',
]
SILKY_AUTHENTICATION = True # User must login
SILKY_AUTHORISATION = True # User must have permissions
SILKY_PERMISSIONS = lambda user: user.is_superuser

{%- if cookiecutter.use_constance == 'y' %}
# Django constance config
CONSTANCE_BACKEND = 'constance.backends.database.DatabaseBackend'
# CONSTANCE_CONFIG = {}
{%- endif %}

{%- if cookiecutter.use_django_rest_framework == 'y' %}
# DRF config
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.TokenAuthentication',
),
}
if not DEBUG:
REST_FRAMEWORK['DEFAULT_RENDERER_CLASSES'] = (
'rest_framework.renderers.JSONRenderer',
)
{%- endif %}
8 changes: 4 additions & 4 deletions {{cookiecutter.repo_name}}/config/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import unicode_literals, absolute_import

from django.conf import settings
from django.conf.urls import include, url
Expand All @@ -9,11 +9,11 @@
from django.views import defaults as default_views

urlpatterns = [
url(r'^$', TemplateView.as_view(template_name='base.html'), name="home"),
url(r'^$', TemplateView.as_view(template_name='base.html'), name='home'),
{% raw %}# Django Admin, use {% url 'admin:index' %}{% endraw %}
url(settings.ADMIN_URL, include(admin.site.urls)),
url(r'^users/', include("{{ cookiecutter.repo_name }}.users.urls", namespace="users")),
url(r'^common/', include("{{ cookiecutter.repo_name }}.common.urls", namespace="common")),
url(r'^users/', include('{{ cookiecutter.repo_name }}.users.urls', namespace='users')),
url(r'^common/', include('{{ cookiecutter.repo_name }}.common.urls', namespace='common')),
{%- if cookiecutter.use_allauth == 'y' %}
url(r'^accounts/', include('allauth.urls')),
{%- endif %}
Expand Down
19 changes: 10 additions & 9 deletions {{cookiecutter.repo_name}}/env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,32 @@ DJANGO_ADMINS=Some User:some.user@gmail.com,
DJANGO_ALLOWED_HOSTS=localhost,127.0.0.1
DJANGO_STATIC_ROOT=path/to/static/root
DJANGO_MEDIA_ROOT=path/to/media/root
{% if cookiecutter.use_postgis == "y" -%}
{% if cookiecutter.use_postgis == "y" %}
DJANGO_DATABASE_URL=postgis:///{{ cookiecutter.repo_name }}
{%- elif cookiecutter.use_postgresql == "y" -%}
{% elif cookiecutter.use_postgresql == "y" %}
DJANGO_DATABASE_URL=postgres:///{{ cookiecutter.repo_name }}
{%- elif cookiecutter.use_mysql == "y" -%}
{% elif cookiecutter.use_mysql == "y" %}
DJANGO_DATABASE_URL=mysql:///{{ cookiecutter.repo_name }}
{%- endif %}
{% endif %}
DJANGO_EMAIL_URL="smtp://user@:password@localhost:25"

DJANGO_DEFAULT_FROM_EMAIL=admin@example.com
DJANGO_EMAIL_BACKEND=django.core.mail.backends.smtp.EmailBackend
DJANGO_SERVER_EMAIL=root@localhost.com
{% if cookiecutter.use_celery == "y" %}
{% if cookiecutter.use_redis == "y" -%}
{% if cookiecutter.use_redis == "y" %}
DJANGO_CELERY_BROKER_URL=redis://localhost:6379/1
DJANGO_CELERY_BACKEND=redis://localhost:6379/1
{% elif cookiecutter.use_rabbitmq == "y" -%}
{% elif cookiecutter.use_rabbitmq == "y" %}
DJANGO_CELERY_BROKER_URL=amqp://guest:guest@localhost:5672//
{% else -%}
{% else %}
DJANGO_CELERY_BROKER_URL=django://
{% endif -%}
{% endif %}
DJANGO_CELERY_ALWAYS_EAGER=off
{%- endif %}
{% endif %}

DJANGO_USE_DEBUG_TOOLBAR=off
DJANGO_USE_DEBUG_PANEL=off
DJANGO_TEST_RUN=off

DJANGO_HEALTH_CHECK_BODY="Success"
Expand Down
46 changes: 31 additions & 15 deletions {{cookiecutter.repo_name}}/requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,40 @@
{%- if cookiecutter.use_celery == "y" -%}
celery==4.0.2
{%- endif %}
Django==1.11.2
Django==1.11.7
{%- if cookiecutter.use_allauth == 'y' %}
django-allauth==0.32.0
django-allauth==0.34.0
{%- endif %}
django-braces==1.11.0
django-environ==0.4.3
django-extensions==1.7.9
django-model-utils==3.0.0
Pillow==4.1.1
psycopg2==2.7.1
pytz==2017.2
raven==6.1.0
{%- if cookiecutter.use_redis == "y" %}
redis>=2.10.5
django-redis-cache==1.7.1
{%- if cookiecutter.use_constance == 'y' %}
django-constance[database]==2.0.0
{%- endif %}
{%- if cookiecutter.use_django_rest_framework == "y" %}
django-cors-headers==2.1.0
{%- endif %}
django-environ==0.4.4
django-extensions==1.9.7
django-model-utils==3.0.0
{%- if cookiecutter.use_robots == "y" %}
django-robots==3.0
{%- endif %}
{%- if cookiecutter.use_redis == "y" %}
django-redis-cache==1.7.1
{%- endif %}
django-solo==1.1.2
django-silk==1.0.0

{%- if cookiecutter.use_django_rest_framework == "y" %}
djangorestframework==3.7.3
{%- endif %}
{%- if cookiecutter.use_rest_auth == "y" %}
django-rest-auth==0.9.2
{%- endif %}

Pillow==4.3.0
psycopg2==2.7.3.2
pytz==2017.3
raven==6.3.0
{%- if cookiecutter.use_redis == "y" %}
redis>=2.10.5
{%- endif %}
{%- if cookiecutter.use_celery == "y" %}
celery==4.1.0
{% endif %}
7 changes: 4 additions & 3 deletions {{cookiecutter.repo_name}}/requirements/local.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
-r base.txt

django-debug-toolbar==1.6
ipdb==0.10.2
django-debug-toolbar==1.9.1
django-debug-panel==0.8.3
ipdb==0.10.3

factory-boy==2.8.1
coverage==4.3.4
coverage==4.4.2
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.contrib import admin
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, absolute_import

# Register your models here.
from django.contrib import admin
Loading