Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Flask-State
## Usage Examples HOW TO

### First time setup
Clone `Flask-State` locally, or download the `examples` directory
```shell script
git clone https://github.com/yoobool/flask-state.git
cd flask-state
```

### Install Python Packages
You can create a virtualenv before install package optionally.
```shell script
python3 -m venv env
. env/bin/activate
```
Install packages for `examples`
```shell script
pip install -e ".[examples]"
```

### Install Redis
You can install through Redis binary release, Ubuntu PPA,<br>
build from source or via Docker.

For more info, check out [Redis - Download](https://redis.io/download)
, Remember to change config in `examples/config.py` after install.

If you have `docker-compose`, you can also create a redis container simply via:
```shell script
# cd path/to/flask-state/examples
docker-compose up -d
```

### Done!
Run examples app via:
```shell script
# cd path/to/flask-state/examples
python3 app.py
```
Checkout pages on your [browser](http://127.0.0.1:5000)
```shell script
http://127.0.0.1:5000
```
12 changes: 6 additions & 6 deletions examples/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

from flask import Flask

from src.flask_state import DEFAULT_BIND_SQLITE, init_app
from flask_state import DEFAULT_BIND_SQLITE, init_app

# SQLite URI compatible
WIN = sys.platform.startswith('win')
WIN = sys.platform.startswith("win")
if WIN:
prefix = 'sqlite:///'
prefix = "sqlite:///"
else:
prefix = 'sqlite:////'
prefix = "sqlite:////"


def setting_app():
Expand All @@ -19,9 +19,9 @@ def setting_app():
# Redis conf
app.config["REDIS_CONF"] = {
"REDIS_STATUS": True,
"REDIS_HOST": "192.168.0.2",
"REDIS_HOST": "127.0.0.1",
"REDIS_PORT": 16379,
"REDIS_PASSWORD": "fish09",
"REDIS_PASSWORD": "password",
}
path_ = os.getcwd() + "/flask_state_host.db"
app.config["SQLALCHEMY_BINDS"] = {DEFAULT_BIND_SQLITE: prefix + path_}
Expand Down
10 changes: 10 additions & 0 deletions examples/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: '3.4'
services:
redis:
image: redis:6.0
command: redis-server /usr/local/etc/redis/redis.conf
ports:
- "16379:6379"
volumes:
- ./data/redis:/var/lib/redis
- ./redis.conf:/usr/local/etc/redis/redis.conf
1 change: 1 addition & 0 deletions examples/redis.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requirepass password
4 changes: 2 additions & 2 deletions examples/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta name="viewport"
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>index</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/yoobool/flask-state@v1.0.4/packages/flask-state.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/yoobool/flask-state@v1.0.5/packages/flask-state.min.css">
</head>
<body style="height: 100%;background-color: purple">
<script src="https://cdn.staticfile.org/echarts/4.2.1/echarts.min.js"></script>
Expand All @@ -14,7 +14,7 @@
click me
</div>

<script src="https://cdn.jsdelivr.net/gh/yoobool/flask-state@v1.0.4/packages/umd/flask-state.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/yoobool/flask-state@v1.0.5/packages/umd/flask-state.min.js"></script>
<script type="text/javascript">
flaskState.init({dom:document.getElementById('test_id')});
</script>
Expand Down
5 changes: 5 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@
name=about["__title__"],
version=about["__version__"],
install_requires=["Flask>=1.0", "Flask-SQLAlchemy>=1.0", "psutil>=5.7.0"],
extras_require={
"test": ["pytest", "redis"],
"dev": ["black", "codespell", "flake8", "isort", "pip-tools", "pre-commit", "setuptools", "twine", "wheel"],
"example": ["redis"],
},
)