Skip to content

Commit b8d54fd

Browse files
committed
Merge branch 'next' of https://github.com/Geode-solutions/OpenGeodeWeb-Back into fix/unused_params
2 parents 5c7f3d0 + 9abf7dd commit b8d54fd

File tree

16 files changed

+303
-89
lines changed

16 files changed

+303
-89
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ __pycache__
99
.vscode
1010
uploads
1111
node_modules
12-
schemas.json
12+
schemas.json
13+
.mypy_cache
14+
*.db

.vscode/settings.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,11 @@
33
"."
44
],
55
"python.testing.unittestEnabled": false,
6-
"python.testing.pytestEnabled": true
6+
"python.testing.pytestEnabled": true,
7+
"mypy-type-checker.args": [
8+
"--config-file=mypy.ini"
9+
],
10+
"mypy-type-checker.interpreter": [
11+
"${workspaceFolder}/venv/bin/python"
12+
]
713
}

app.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from src.opengeodeweb_back.routes.models import blueprint_models
1111
from src.opengeodeweb_back.utils_functions import handle_exception
1212
from src.opengeodeweb_back import app_config
13+
from src.opengeodeweb_back.database import initialize_database
1314

1415

1516
""" Global config """
@@ -57,5 +58,6 @@ def return_error():
5758

5859
# ''' Main '''
5960
if __name__ == "__main__":
61+
initialize_database(app)
6062
print(f"Python is running in {FLASK_DEBUG} mode")
6163
app.run(debug=FLASK_DEBUG, host=DEFAULT_HOST, port=PORT, ssl_context=SSL)

commitlint.config.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export default {
2+
extends: ["@commitlint/config-angular"],
3+
rules: {
4+
"scope-empty": [2, "never"],
5+
"subject-empty": [2, "never"],
6+
"subject-max-length": [0],
7+
"body-leading-blank": [0],
8+
"footer-leading-blank": [0],
9+
"header-max-length": [0],
10+
"scope-case": [0],
11+
"subject-case": [0],
12+
"subject-full-stop": [0],
13+
"type-case": [0],
14+
"type-empty": [0],
15+
},
16+
}

mypy.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[mypy]
2+
strict = True
3+
files = src/

requirements.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ fastjsonschema==2.16.2
88
Flask[async]==3.0.3
99
Flask-Cors==6.0.1
1010
werkzeug==3.0.3
11+
Flask-SQLAlchemy==3.1.1

requirements.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,17 @@ flask[async]==3.0.3
1717
# -r requirements.in
1818
# flask
1919
# flask-cors
20+
# flask-sqlalchemy
2021
flask-cors==6.0.1
2122
# via -r requirements.in
23+
flask-sqlalchemy==3.1.1
24+
# via -r requirements.in
2225
geode-common==33.9.0
2326
# via geode-viewables
2427
geode-viewables==3.2.0
2528
# via -r requirements.in
29+
greenlet==3.2.4
30+
# via sqlalchemy
2631
itsdangerous==2.2.0
2732
# via flask
2833
jinja2==3.1.6
@@ -54,6 +59,10 @@ opengeode-io==7.3.2
5459
# -r requirements.in
5560
# geode-viewables
5661
# opengeode-geosciencesio
62+
sqlalchemy==2.0.43
63+
# via flask-sqlalchemy
64+
typing-extensions==4.15.0
65+
# via sqlalchemy
5766
werkzeug==3.0.3
5867
# via
5968
# -r requirements.in

src/opengeodeweb_back/app_config.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
# Third party imports
66
# Local application imports
7+
from .database import DATABASE_FILENAME
78

89

910
class Config(object):
@@ -15,19 +16,27 @@ class Config(object):
1516
REQUEST_COUNTER = 0
1617
LAST_REQUEST_TIME = time.time()
1718
LAST_PING_TIME = time.time()
19+
SQLALCHEMY_TRACK_MODIFICATIONS = False
1820

1921

2022
class ProdConfig(Config):
2123
SSL = None
2224
ORIGINS = ""
2325
MINUTES_BEFORE_TIMEOUT = "1"
2426
SECONDS_BETWEEN_SHUTDOWNS = "10"
25-
DATA_FOLDER_PATH = "/data/"
27+
DATA_FOLDER_PATH = "/data"
28+
SQLALCHEMY_DATABASE_URI = f"sqlite:///{os.path.abspath(
29+
os.path.join(DATA_FOLDER_PATH, DATABASE_FILENAME)
30+
)}"
2631

2732

2833
class DevConfig(Config):
2934
SSL = None
3035
ORIGINS = "*"
3136
MINUTES_BEFORE_TIMEOUT = "1"
3237
SECONDS_BETWEEN_SHUTDOWNS = "10"
33-
DATA_FOLDER_PATH = "./data/"
38+
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
39+
DATA_FOLDER_PATH = os.path.join(BASE_DIR, "data")
40+
SQLALCHEMY_DATABASE_URI = f"sqlite:///{os.path.join(
41+
BASE_DIR, DATA_FOLDER_PATH, DATABASE_FILENAME
42+
)}"

src/opengeodeweb_back/data.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from sqlalchemy import String, JSON
2+
from sqlalchemy.orm import Mapped, mapped_column
3+
from .database import database, Base
4+
import uuid
5+
6+
7+
class Data(Base):
8+
__tablename__ = "datas"
9+
10+
id: Mapped[str] = mapped_column(
11+
String, primary_key=True, default=lambda: str(uuid.uuid4()).replace("-", "")
12+
)
13+
name: Mapped[str] = mapped_column(String, nullable=False)
14+
native_file_name: Mapped[str] = mapped_column(String, nullable=False)
15+
viewable_file_name: Mapped[str] = mapped_column(String, nullable=False)
16+
geode_object: Mapped[str] = mapped_column(String, nullable=False)
17+
18+
light_viewable: Mapped[str | None] = mapped_column(String, nullable=True)
19+
input_file: Mapped[str | None] = mapped_column(String, nullable=True)
20+
additional_files: Mapped[list[str] | None] = mapped_column(JSON, nullable=True)
21+
22+
@staticmethod
23+
def create(
24+
name: str,
25+
geode_object: str,
26+
input_file: str | None = None,
27+
additional_files: list[str] | None = None,
28+
) -> "Data":
29+
input_file = input_file if input_file is not None else ""
30+
additional_files = additional_files if additional_files is not None else []
31+
32+
data_entry = Data(
33+
name=name,
34+
geode_object=geode_object,
35+
input_file=input_file,
36+
additional_files=additional_files,
37+
native_file_name="",
38+
viewable_file_name="",
39+
light_viewable=None,
40+
)
41+
42+
database.session.add(data_entry)
43+
database.session.flush()
44+
return data_entry

src/opengeodeweb_back/database.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from flask import Flask
2+
from flask_sqlalchemy import SQLAlchemy
3+
from sqlalchemy.orm import DeclarativeBase
4+
5+
DATABASE_FILENAME = "project.db"
6+
7+
8+
class Base(DeclarativeBase):
9+
pass
10+
11+
12+
database = SQLAlchemy(model_class=Base)
13+
14+
15+
def initialize_database(app: Flask) -> SQLAlchemy:
16+
database.init_app(app)
17+
with app.app_context():
18+
database.create_all()
19+
return database

0 commit comments

Comments
 (0)