- goto your project src dir
git submodule add [email protected]:izumiFinance/izumi_infra.git
- add django app under izumi_infra to
INSTALLED_APPS
, such asizumi_infra.blockchain
izumi_infra.etherscan
- optional, you can load base fixture data from app fixture dir by
python manage.py loaddata xxx
update izumi_infra package version
- rewire izumi_infra code until finished
- izumi_infra submodule git commit
git tag a v0.0.1 -m 'Your improve message'
thengit push origin --tags
git checkout v0.0.1
- top git project commit
- create file
apps/utils/blockchain_const.py
like below:
# -*- coding: utf-8 -*-
from enum import Enum
from izumi_infra.blockchain.constants import BaseContractInfoEnum, BaseTopicEnum, BasicContractInfoEnum
from izumi_infra.utils import abiJsonLoader
from izumi_infra.utils.enum_utils import extend_enum
class ContractABI(Enum):
HOURAI_ABI = abiJsonLoader.get('apps.gallery.hourai.json')
@extend_enum(BaseContractInfoEnum)
class ContractInfoEnum(BasicContractInfoEnum):
Hourai = {
"desc": "Hourai Contract",
"topic": BaseTopicEnum.topic_list(),
"abi": ContractABI.HOURAI_ABI.value
}
- override default enum class for blockchain in
setting.py
IZUMI_INFRA_BLOCKCHAIN = {
'CONTRACT_CHOICES_CLASS': 'apps.utils.blockchain_const.ContractInfoEnum'
}
support change default conf by set new object named IZUMI_INFRA_BLOCKCHAIN
, or set env variable, see
izumi_infra/blockchain/conf.py
for detail.
support change default conf by set new object named IZUMI_INFRA_ETHERSCAN
, or set env variable, see
izumi_infra/etherscan/conf.py
for detail.
add izumi_infra.extensions at your INSTALLED_APPS.
# add izumi_infra/extensions/templates to TEMPLATES.DIRS
TEMPLATES = [
{
...
'DIRS': [os.path.join(BASE_DIR, "templates/"), os.path.join(BASE_DIR, "../izumi_infra/extensions/templates/")],
...
},
]
# add url to your root project url setting, remind add this path to your admin nginx proxy
urlpatterns = [
...
path('', include('izumi_infra.extensions.urls')),
]
# custom your Captcha conf, ref: https://django-simple-captcha.readthedocs.io/en/latest/
# like math captcha
CAPTCHA_IMAGE_SIZE = (80, 45)
CAPTCHA_LENGTH = 6
CAPTCHA_TIMEOUT = 1
CAPTCHA_OUTPUT_FORMAT = '%(image)s %(text_field)s %(hidden_field)s '
CAPTCHA_NOISE_FUNCTIONS = (
'captcha.helpers.noise_null',
'captcha.helpers.noise_arcs',
'captcha.helpers.noise_dots',
)
CAPTCHA_CHALLENGE_FUNCT = 'captcha.helpers.math_challenge'
Then you may add nginx config like below, if you use nginx.
location ^~ /admin/ {
proxy_set_header Host $proxy_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;
proxy_pass ...
}
limit ip and admin site title conf see izumi_infra/extensions/conf.py
.
features:
abitypegen
generate typing files of Python by Contract abi file- example:
python manage.py abitypegen izumi_infra/blockchain/data/abi/erc/erc20.json
- example:
backupdb
backup database as sql filecleanup
reset database for django project initialloaddatax
load fixtures data with ignoresqldiff
show different of schema between database and django model
- config AsyncEmailAlertLogHandler as FATAL level handlers.
# django config file
LOGGING = {
'handlers': {
...
'email-alert': {
'level': 'FATAL',
'class': 'izumi_infra.extensions.AsyncEmailAlertLogHandler',
'formatter': 'verbose'
},
},
'loggers': {
'XXX': {
'handlers': [..., 'email-alert'],
}
}
}
-
add email which receive alert email to your superuser by admin page, or config at ADMINS. custom email from user will use first not blank value of
extensions_settings.ALERT_FROM_EMAIL
,settings.SERVER_EMAIL
,settings.DEFAULT_FROM_EMAIL
or default [email protected] -
config django email backend, example
# django config file
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_PORT = XXX
EMAIL_HOST = XXX
EMAIL_HOST_USER = XXX
EMAIL_HOST_PASSWORD = XXX
- set
ENABLE_SEND_ALERT_EMAIL
toTrue
at yourIZUMI_INFRA_EXTENSIONS
config
You can invoke method which register by SYSTEM_INVOKE_METHOD_LIST
in admin page, required super user permission.
# django config file
IZUMI_INFRA_EXTENSIONS = {
'SYSTEM_INVOKE_METHOD_LIST': (
# module path, method name
('izumi_infra.extensions.tasks', 'get_superuser_email_list'),
)
}
Then you invoke method at admin/extensions/system-invoke
page.
add it to your django conf like
MIDDLEWARE = [
...
'izumi_infra.middleware.exception_handler.ExceptionMiddleware'
]