File tree 4 files changed +50
-14
lines changed
4 files changed +50
-14
lines changed Original file line number Diff line number Diff line change @@ -27,9 +27,14 @@ Ziho is a prototype for a better online interface for Anki than [Anki Web](https
27
27
Ziho allows you to create, study and easily share and clone decks, as well as edit them online.
28
28
29
29
The backend is built with ** Flask** , and the [ fsrs] ( https://github.com/open-spaced-repetition ) algorithm is used for spaced repetition.
30
+ Following were also used:
31
+ - Bootstrap
32
+ - SQLAlchemy
33
+ - Docker
30
34
31
- <span ><img src =" https://shanukun.github.io/static/images/ziho/home.png " width =" 30% " ></span >
32
- <span ><img src =" https://shanukun.github.io/static/images/ziho/study-deck.png " width =" 25% " ></span >
35
+
36
+ <span ><img src =" https://shanukun.github.io/static/images/ziho/home.png " width =" 40% " ></span >
37
+ <span ><img src =" https://shanukun.github.io/static/images/ziho/study-deck.png " width =" 35% " ></span >
33
38
34
39
You can find more screenshots [ here] ( https://shanukun.github.io/ziho-ss/ ) .
35
40
@@ -58,7 +63,30 @@ You can find more screenshots [here](https://shanukun.github.io/ziho-ss/).
58
63
./tools/setup
59
64
` ` `
60
65
3. ** Set up your environment variables in a ` .env` file: To run without debug mode, set ` DEBUG_MODE=off` .**
66
+ - Set following for using MySQL
67
+ - MYSQL_USER
68
+ - MYSQL_PASS
69
+ - MYSQL_HOST
70
+ - MYSQL_PORT
71
+ - MYSQL_DB
61
72
4. ** Start the webapp:**
62
73
` ` ` bash
63
74
./tools/run-ziho
64
75
` ` `
76
+
77
+ # # Contributing
78
+
79
+ 1. Follow the code style. Run the following to test the format.
80
+ ` ` ` bash
81
+ ./tools/test_lint
82
+ ` ` `
83
+ 2. Format the code using:
84
+ ` ` ` bash
85
+ ./tools/lint_and_format
86
+ ` ` `
87
+ 3. Make sure to add the tests for new routes
88
+ ` ` ` bash
89
+ pytest ./tests
90
+ ` ` `
91
+
92
+
Original file line number Diff line number Diff line change 1
1
import os
2
+ import sys
2
3
from pathlib import Path
3
4
4
5
from dotenv import load_dotenv
7
8
load_dotenv ()
8
9
9
10
10
- DATABASE = "sqlite:///" + os .path .join (basedir , "app.db" )
11
+ def z_env (env_var : str ) -> str | None :
12
+ var_val = os .environ .get (env_var , None )
13
+ return var_val
14
+
15
+
16
+ DATABASE_URL = "sqlite:///" + os .path .join (basedir , "app.db" )
11
17
if os .environ .get ("DATABASE" ) == "mysql" :
12
- pass
18
+ DATABASE_URL = f"mysql+pymysql:// { z_env ( 'MYSQL_USER' ) } : { z_env ( 'MYSQL_PASS' ) } @ { z_env ( 'MYSQL_HOST' ) } : { z_env ( 'MYSQL_PORT' ) } / { z_env ( 'MYSQL_DB' ) } "
13
19
14
20
15
21
class Config :
16
- SECRET_KEY = os .environ .get ("SECRET_KEY" ) or "hardcoded-string"
22
+ DATABASE = z_env ("DATABASE" )
23
+ SECRET_KEY = z_env ("SECRET_KEY" ) or "hardcoded-string"
17
24
18
25
# sqlalchemy
19
- SQLALCHEMY_DATABASE_URI = os . environ . get ( " DATABASE_URL" ) or DATABASE
26
+ SQLALCHEMY_DATABASE_URI = DATABASE_URL
20
27
SQLALCHEMY_TRACK_MODIFICATIONS = False
28
+
21
29
UPLOAD_FOLDER = Path ("ziho_uploads" )
22
30
UPLOAD_PATH = Path (basedir ) / "ziho" / UPLOAD_FOLDER
23
31
Original file line number Diff line number Diff line change @@ -32,4 +32,3 @@ curl -fLO --retry 3 "https://github.com/sass/dart-sass/releases/download/$versio
32
32
tar -xf " $tarball " --strip-components=1 -C " $CWD /bin/sass"
33
33
34
34
" $CWD " /bin/sass/sass --no-source-map --style compressed " $CWD " /ziho/static/scss/main.scss " $CWD " /ziho/static/css/main.css
35
-
Original file line number Diff line number Diff line change @@ -28,13 +28,14 @@ def create_app(config_class=Config):
28
28
29
29
db .init_app (app )
30
30
31
- with app .app_context ():
32
-
33
- @event .listens_for (db .engine , "connect" )
34
- def set_sqlite_pragma (dbapi_connection , connection_record ):
35
- cursor = dbapi_connection .cursor ()
36
- cursor .execute ("PRAGMA foreign_keys=ON" )
37
- cursor .close ()
31
+ if config_class .DATABASE != "mysql" :
32
+ with app .app_context ():
33
+
34
+ @event .listens_for (db .engine , "connect" )
35
+ def set_sqlite_pragma (dbapi_connection , connection_record ):
36
+ cursor = dbapi_connection .cursor ()
37
+ cursor .execute ("PRAGMA foreign_keys=ON" )
38
+ cursor .close ()
38
39
39
40
migrate .init_app (app , db , render_as_batch = True )
40
41
login_manager .init_app (app )
You can’t perform that action at this time.
0 commit comments