Проект "Карта ДТП" (https://dtp-stat.ru)
Обсуждение проекта - https://t.me/crash_map
- Python >=3.6
- Postgresql >=10.6
- Nodejs (npm)
- Install node packages
$ npm install -g npx
$ npm install- Install python dependencies
pip install -r requirements.txt- Start postgresql server.
- Create appropriate database and role:
$ psql -c "CREATE DATABASE django;" -U postgres
$ psql -c "CREATE ROLE django WITH LOGIN PASSWORD 'django';" -U postgres
$ psql -c "ALTER ROLE django CREATEDB;" -U postgres
$ psql -c "GRANT ALL PRIVILEGES ON DATABASE django TO django;" -U postgres- Export
DATABASE_URL(used by app for database connection) andDEBUGenvironment variable with database info according to previous steps:
$ export DATABASE_URL="postgres://django:django@localhost:5432/django"
$ export DEBUG=true- Perform migrations:
$ ./manage.py makemigrations --noinput
$ ./manage.py migrate --noinput- Create
default_cachecache table:
$ ./manage.py createcachetable- It`s time to start app:
$ ./manage.py runserver localhost:8000Authorize on http://127.0.0.1:8000/admin1.
- You need to run
npm starttogether with app to generate JavaScript-code:
npm start- docker
- docker-compose
- docker-machine (for win & mac)
Project configured by .dockerenv file in docker folder.
Rename docker/.dockerenv.example to docker/.dockerenv and set variables:
SECRET_KEY, - secret key, you can generate it with:- Secret key generator (recomended length: 50 symbols)
- oneliner:
python3 -c "import random, string; print('SECRET_KEY=\"%s\"'%''.join([random.SystemRandom().choice(\"{}{}{}\".format(string.ascii_letters, string.digits, string.punctuation)) for i in range(63)]))"DEBUG, - set it totrue
- Build and up containers:
docker-compose up -d --build - First time need create superuser
Run this and follow instructions:
$ docker-compose exec app ./manage.py createsuperuser --email admin@localhost --username admin- Authorize on http://127.0.0.1:8000/admin1.
Загрузить в базу техническую информацию (названия разделов)
$ ./parser.py tech_dataЗагрузить в базу регионы и районы
$ ./parser.py get_regionsЗагрузить в базу все ДТП. Для этого нужно предварительно скачать дамп всех ДТП и положить в папку data - https://drive.google.com/file/d/1aUTPLqUX5xZhmtcFODyVb7GpBj3_SHui/view?usp=sharing
$ ./parser.py get_dtpЧтобы включить отображение региона нужно в базе данных поставить ему status = True.
Запустите эту команду перед развертыванием для генерации JavaScript кода:
$ npm run build-productionЕсли не хочется выкачивать все данные - вот бекап базы https://drive.google.com/open?id=1SPHyY-802U-USRQh3j4JfzhIO86eAaUp
- Скопировать
dtpmap/.env.tmpl -> dtpmap/.env - Отредактировать
dtpmap/.env
(самый простой способ)
- Ставите Node.js https://nodejs.org/en/
- Ставите yarn https://yarnpkg.com/en/docs/install
- В корне проекта выполняете
yarnи затемyarn start
Выполнить manage.py runserver 8000