项目作者: vbyazilim

项目描述 :
Create custom Django project layout
高级语言: Python
项目地址: git://github.com/vbyazilim/django-vb-admin.git
创建时间: 2019-08-07T09:37:13Z
项目社区:https://github.com/vbyazilim/django-vb-admin

开源协议:MIT License

下载


Python
Django
Version
Codacy Badge
Code style: black
Downloads

django-vb-admin

Creates custom Django project layout. Compatible with Django 2.2.8 and
requires Python 3.7.x. By default, project uses PostgreSQL,
this means you need to install :) macOS users can install via brew install postgres

Installation

Let’s create PostgreSQL database first:

  1. $ createdb -E UTF8 -T template0 my_project_dev # create your database
  2. $ createdb -E UTF8 -T template0 --lc-collate=tr_TR.UTF-8 --lc-ctype=tr_TR.UTF-8 my_project_dev # or create your database with Turkish locale support

Now, install package:

  1. $ pip install django-vb-admin

This package heavily depends on django-vb-baseapp.
All the rake tasks are related to django-vb-baseapp. You don’t need to do
anything, django-vb-admin installs required packages automatically.

Usage

After installation, you’ll have a command: django-vb-admin

  1. $ django-vb-admin -h
  2. usage: django-vb-admin [-h] [-t TARGET] [-v {0,1}] [--version]
  3. [{startproject}]
  4. Create new Django project
  5. positional arguments:
  6. {startproject} Name of command(s)
  7. optional arguments:
  8. -h, --help show this help message and exit
  9. -t TARGET, --target TARGET
  10. Target path
  11. -v {0,1}, --verbosity {0,1}
  12. Verbose mode
  13. --version show program's version number and exit

Let’s create project:

  1. $ mkdir /path/to/my-django-project/
  2. $ cd /path/to/my-django-project
  3. $ django-vb-admin startproject # create structure to current working directory
  4. # or
  5. $ django-vb-admin startproject --target="/path/to/folder" # create structure to given path

When creation completed, you can create your virtual environment and set your
environment variables:

  1. export DJANGO_SECRET=$(head -c 75 /dev/random | base64 | tr -dc 'a-zA-Z0-9' | head -c 50)
  2. export DATABASE_URL="postgres://localhost:5432/my_project_dev"

then;

  1. $ pip install -r requirements/development.pip

Directory structure:

  1. .
  2. ├── applications
  3. ├── config
  4. ├── settings
  5. ├── __init__.py
  6. ├── base.py
  7. ├── development.example.py
  8. ├── heroku.py
  9. ├── production.py
  10. └── test.example.py
  11. ├── __init__.py
  12. ├── urls.py
  13. └── wsgi.py
  14. ├── locale
  15. └── tr
  16. └── LC_MESSAGES
  17. ├── django.mo
  18. └── django.po
  19. ├── requirements
  20. ├── base.pip
  21. ├── development.pip
  22. ├── heroku.pip
  23. └── production.pip
  24. ├── static
  25. ├── css
  26. ├── application.css
  27. └── bulma.min.X.X.X.css
  28. ├── images
  29. └── .gitkeep
  30. └── js
  31. ├── .gitkeep
  32. ├── application.js
  33. └── fontawesome.X.X.X.all.js
  34. ├── templates
  35. ├── admin
  36. └── base_site.html
  37. ├── custom_errors
  38. ├── 400.html
  39. ├── 403.html
  40. ├── 404.html
  41. └── 500.html
  42. └── base.html
  43. ├── .bandit
  44. ├── .flake8
  45. ├── .gitignore
  46. ├── .isort.cfg
  47. ├── .pylintrc
  48. ├── .python-version
  49. ├── .ruby-version
  50. ├── .tm_properties
  51. ├── Procfile
  52. ├── manage.py
  53. ├── pyproject.toml
  54. ├── requirements.txt
  55. └── runtime.txt

Now you can init git:

  1. $ cd /path/to/my-django-project/
  2. $ git init

Packages

Common packages: requirements/base.pip

  1. Django==2.2.8
  2. Pillow==6.2.1
  3. django-extensions==2.2.5
  4. python-slugify==4.0.0
  5. psycopg2-binary==2.8.4
  6. dj-database-url==0.5.0
  7. django-vb-baseapp
  8. vb-console

Development packages: requirements/development.pip

  1. -r base.pip
  2. ipython==7.10.0
  3. ipdb==0.12.3
  4. prompt-toolkit==2.0.10
  5. bpython==0.18
  6. ptpython==2.0.6
  7. Werkzeug==0.16.0
  8. django-debug-toolbar==2.1
  9. coverage==4.5.4
  10. isort==4.3.21
  11. black==19.10b0
  12. flake8==3.7.9
  13. flake8-bandit==2.1.2
  14. flake8-blind-except==0.1.1
  15. flake8-bugbear==19.8.0
  16. flake8-builtins==1.4.1
  17. flake8-polyfill==1.0.2
  18. flake8-print==3.1.4
  19. flake8-quotes==2.1.1
  20. flake8-string-format==0.2.3
  21. pylint==2.4.4

Note: Package order is important here. Due to prompt-toolkit dependency
on ipdb and ptpython, we need to install specific version: prompt-toolkit==2.0.10
in the given order. Packages are test on Python 3.8.0 environment and had
issues with ipdb, ipython and other repls.

Heroku related packages: requirements/heroku.pip

  1. -r base.pip
  2. gunicorn==20.0.4
  3. whitenoise==4.1.4
  4. boto3==1.10.33
  5. django-storages==1.8

Built-in support for AWS-S3 Storage. You need to create/get your:

  • S3_ACCESS_KEY_ID
  • S3_SECRET_ACCESS_KEY

and set those variables on Heroku. Please check config/settings/heroku.py
for more details. Basic Heroku setup:

  1. $ heroku login
  2. $ heroku apps:create
  3. $ heroku addons:create heroku-postgresql:hobby-dev
  4. $ heroku config:set DJANGO_ENV="heroku"
  5. $ heroku config:set DJANGO_SECRET='YOUR_GENERATED_RANDOM_SECRET'
  6. $ heroku config:set S3_ACCESS_KEY_ID='YOUR_S3_ACCESS_KEY_ID'
  7. $ heroku config:set S3_SECRET_ACCESS_KEY='YOUR_S3_SECRET_ACCESS_KEY'
  8. $ heroku config:set S3_BUCKET_NAME='YOUR_S3_BUCKET_NAME'
  9. $ heroku config:set WEB_CONCURRENCY=3
  10. $ git push heroku master
  11. $ heroku run python manage.py migrate
  12. $ heroku run python manage.py createsuperuser

If you want to use email reporter for Django errors, you need to set couple
more environment variables on Heroku side too.

Linux/Production packages: requirements/production.pip

  1. -r base.pip
  2. uWSGI==2.0.18

Rakefile

If you have Ruby installed on your system (if you are on macOS you’ll have it by default)
you can easily automate your basic operations. Run rake -T for listing
available tasks:

  1. $ rake -T
  2. rake db:migrate[database] # Run migration for given database (default: 'default')
  3. rake db:roll_back[name_of_application,name_of_migration] # Roll-back (name of application, name of migration)
  4. rake db:shell # run database shell ..
  5. rake db:show[name_of_application] # Show migrations for an application (default: 'all')
  6. rake db:update[name_of_application,name_of_migration,is_empty] # Update migration (name of application, name of migration?, is empty?)
  7. rake default # Default task: runserver_plus (Werkzeug)
  8. rake locale:compile # Compile locale dictionary
  9. rake locale:update # Update locale dictionary
  10. rake new:application[name_of_application] # Create new Django application
  11. rake new:model[name_of_application,name_of_model,type_of_model] # Create new Model for given application: django,basemodel,softdelete
  12. rake runserver:default # Run: runserver (Django's default server)
  13. rake runserver:default_ipdb # Run: runserver (Django's default server) + ipdb debug support
  14. rake runserver:plus # Run: runserver_plus (Werkzeug)
  15. rake runserver:plus_ipdb # Run: runserver_plus (Werkzeug) + ipdb debug support
  16. rake shell[repl] # Run shell+ avail: ptpython,ipython,bpython default: ptpython
  17. rake test:browse_coverage[port] # Browse test coverage
  18. rake test:coverage[cli_args] # Show test coverage (default: '--show-missing --ignore-errors --skip-covered')
  19. rake test:run[name_of_application,verbose] # Run tests for given application

Rake tasks are the wrapper for Django’s management commands. Mostly related
to django-vb-baseapp application. Please checkout https://github.com/vbyazilim/django-vb-baseapp
for more detail and examples. django-vb-baseapp has lot of features :)


License

This project is licensed under MIT


Contributer(s)


Contribute

All PR’s are welcome!

  1. fork (https://github.com/vbyazilim/django-vb-admin/fork)
  2. Create your branch (git checkout -b my-features)
  3. commit yours (git commit -am 'Add awesome feature')
  4. push your branch (git push origin my-features)
  5. Than create a new Pull Request!

Change Log

2019-12-08

  • Drop Python 3.8.0 support
  • Fix repls and debug related issues
  • Bump version

2019-12-05

  • Upgrade packages, now using Django 2.2.8
  • Python 3.8.0 support
  • Add new rake tasks
  • Fix development.pip package installation order
  • Bump version

2019-10-20

  • Add current git tag and python version information indicator to django-admin index
  • Add django-vb-baseapp as package dependency
  • Upgrade python packages
  • Add templates/base.html using Bulma.io 0.8.0
  • Bump version: 1.0.13

2019-09-19

  • Add Codacy integration
  • Add setup completed message

2019-08-12

  • Add templates/base.html using Bulma.io 0.7.5
  • Add templates/admin/ for base admin site.
  • Add static/js/application.js
  • Add global locale path
  • Bump version: 1.0.4
  • Bump version: 1.0.5 (Fix README file)

2019-08-07

  • Add --version option, version bump to 1.0.3
  • Bump version: 1.0.2
  • Add Rake tasks
  • Fix MAFIFEST.in file
  • Initial Beta relase: 1.0.0