Skip to content

Commit

Permalink
feat: VERSION 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Chaptsev committed Sep 2, 2018
1 parent 8c5559b commit 58fb3ed
Show file tree
Hide file tree
Showing 97 changed files with 1,498 additions and 930 deletions.
38 changes: 29 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<a href="https://travis-ci.org/vchaptsev/cookiecutter-django-vue">
<img src="https://travis-ci.org/vchaptsev/cookiecutter-django-vue.svg?branch=master" />
</a>

Cookiecutter Django-Vue
=======================

Expand All @@ -8,17 +12,16 @@ inspired by [Cookiecutter Django](https://github.com/pydanny/cookiecutter-django
<img src="https://i.imgur.com/SA8cjs8.png" />
</p>


Features
--------

- [Docker](https://www.docker.com/)
- [12 Factor](http://12factor.net/)
<!-- - Server: [Caddy](https://caddyserver.com/) -->
- Frontend: [Vue](https://vuejs.org/) + vue-cli
- Server: [Nginx](https://nginx.org/)
- Frontend: [Vue](https://vuejs.org/) + [vue-cli](https://cli.vuejs.org/)
- Backend: [Django](https://www.djangoproject.com/)
- Database: [PostgreSQL](https://www.postgresql.org/)
<!-- - [pipenv](https://github.com/pypa/pipenv) for python-requirements -->
- API: REST or GraphQL

Optional Integrations
---------------------
Expand All @@ -27,7 +30,9 @@ Optional Integrations

- Integration with [MailHog](https://github.com/mailhog/MailHog) for local email testing
- Integration with [Sentry](https://sentry.io/welcome/) for frontend and backend errors logging
- Integration with [Portainer](https://portainer.io/) (management UI for docker)
- Integration with [Google Analytics](https://www.google.com/analytics/) or [Yandex Metrika](https://tech.yandex.ru/metrika/) for web-analytics
- Automatic database backups

Usage
-----
Expand All @@ -45,24 +50,33 @@ will be created for you.

Answer the prompts with your own desired options. For example:

======================= GENERAL ====================== [ ]:
======================== INFO ======================= [ ]:
project_name [Project Name]: Website
project_slug [website]: website
description [Short description]: My awesome website
author [Your Name]: Your Name
email [<[email protected]>]: <[email protected]>
======================= DEVOPS ======================= [ ]:
====================== GENERAL ====================== [ ]:
Select api:
1 - REST
2 - GraphQL
Choose from 1, 2 [1]: 2
backups [y]: y
==================== INTEGRATIONS =================== [ ]:
use_sentry [y]: y
======================= BACKEND ====================== [ ]:
use_portainer [y]: y
use_mailhog [y]: y
custom_user [n]: n
======================= FRONTEND ===================== [ ]:
Select analytics:
1 - Google Analytics
2 - Yandex Metrika
3 - None
Choose from 1, 2, 3 [1]: 2

Project creation will cause some odd newlines and linter errors, so I'd recommend:

$ autopep8 -r --in-place --aggressive --aggressive .
$ npm run lint --fix

Now you can start project with
[docker-compose](https://docs.docker.com/compose/):

Expand All @@ -72,3 +86,9 @@ For production you'll need to fill out `.env` file and use
`docker-compose-prod.yml` file:

$ docker-compose -f docker-compose-prod.yml up --build -d


Contributing
------------

Help and feedback are welcome :)
17 changes: 8 additions & 9 deletions cookiecutter.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"======================= GENERAL ======================": " ",
"======================== INFO =======================": " ",
"project_name": "Project Name",
"project_slug": "{{ cookiecutter.project_name.lower()|replace(' ', '_')|replace('-', '_') }}",
"domain": "{{ cookiecutter.project_slug }}.com",
Expand All @@ -8,14 +8,13 @@
"author": "Your Name",
"email": "admin@{{ cookiecutter.domain }}",

"======================= DEVOPS =======================": " ",
"use_travis": "y",
"====================== GENERAL ======================": " ",
"api": ["REST", "GraphQL"],
"backups": "y",

"==================== INTEGRATIONS ===================": " ",
"use_sentry": "y",

"======================= BACKEND ======================": " ",
"use_portainer": "y",
"use_mailhog": "y",
"custom_user": "n",

"======================= FRONTEND =====================": " ",
"analytics": ["Google Analytics", "Yandex Metrika", "None"],
"analytics": ["Google Analytics", "Yandex Metrika", "None"]
}
47 changes: 28 additions & 19 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
1. Generates and saves random secret key
2. Renames env.example to .env
3. Removes users app if it isn't going to be used
3. Deletes unused API files
"""
import os
import random
Expand All @@ -12,38 +12,47 @@
PROJECT_DIRECTORY = os.path.realpath(os.path.curdir)


def set_secret_key(file_location):
def set_secret_key():
""" Generates and saves random secret key """
with open(file_location) as f:
with open(os.path.join(PROJECT_DIRECTORY, 'env.example')) as f:
file_ = f.read()

punctuation = string.punctuation.replace('"', '').replace("'", '').replace('\\', '')
secret = ''.join(random.choice(string.digits + string.ascii_letters + punctuation) for i in range(50))
file_ = file_.replace('CHANGEME!!!', secret, 1)

# Write the results
with open(file_location, 'w') as f:
with open(os.path.join(PROJECT_DIRECTORY, 'env.example'), 'w') as f:
f.write(file_)


def rename_env_file():
""" Renames env file """
os.rename(os.path.join(PROJECT_DIRECTORY, 'env.example'), os.path.join(PROJECT_DIRECTORY, '.env'))

def remove_users_app():
""" Removes users app if it isn't going to be used """
users_app = os.path.join(PROJECT_DIRECTORY, '{{ cookiecutter.project_slug }}/users')
shutil.rmtree(users_app)

for filename in ['modules/auth.js', 'services/users.js']:
os.remove(os.path.join(PROJECT_DIRECTORY, '{{ cookiecutter.project_slug }}/static/store/' + filename))

# Removes users app if it isn't going to be used
if '{{ cookiecutter.custom_user }}' == 'n':
remove_users_app()

# Generates and saves random secret key
set_secret_key(os.path.join(PROJECT_DIRECTORY, 'env.example')) # env file

# Renames env file
def delete_api_files():
""" Deletes unused API files """
if '{{ cookiecutter.api }}' == 'REST':
files = [
'.graphqlrc',
'backend/config/schema.py',
'backend/apps/users/schema.py',
'frontend/src/apollo.js',
]
shutil.rmtree(os.path.join(PROJECT_DIRECTORY, 'frontend/src/graphql'))
else:
files = [
'backend/config/api.py',
'backend/apps/users/views.py',
'backend/apps/users/serializers.py',
]
shutil.rmtree(os.path.join(PROJECT_DIRECTORY, 'frontend/src/store'))

for filename in files:
os.remove(os.path.join(PROJECT_DIRECTORY, filename))


set_secret_key()
rename_env_file()
delete_api_files()
6 changes: 2 additions & 4 deletions tests/test_docker.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/bin/sh

# install test requirements
pip install pipenv
pipenv install --system
pip install -r requirements.txt

# create a cache directory
mkdir -p .cache/docker && cd .cache/docker
Expand All @@ -11,5 +10,4 @@ mkdir -p .cache/docker && cd .cache/docker
# DEFAULT SETTINGS
cookiecutter ../../ --no-input --overwrite-if-exists && cd project_name

# run the project's tests
docker-compose run backend py.test
docker-compose run backend python manage.py check
13 changes: 13 additions & 0 deletions {{cookiecutter.project_slug}}/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
root = true

[*]
indent_size = 2
charset = utf-8
end_of_line = lf
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.py]
indent_size = 4
max_line_length = 120
78 changes: 78 additions & 0 deletions {{cookiecutter.project_slug}}/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
### OSX ###
.DS_Store
.AppleDouble
.LSOverride

### SublimeText ###
# cache files for sublime text
*.tmlanguage.cache
*.tmPreferences.cache
*.stTheme.cache

*.sublime-project
*.sublime-workspace

# sftp configuration file
sftp-config.json

# Basics
*.py[cod]
__pycache__

# Logs
logs
*.log
pip-log.txt
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Unit test / coverage reports
.coverage
.tox
nosetests.xml
htmlcov

# Translations
*.mo
*.pot

# Webpack
webpack-stats.json
dist/

# Vim
*~
*.swp
*.swo

# npm
node_modules

# Compass
.sass-cache

# User-uploaded media
media/

# Collected staticfiles
*/staticfiles/

.cache/
**/certs

# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw*

# VS code
.vscode
.pythonconfig

# Venv
venv
5 changes: 5 additions & 0 deletions {{cookiecutter.project_slug}}/.graphqlrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"request": {
"url": "http://localhost:8000/graphql"
}
}
10 changes: 6 additions & 4 deletions {{cookiecutter.project_slug}}/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

{{cookiecutter.description}}

<a href="https://github.com/vchaptsev/cookiecutter-django-vue">
<img src="https://img.shields.io/badge/built%20with-Cookiecutter%20Django%20Vue-blue.svg" />
</a>
<a href="https://github.com/vchaptsev/cookiecutter-django-vue">
<img src="https://img.shields.io/badge/built%20with-Cookiecutter%20Django%20Vue-blue.svg" />
</a>

{% endif %}

## Development
+ run `docker-compose up --build`
18 changes: 18 additions & 0 deletions {{cookiecutter.project_slug}}/backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM python:3.6

# python envs
ENV PYTHONFAULTHANDLER=1 \
PYTHONUNBUFFERED=1 \
PYTHONHASHSEED=random \
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100

# python dependencies
COPY ./requirements.txt /
RUN pip install -r ./requirements.txt

# upload scripts
COPY ./scripts/entrypoint.sh ./scripts/start.sh ./scripts/gunicorn.sh /

WORKDIR /app
2 changes: 0 additions & 2 deletions {{cookiecutter.project_slug}}/backend/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
__version__ = '0.1.0'
__version_info__ = tuple([int(num) if num.isdigit() else num for num in __version__.replace('-', '.', 1).split('.')])
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from django.contrib.auth.models import Group
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin

from .models import User
from .forms import UserChangeForm, UserCreationForm
from apps.users.models import User
from apps.users.forms import UserChangeForm, UserCreationForm


class UserAdmin(BaseUserAdmin):
Expand All @@ -18,13 +18,13 @@ class UserAdmin(BaseUserAdmin):
['Auth', {'fields': ['email', 'password']}],
['Personal info', {'fields': ['last_name', 'first_name', 'avatar']}],
['Settings', {'fields': ['groups', 'is_admin', 'is_active', 'is_staff', 'is_superuser']}],
['Important dates', {'fields': ['last_login', 'registered_at']}]
['Important dates', {'fields': ['last_login', 'registered_at']}],
]
# add_fieldsets is not a standard ModelAdmin attribute. UserAdmin
# overrides get_fieldsets to use this attribute when creating a user.
add_fieldsets = [
[None, {'classes': ['wide'],
'fields': ['email', 'first_name', 'last_name', 'password1', 'password2']}]
'fields': ['email', 'first_name', 'last_name', 'password1', 'password2']}],
]
search_fields = ['email']
ordering = ['email']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


class UsersConfig(AppConfig):
name = '{{cookiecutter.project_slug}}.users'
name = 'apps.users'
verbose_name = 'Users'
Loading

0 comments on commit 58fb3ed

Please sign in to comment.