Skip to content

Commit 58fb3ed

Browse files
author
Victor Chaptsev
committed
feat: VERSION 2.0.0
1 parent 8c5559b commit 58fb3ed

File tree

97 files changed

+1498
-930
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+1498
-930
lines changed

README.md

+29-9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
<a href="https://travis-ci.org/vchaptsev/cookiecutter-django-vue">
2+
<img src="https://travis-ci.org/vchaptsev/cookiecutter-django-vue.svg?branch=master" />
3+
</a>
4+
15
Cookiecutter Django-Vue
26
=======================
37

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

11-
1215
Features
1316
--------
1417

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

2326
Optional Integrations
2427
---------------------
@@ -27,7 +30,9 @@ Optional Integrations
2730

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

3237
Usage
3338
-----
@@ -45,24 +50,33 @@ will be created for you.
4550

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

48-
======================= GENERAL ====================== [ ]:
53+
======================== INFO ======================= [ ]:
4954
project_name [Project Name]: Website
5055
project_slug [website]: website
5156
description [Short description]: My awesome website
5257
author [Your Name]: Your Name
5358
54-
======================= DEVOPS ======================= [ ]:
59+
====================== GENERAL ====================== [ ]:
60+
Select api:
61+
1 - REST
62+
2 - GraphQL
63+
Choose from 1, 2 [1]: 2
64+
backups [y]: y
65+
==================== INTEGRATIONS =================== [ ]:
5566
use_sentry [y]: y
56-
======================= BACKEND ====================== [ ]:
67+
use_portainer [y]: y
5768
use_mailhog [y]: y
58-
custom_user [n]: n
59-
======================= FRONTEND ===================== [ ]:
6069
Select analytics:
6170
1 - Google Analytics
6271
2 - Yandex Metrika
6372
3 - None
6473
Choose from 1, 2, 3 [1]: 2
6574

75+
Project creation will cause some odd newlines and linter errors, so I'd recommend:
76+
77+
$ autopep8 -r --in-place --aggressive --aggressive .
78+
$ npm run lint --fix
79+
6680
Now you can start project with
6781
[docker-compose](https://docs.docker.com/compose/):
6882

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

7488
$ docker-compose -f docker-compose-prod.yml up --build -d
89+
90+
91+
Contributing
92+
------------
93+
94+
Help and feedback are welcome :)

cookiecutter.json

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"======================= GENERAL ======================": " ",
2+
"======================== INFO =======================": " ",
33
"project_name": "Project Name",
44
"project_slug": "{{ cookiecutter.project_name.lower()|replace(' ', '_')|replace('-', '_') }}",
55
"domain": "{{ cookiecutter.project_slug }}.com",
@@ -8,14 +8,13 @@
88
"author": "Your Name",
99
"email": "admin@{{ cookiecutter.domain }}",
1010

11-
"======================= DEVOPS =======================": " ",
12-
"use_travis": "y",
11+
"====================== GENERAL ======================": " ",
12+
"api": ["REST", "GraphQL"],
13+
"backups": "y",
14+
15+
"==================== INTEGRATIONS ===================": " ",
1316
"use_sentry": "y",
14-
15-
"======================= BACKEND ======================": " ",
17+
"use_portainer": "y",
1618
"use_mailhog": "y",
17-
"custom_user": "n",
18-
19-
"======================= FRONTEND =====================": " ",
20-
"analytics": ["Google Analytics", "Yandex Metrika", "None"],
19+
"analytics": ["Google Analytics", "Yandex Metrika", "None"]
2120
}

hooks/post_gen_project.py

+28-19
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
1. Generates and saves random secret key
33
2. Renames env.example to .env
4-
3. Removes users app if it isn't going to be used
4+
3. Deletes unused API files
55
"""
66
import os
77
import random
@@ -12,38 +12,47 @@
1212
PROJECT_DIRECTORY = os.path.realpath(os.path.curdir)
1313

1414

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

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

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

2828

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

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

38-
for filename in ['modules/auth.js', 'services/users.js']:
39-
os.remove(os.path.join(PROJECT_DIRECTORY, '{{ cookiecutter.project_slug }}/static/store/' + filename))
40-
41-
# Removes users app if it isn't going to be used
42-
if '{{ cookiecutter.custom_user }}' == 'n':
43-
remove_users_app()
44-
45-
# Generates and saves random secret key
46-
set_secret_key(os.path.join(PROJECT_DIRECTORY, 'env.example')) # env file
47-
48-
# Renames env file
34+
def delete_api_files():
35+
""" Deletes unused API files """
36+
if '{{ cookiecutter.api }}' == 'REST':
37+
files = [
38+
'.graphqlrc',
39+
'backend/config/schema.py',
40+
'backend/apps/users/schema.py',
41+
'frontend/src/apollo.js',
42+
]
43+
shutil.rmtree(os.path.join(PROJECT_DIRECTORY, 'frontend/src/graphql'))
44+
else:
45+
files = [
46+
'backend/config/api.py',
47+
'backend/apps/users/views.py',
48+
'backend/apps/users/serializers.py',
49+
]
50+
shutil.rmtree(os.path.join(PROJECT_DIRECTORY, 'frontend/src/store'))
51+
52+
for filename in files:
53+
os.remove(os.path.join(PROJECT_DIRECTORY, filename))
54+
55+
56+
set_secret_key()
4957
rename_env_file()
58+
delete_api_files()

tests/test_docker.sh

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#!/bin/sh
22

33
# install test requirements
4-
pip install pipenv
5-
pipenv install --system
4+
pip install -r requirements.txt
65

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

14-
# run the project's tests
15-
docker-compose run backend py.test
13+
docker-compose run backend python manage.py check
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
root = true
2+
3+
[*]
4+
indent_size = 2
5+
charset = utf-8
6+
end_of_line = lf
7+
indent_style = space
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.py]
12+
indent_size = 4
13+
max_line_length = 120
+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
### OSX ###
2+
.DS_Store
3+
.AppleDouble
4+
.LSOverride
5+
6+
### SublimeText ###
7+
# cache files for sublime text
8+
*.tmlanguage.cache
9+
*.tmPreferences.cache
10+
*.stTheme.cache
11+
12+
*.sublime-project
13+
*.sublime-workspace
14+
15+
# sftp configuration file
16+
sftp-config.json
17+
18+
# Basics
19+
*.py[cod]
20+
__pycache__
21+
22+
# Logs
23+
logs
24+
*.log
25+
pip-log.txt
26+
npm-debug.log*
27+
yarn-debug.log*
28+
yarn-error.log*
29+
30+
# Unit test / coverage reports
31+
.coverage
32+
.tox
33+
nosetests.xml
34+
htmlcov
35+
36+
# Translations
37+
*.mo
38+
*.pot
39+
40+
# Webpack
41+
webpack-stats.json
42+
dist/
43+
44+
# Vim
45+
*~
46+
*.swp
47+
*.swo
48+
49+
# npm
50+
node_modules
51+
52+
# Compass
53+
.sass-cache
54+
55+
# User-uploaded media
56+
media/
57+
58+
# Collected staticfiles
59+
*/staticfiles/
60+
61+
.cache/
62+
**/certs
63+
64+
# Editor directories and files
65+
.idea
66+
.vscode
67+
*.suo
68+
*.ntvs*
69+
*.njsproj
70+
*.sln
71+
*.sw*
72+
73+
# VS code
74+
.vscode
75+
.pythonconfig
76+
77+
# Venv
78+
venv
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"request": {
3+
"url": "http://localhost:8000/graphql"
4+
}
5+
}

{{cookiecutter.project_slug}}/README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33

44
{{cookiecutter.description}}
55

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

10-
{% endif %}
10+
11+
## Development
12+
+ run `docker-compose up --build`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM python:3.6
2+
3+
# python envs
4+
ENV PYTHONFAULTHANDLER=1 \
5+
PYTHONUNBUFFERED=1 \
6+
PYTHONHASHSEED=random \
7+
PIP_NO_CACHE_DIR=off \
8+
PIP_DISABLE_PIP_VERSION_CHECK=on \
9+
PIP_DEFAULT_TIMEOUT=100
10+
11+
# python dependencies
12+
COPY ./requirements.txt /
13+
RUN pip install -r ./requirements.txt
14+
15+
# upload scripts
16+
COPY ./scripts/entrypoint.sh ./scripts/start.sh ./scripts/gunicorn.sh /
17+
18+
WORKDIR /app
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
__version__ = '0.1.0'
2-
__version_info__ = tuple([int(num) if num.isdigit() else num for num in __version__.replace('-', '.', 1).split('.')])

{{cookiecutter.project_slug}}/backend/users/admin.py renamed to {{cookiecutter.project_slug}}/backend/apps/users/admin.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
from django.contrib.auth.models import Group
33
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
44

5-
from .models import User
6-
from .forms import UserChangeForm, UserCreationForm
5+
from apps.users.models import User
6+
from apps.users.forms import UserChangeForm, UserCreationForm
77

88

99
class UserAdmin(BaseUserAdmin):
@@ -18,13 +18,13 @@ class UserAdmin(BaseUserAdmin):
1818
['Auth', {'fields': ['email', 'password']}],
1919
['Personal info', {'fields': ['last_name', 'first_name', 'avatar']}],
2020
['Settings', {'fields': ['groups', 'is_admin', 'is_active', 'is_staff', 'is_superuser']}],
21-
['Important dates', {'fields': ['last_login', 'registered_at']}]
21+
['Important dates', {'fields': ['last_login', 'registered_at']}],
2222
]
2323
# add_fieldsets is not a standard ModelAdmin attribute. UserAdmin
2424
# overrides get_fieldsets to use this attribute when creating a user.
2525
add_fieldsets = [
2626
[None, {'classes': ['wide'],
27-
'fields': ['email', 'first_name', 'last_name', 'password1', 'password2']}]
27+
'fields': ['email', 'first_name', 'last_name', 'password1', 'password2']}],
2828
]
2929
search_fields = ['email']
3030
ordering = ['email']

{{cookiecutter.project_slug}}/backend/users/apps.py renamed to {{cookiecutter.project_slug}}/backend/apps/users/apps.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33

44
class UsersConfig(AppConfig):
5-
name = '{{cookiecutter.project_slug}}.users'
5+
name = 'apps.users'
66
verbose_name = 'Users'

0 commit comments

Comments
 (0)