Giter Club home page Giter Club logo

django-service-boilerplate's Introduction

CircleCI

HowTo Use

Backend requirements:

  1. install pip -- https://pip.pypa.io/en/stable/installing/#installation
  2. install virtualenv -- https://virtualenv.pypa.io/en/stable/installation/#installation
  3. install virtualenvwrapper -- https://virtualenvwrapper.readthedocs.io/en/latest/install.html#installation (pip install virtualenvwrapper)
  4. install and run PostgreSQL and Redis
  5. install PhantomJS selenium driver (if you want to run selenium tests)

Ubuntu OS:

  1. install libcurl4-openssl-dev -- https://packages.ubuntu.com/xenial/libcurl4-openssl-dev (sudo apt-get install libcurl4-openssl-dev)
  2. install zlib1g-dev -- https://packages.ubuntu.com/ru/xenial/zlib1g-dev (sudo apt-get install zlib1g-dev)
  3. install postgis -- http://postgis.net/install/ (sudo apt-get install postgis)
  4. install libgdal-dev -- https://packages.ubuntu.com/xenial/libgdal-dev (sudo apt-get install libgdal-dev)
  5. install gdal -- https://pypi.python.org/pypi/GDAL (pip install gdal)

Create new project, virtualenv and install requirements:

git clone [email protected]:pik-software/<repo>.git <project-name>
cd <project-name>
mkvirtualenv --python=$(which python3.6) <project-name>
pip install -r requirements.txt  # install python requirements

Create file settings_local.py in _project_ and setup DATABASE and some local settings:

  DEBUG = True
  SECRET_KEY = '0n-w7wsf^3-ehi^!@m2fayppf7cc3k4j5$2($59ai*5whm^l7k'
  DATABASES = {
      'default': {
          'ENGINE': 'django.contrib.gis.db.backends.postgis',
          'NAME': '<project-name>',
          'USER': 'postgres',
          'PASSWORD': 'postgres',
          'HOST': 'localhost',
          'PORT': '5432'
      }
  }

Create and migrate database:

createdb <project-name>  # create postgres database
(OR sudo su postgres -c "createdb <project-name>")
python manage.py migrate

Run dev server:

python manage.py runserver

Database transfer with dumpfile:

# The command for create dumpfile (on localhost)
pg_dump -d <project-name> -h localhost -U postgres -W -Fc -x -O > dump.dmp

# The command for restore dump from file (on server)
pg_restore dump.dmp

Run tests:

# Execute tests with predefined `test.ini` project settings

pytest

# WARNING! By default `--reuse-db` is on, it means that test database is 
# saved between test sessions. To override this behaviour or in case of 
# problems like "Permission already exists" or similar, use `--create-db` 
# option for db recreation forcing.

pytest --create-db

ENVIRONMENTS

CELERY_WORKER_CONCURRENCY -- celery worker concurrency info

lib.codegen

Help you to generate django models by OpenAPI Swagger schema.

  1. Add lib.codegen to INSTALLED_APPS

  2. run python manage.py schema_to_models ./app.schema.json app_name command

integration

Known issues:

  • By default boolean API field transforms into BooleanField with null=True. This behavior follows recommendation to Django >= 2.1. However this flag is not supported in early versions and BooleanField should be overridden by NullBoleanField in generated models.py module.
  • If target API endpoint have updated field, you mast ensure that ordering is supported for this field.
  • You mast put related model before original. If one have link e.g Category should be placed before Contact.
#!/bin/bash

# 0. prepare settings
INTEGRA_BASE_URL="http://127.0.0.1:8000"
INTEGRA_SCHEMA_PATH="schema.json"
INTEGRA_APP_NAME="contacts_replica1"

# 1. create login/pass API user
AUTH="api-reader:MyPass39dza2es"

# 2. download swagger `curl`
curl -u "${AUTH}" "${INTEGRA_BASE_URL}/api/v1/schema/?format=openapi" -o "${INTEGRA_SCHEMA_PATH}"

# 3. generate integration app
python manage.py schema_to_models "${INTEGRA_SCHEMA_PATH}" "${INTEGRA_APP_NAME}" --options '{"skip_models":["HistoricalComment","HistoricalContact","User"],"skip_fields":["_type"]}'

echo Add "${INTEGRA_APP_NAME}" to INSTALLED_APPS
echo
echo Setup integration settings like:
echo
echo "INTEGRA_CONFIGS = [                                        "
echo "    ...                                                    "
echo "    {                                                      "
echo "        'base_url': '${INTEGRA_BASE_URL}',                 "
echo "        'request': {                                       "
echo "            'auth': '${AUTH}',                             "
echo "        },                                                 "
echo "        'models': [                                        "
echo "            {'url': '/api/v1/<model>-list/',               "
echo "             'app': '${INTEGRA_APP_NAME}',                 "
echo "             'model': '<model>'},                          "
echo "            ...                                            "
echo "        ],                                                 "
echo "    }                                                      "
echo "    ...                                                    "
echo "]                                                          "
echo
echo Run: python manage.py makemigrations "${INTEGRA_APP_NAME}"
echo Run: python manage.py migrate
echo Setup: CELERY_BEAT_SCHEDULE in settings

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.