Merge pull request #8 from jedie/import-export

Import export
pull/9/head
Jens Diemer 2020-10-24 16:56:15 +02:00 zatwierdzone przez GitHub
commit d1bf6f25d6
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
12 zmienionych plików z 84 dodań i 15 usunięć

4
.gitignore vendored
Wyświetl plik

@ -8,6 +8,10 @@
!/.style.yapf !/.style.yapf
!.coveralls.yml !.coveralls.yml
# for django-dbbackup
/backups/
!/backups/.gitkeep
# from test projects: # from test projects:
/static/ /static/
/media/ /media/

Wyświetl plik

@ -1,9 +1,10 @@
FROM python:3.7-slim-buster FROM python:3.9-slim-buster
# https://hub.docker.com/_/python
# Install deps # Install deps
RUN apt-get update \ RUN apt-get update \
&& apt-mark auto $(apt-mark showinstall) \ && apt-mark auto $(apt-mark showinstall) \
&& apt-get install -y python3-pip \ && apt-get install -y postgresql-client-11 python3-pip \
&& apt autoremove \ && apt autoremove \
&& apt -y full-upgrade \ && apt -y full-upgrade \
&& rm -rf /var/lib/apt \ && rm -rf /var/lib/apt \

Wyświetl plik

@ -1,15 +1,13 @@
SHELL := /bin/bash SHELL := /bin/bash
MAX_LINE_LENGTH := 119 MAX_LINE_LENGTH := 119
POETRY_VERSION := $(shell poetry --version 2>/dev/null)
COMPOSE_VERSION := $(shell poetry run docker-compose --version 2>/dev/null)
help: ## List all commands help: ## List all commands
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z0-9 -]+:.*?## / {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z0-9 -]+:.*?## / {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
check-poetry: check-poetry:
@if [[ "${POETRY_VERSION}" == *"Poetry"* ]] ; \ @if [[ "$(shell poetry --version 2>/dev/null)" == *"Poetry"* ]] ; \
then \ then \
echo "Found ${POETRY_VERSION}, ok." ; \ echo "Poetry found, ok." ; \
else \ else \
echo 'Please install poetry first, with e.g.:' ; \ echo 'Please install poetry first, with e.g.:' ; \
echo 'make install-poetry' ; \ echo 'make install-poetry' ; \
@ -17,9 +15,9 @@ check-poetry:
fi fi
install-poetry: ## install or update poetry install-poetry: ## install or update poetry
@if [[ "${POETRY_VERSION}" == *"Poetry"* ]] ; \ @if [[ "$(shell poetry --version 2>/dev/null)" == *"Poetry"* ]] ; \
then \ then \
echo 'Update poetry v$(POETRY_VERSION)' ; \ echo 'Update poetry' ; \
poetry self update ; \ poetry self update ; \
else \ else \
echo 'Install poetry' ; \ echo 'Install poetry' ; \
@ -96,9 +94,9 @@ create-starter: ## Create starter file.
check-compose: check-compose:
@if [[ "${COMPOSE_VERSION}" == *"docker-compose version"* ]] ; \ @if [[ "$(shell poetry run docker-compose --version 2>/dev/null)" = *"docker-compose version"* ]] ; \
then \ then \
echo "Found ${COMPOSE_VERSION}, ok." ; \ echo "docker-compose found, ok." ; \
else \ else \
echo 'Please install extras first, with e.g.:' ; \ echo 'Please install extras first, with e.g.:' ; \
echo 'make install-compose' ; \ echo 'make install-compose' ; \
@ -148,6 +146,20 @@ logs_inventory: ## Display docker logs from postgres container
############################################################################## ##############################################################################
dbbackup: ## Backup database
./manage.sh dbbackup
docker_dbbackup: ## Backup database (Docker usage)
./compose.sh exec inventory ./manage.sh dbbackup
dbrestore: ## Restore a database backup
./manage.sh dbrestore
docker_dbrestore: ## Restore a database backup (Docker usage)
./compose.sh exec inventory ./manage.sh dbrestore
##############################################################################
restart: down up ## Restart all containers restart: down up ## Restart all containers
upgrade_inventory: ## Upgrade "inventory" container and restart it upgrade_inventory: ## Upgrade "inventory" container and restart it

Wyświetl plik

@ -75,6 +75,9 @@ up Start containers via docker-compose
down Stop all containers down Stop all containers
prune Cleanup docker prune Cleanup docker
build Update docker container build build Update docker container build
logs Display docker logs from all containers
dbbackup Backup database
dbrestore Restore a database backup
restart Restart all containers restart Restart all containers
}}} }}}
@ -108,6 +111,8 @@ ENABLE_DJDT=1
~/PyInventory$ make run-dev-server ~/PyInventory$ make run-dev-server
}}} }}}
The web page is available via: {{{http://127.0.0.1:8000/}}}
=== docker-compose usage === docker-compose usage

Wyświetl plik

@ -112,6 +112,9 @@ prepare
down Stop all containers down Stop all containers
prune Cleanup docker prune Cleanup docker
build Update docker container build build Update docker container build
logs Display docker logs from all containers
dbbackup Backup database
dbrestore Restore a database backup
restart Restart all containers restart Restart all containers
.env .env
@ -145,6 +148,8 @@ local install without docker
# start local dev. web server: # start local dev. web server:
~/PyInventory$ make run-dev-server ~/PyInventory$ make run-dev-server
The web page is available via: ``http://127.0.0.1:8000/``
docker-compose usage docker-compose usage
==================== ====================
@ -241,4 +246,4 @@ donation
------------ ------------
``Note: this file is generated from README.creole 2020-10-24 14:14:38 with "python-creole"`` ``Note: this file is generated from README.creole 2020-10-24 16:39:24 with "python-creole"``

Wyświetl plik

@ -25,7 +25,7 @@ services:
postgres: postgres:
# https://hub.docker.com/_/postgres # https://hub.docker.com/_/postgres
image: postgres:13-alpine image: postgres:11-alpine
restart: "no" restart: "no"
hostname: postgres hostname: postgres
ports: ports:

Wyświetl plik

@ -21,6 +21,8 @@ echo "$(date +%c) - ${0}"
( (
set -x set -x
poetry install --extras "postgres"
./manage.sh collectstatic --noinput --link ./manage.sh collectstatic --noinput --link
./manage.sh makemigrations ./manage.sh makemigrations
./manage.sh migrate ./manage.sh migrate

Wyświetl plik

@ -2,6 +2,8 @@ import tagulous
from adminsortable2.admin import SortableInlineAdminMixin from adminsortable2.admin import SortableInlineAdminMixin
from django.contrib import admin from django.contrib import admin
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from import_export.admin import ImportExportMixin
from import_export.resources import ModelResource
from inventory.admin.base import BaseUserAdmin from inventory.admin.base import BaseUserAdmin
from inventory.models import ItemLinkModel, ItemModel from inventory.models import ItemLinkModel, ItemModel
@ -12,8 +14,14 @@ class ItemLinkModelInline(SortableInlineAdminMixin, admin.TabularInline):
extra = 1 extra = 1
class ItemModelResource(ModelResource):
class Meta:
model = ItemModel
@admin.register(ItemModel) @admin.register(ItemModel)
class ItemModelAdmin(BaseUserAdmin): class ItemModelAdmin(ImportExportMixin, BaseUserAdmin):
date_hierarchy = 'create_dt' date_hierarchy = 'create_dt'
list_display = ( list_display = (
'kind', 'producer', 'kind', 'producer',

Wyświetl plik

@ -1,9 +1,17 @@
from django.contrib import admin from django.contrib import admin
from import_export.admin import ImportExportMixin
from import_export.resources import ModelResource
from inventory.admin.base import BaseUserAdmin from inventory.admin.base import BaseUserAdmin
from inventory.models import LocationModel from inventory.models import LocationModel
class LocationModelResource(ModelResource):
class Meta:
model = LocationModel
@admin.register(LocationModel) @admin.register(LocationModel)
class LocationModelAdmin(BaseUserAdmin): class LocationModelAdmin(ImportExportMixin, BaseUserAdmin):
pass pass

Wyświetl plik

@ -39,6 +39,7 @@ INSTALLED_APPS = [
'bx_py_utils', # https://github.com/boxine/bx_py_utils 'bx_py_utils', # https://github.com/boxine/bx_py_utils
'import_export', # https://github.com/django-import-export/django-import-export 'import_export', # https://github.com/django-import-export/django-import-export
'dbbackup', # https://github.com/django-dbbackup/django-dbbackup
'ckeditor', # https://github.com/django-ckeditor/django-ckeditor 'ckeditor', # https://github.com/django-ckeditor/django-ckeditor
'reversion', # https://github.com/etianen/django-reversion 'reversion', # https://github.com/etianen/django-reversion
'reversion_compare', # https://github.com/jedie/django-reversion-compare 'reversion_compare', # https://github.com/jedie/django-reversion-compare
@ -142,6 +143,12 @@ STATIC_ROOT = str(__Path(BASE_PATH, 'static'))
MEDIA_URL = '/media/' MEDIA_URL = '/media/'
MEDIA_ROOT = str(__Path(BASE_PATH, 'media')) MEDIA_ROOT = str(__Path(BASE_PATH, 'media'))
# _____________________________________________________________________________
# Django-dbbackup
DBBACKUP_STORAGE = 'django.core.files.storage.FileSystemStorage'
DBBACKUP_STORAGE_OPTIONS = {'location': str(__Path(BASE_PATH, 'backups'))}
# _____________________________________________________________________________ # _____________________________________________________________________________
# Django-Debug-Toolbar # Django-Debug-Toolbar

18
poetry.lock wygenerowano
Wyświetl plik

@ -258,6 +258,19 @@ python-versions = "*"
[package.dependencies] [package.dependencies]
django-js-asset = ">=1.2.2" django-js-asset = ">=1.2.2"
[[package]]
name = "django-dbbackup"
version = "3.3.0"
description = "Management commands to help backup and restore a project database and media"
category = "main"
optional = false
python-versions = "*"
[package.dependencies]
Django = ">=1.5"
pytz = "*"
six = "*"
[[package]] [[package]]
name = "django-debug-toolbar" name = "django-debug-toolbar"
version = "3.1.1" version = "3.1.1"
@ -1178,7 +1191,7 @@ postgres = ["psycopg2-binary"]
[metadata] [metadata]
lock-version = "1.1" lock-version = "1.1"
python-versions = ">=3.7,<4.0.0" python-versions = ">=3.7,<4.0.0"
content-hash = "4ad32caba18b4f973eee3d59a129b1ccd5750289a60c07939e1ab2f973fb4940" content-hash = "d07f05b3cb200bb30974923869838af5e96a1935fdcbaa2e536f03f046583d90"
[metadata.files] [metadata.files]
appdirs = [ appdirs = [
@ -1365,6 +1378,9 @@ django-ckeditor = [
{file = "django-ckeditor-6.0.0.tar.gz", hash = "sha256:29fd1a333cb9741ac2c3fd4e427a5c00115ed33a2389716a09af7656022dcdde"}, {file = "django-ckeditor-6.0.0.tar.gz", hash = "sha256:29fd1a333cb9741ac2c3fd4e427a5c00115ed33a2389716a09af7656022dcdde"},
{file = "django_ckeditor-6.0.0-py2.py3-none-any.whl", hash = "sha256:cc2d377f1bdcd4ca1540caeebe85f7e2cd006198d57328ef6c718d3eaa5a0846"}, {file = "django_ckeditor-6.0.0-py2.py3-none-any.whl", hash = "sha256:cc2d377f1bdcd4ca1540caeebe85f7e2cd006198d57328ef6c718d3eaa5a0846"},
] ]
django-dbbackup = [
{file = "django-dbbackup-3.3.0.tar.gz", hash = "sha256:bb109735cae98b64ad084e5b461b7aca2d7b39992f10c9ed9435e3ebb6fb76c8"},
]
django-debug-toolbar = [ django-debug-toolbar = [
{file = "django-debug-toolbar-3.1.1.tar.gz", hash = "sha256:c97921a9cd421d392e7860dc4b464db8e06c8628df4dc58fedab012888c293c6"}, {file = "django-debug-toolbar-3.1.1.tar.gz", hash = "sha256:c97921a9cd421d392e7860dc4b464db8e06c8628df4dc58fedab012888c293c6"},
{file = "django_debug_toolbar-3.1.1-py3-none-any.whl", hash = "sha256:a1ce0665f7ef47d27b8df4b5d1058748e1f08500a01421a30d35164f38aaaf4c"}, {file = "django_debug_toolbar-3.1.1-py3-none-any.whl", hash = "sha256:a1ce0665f7ef47d27b8df4b5d1058748e1f08500a01421a30d35164f38aaaf4c"},

Wyświetl plik

@ -45,6 +45,7 @@ gunicorn = "*" # https://gunicorn.org/
django = "2.2.*" django = "2.2.*"
django-debug-toolbar = "*" # http://django-debug-toolbar.readthedocs.io/en/stable/changes.html django-debug-toolbar = "*" # http://django-debug-toolbar.readthedocs.io/en/stable/changes.html
django-import-export = "*" # https://github.com/django-import-export/django-import-export django-import-export = "*" # https://github.com/django-import-export/django-import-export
django-dbbackup = "*" # https://github.com/django-dbbackup/django-dbbackup
django-tools = "*" # https://github.com/jedie/django-tools/ django-tools = "*" # https://github.com/jedie/django-tools/
django-reversion-compare = "*" # https://github.com/jedie/django-reversion-compare/ django-reversion-compare = "*" # https://github.com/jedie/django-reversion-compare/
django-ckeditor = "*" # https://github.com/django-ckeditor/django-ckeditor django-ckeditor = "*" # https://github.com/django-ckeditor/django-ckeditor