Skip to content

Commit

Permalink
#2 update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
emil-balashov committed Dec 23, 2019
1 parent db310ca commit 68851ff
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 4 deletions.
76 changes: 73 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Django-Logic (under development)
[![Build Status](https://travis-ci.org/Borderless360/django-logic.svg?branch=master)](https://travis-ci.org/Borderless360/django-logic) [![Coverage Status](https://coveralls.io/repos/github/Borderless360/django-logic/badge.svg?branch=master)](https://coveralls.io/github/Borderless360/django-logic?branch=master)
# Django-Logic

django-logic - easy way to implement state-based business logic
[![Build Status](https://travis-ci.org/Borderless360/django-logic.svg?branch=master)](https://travis-ci.org/Borderless360/django-logic) [![Coverage Status](https://coveralls.io/repos/github/Borderless360/django-logic/badge.svg?branch=master)](https://coveralls.io/github/Borderless360/django-logic?branch=master)

Django Logic is a lightweight workflow framework aims to solve an open problem "Where to put the business logic in Django?".

Expand All @@ -18,3 +17,74 @@ Django Logic is a lightweight workflow framework aims to solve an open problem "
- Test your business logic by unit-tests as pure functions.
- Protects from overwritten states, locks, etc. already implemented in Django Logic and you could control the behaviour.
- Several states can be combined under the same Model.

## Installation

Use the package manager [pip](https://pip.pypa.io/en/stable/) to install Django-Logic.

```bash
pip install django-logic
```

## Usage
1. Create a django project and start a new app
2. Create a new file `process.py` under the app and define your process.
```python
from django_logic import Process as BaseProcess, Transition


class Process(BaseProcess):
states = (
('draft', 'Draft'),
('paid', 'Paid'),
('void', 'Void'),
)

transitions = [
Transition(action_name='approve', sources=['draft'], target='approved'),
Transition(action_name='void', sources=['draft', 'approved'], target='void'),
]
```
3. Display the process.

[![][invoice-img]][invoice-img]

4. Bind the process with a model
```python
from django.db import models
from django_logic.process import ProcessManager
from .process import Process as InvoiceProcess


class Invoice(ProcessManager.bind_state_fields(status=InvoiceProcess), models.Model):
status = models.CharField(choices=InvoiceProcess.states, default='draft', max_length=16, blank=True)
```
5. Usage
```python
invoice = Invoice.objects.create()
print(list([transition.action_name for transition in invoice.process.get_available_transitions())])
>> ['approve', 'void']
invoice.process.approve()
invoice.status
>> 'approved'

print(list([transition.action_name for transition in invoice.process.get_available_transitions())])
>> ['void']
invoice.process.void()
invoice.status
>> 'void'

```
## Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

## License
[MIT](https://choosealicense.com/licenses/mit/)

## Project status
Under development


[invoice-img]: https://user-images.githubusercontent.com/6745569/71333209-2840f080-2574-11ea-84e6-633f20d7d78f.png
2 changes: 1 addition & 1 deletion django_logic/draw.py → django_logic/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def get_graph_from_process(process_class, state, skip_main_process=False):
return graph


def view_process(process_class, state, skip_main_process=False):
def display_process(process_class, state, skip_main_process=False):
graph = get_graph_from_process(process_class, state, skip_main_process)
try:
graph.view()
Expand Down

0 comments on commit 68851ff

Please sign in to comment.