If you are familiar with react/mobx and want to help us build awesome django-business-logic library, contact us at email@example.com.
Work on documentation in the process, see draft here.
The main goal of this project is to provide django site users (such as administrators or ordinal users) with ability to visually edit business logic layer. This library implements execution engine and code editor based on awesome blockly library. See screenshots.
Please note that this software is still Alpha/Beta quality and is not recommended for production use. The library is currently in active development and any API may be changed. Migration history for models is not supported now. Some internal objects are world writable!
This library requires the following:
Internally program code is stored as special django models such as NumberConstant, IfStatement, Assignment and so forth. Structure of syntax tree is held by class Node derived from treebeard.NS_Node. Operators and operands are linked with Node objects via django contenttypes system. Other details are briefly described below in sections Administrative setup and Execution
You can run demo app locally using docker:
docker build . -t django-business-logic-demo docker run --rm -it -p 8000:8000 django-business-logic-demo
or using docker-compose:
Also you can use prebuilt image:
docker run --rm -it -p 8000:8000 dgksu/django-business-logic:demo
Now you can login into django admin interface http://localhost:8000/admin/
test and password
You can deploy demo app directly to Heroku to see the app live. Just click the button below. This will walk you through getting this app up and running on Heroku in minutes.
There are a few different ways you can install django-business-logic:
pip install -U django-business-logic
git clone git://github.com/dgk/django-business-logic.gitand install it yourself.
# settings.py INSTALLED_APPS = ( # ... 'django.contrib.contenttypes', 'ace_overlay', # optional, for comfortable python functions editing 'adminsortable2', 'nested_admin', 'polymorphic', 'rest_framework', # optional, provided browsable API for this library handy development 'django_filters', # ^^ same 'business_logic', # ... )
# urls.py urlpatterns = ( # ... url('^nested_admin/', include('nested_admin.urls')), url('^business-logic/', include('business_logic.urls')), # ... )
python manage.py migrate
python manage.py collectstatic
First you should define one or more ProgramInterface objects via django admin interface (http://localhost:8000/admin/business_logic/programinterface/).
Each ProgramInterface must contain one or more ProgramArgument objects.
The ProgramArgument object represents one instance of django.db.Model
derived class specified as django.contrib.contentypes.ContentType instance (e.g. for your custom Order model) and his keyword argumet name (e.g.
Each ProgramArgument object must contain one or more ProgramArgumentField
which represents one field of django model
sum for Order object or
city field nested into Order DeliveryAddress model).
If you want to use system-wide references (e.g. your custom City or ProductCategory django model) and you define represented ProgramArgumentField you should register referenced model via django admin interface(http://localhost:8000/admin/business_logic/referencedescriptor/).
Next create one or more Program objects which must implements described ProgramInterface(e.g.
named "On Order create" with "on_order_create"
code field for programmatic access)
After setup you can go to web editor interface (http://localhost:8000/static/business_logic/index.html), choose program interface, program, create and start editing your first program version.
You may inject execution engine call at arbitrary place of your code, such as custom form.save, model.post_save methods, any django.dispatch.Signal handler or so on. Just instantiate appropriate ProgramVersion object and pass kwargs described in the ProgramInterface admin page to its execute() method . e.g.
from django.views.generic.edit import CreateView from business_logic.models import Program class OrderCreate(CreateView): def form_valid(self, form): order = form.save() program = Program.objects.get(code="on_order_create") program_version = program.versions.order_by("id").last() program_version.execute(order=order)
ProgramVersion.execute() method can accept instance of business_logic.Context object. If this parameter omitted execute() method creates new instance of Context with default parameters.
It can be initialized by the following parameters:
ProgramVersion.execute() returns the Context instance.
Many thanks to:
Virtualenv is probably what you want to use during development. Once you have virtualenv installed, just fire up a shell and create your own environment.
virtualenv venv source venv/bin/activate pip install -r requirements.dev.txt
python manage.py migrate python manage.py loaddata sites/dev/fixtures/data.json
python manage.py runserver
Fronted source files located under
npm run server:dev:hmr
Now webpack dev server will be listening on http://localhost:3000/ .
npm run build:prod
python manage.py test
You need to know at least one command; the one that runs all the tests: