mirror of
https://gitflic.ru/project/maks1ms/ocab.git
synced 2025-03-13 22:03:50 +03:00
исправлено сохранение настроек
This commit is contained in:
parent
d5f6f1bb4f
commit
3130e820c3
1
.gitignore
vendored
1
.gitignore
vendored
@ -7,3 +7,4 @@ venv
|
|||||||
__pycache__
|
__pycache__
|
||||||
OCAB.db
|
OCAB.db
|
||||||
config.yaml
|
config.yaml
|
||||||
|
dist
|
||||||
|
2
poetry.toml
Normal file
2
poetry.toml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
[virtualenvs]
|
||||||
|
in-project = true
|
23
src/gnomik/Dockerfile
Normal file
23
src/gnomik/Dockerfile
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
FROM python:3.12-slim as builder
|
||||||
|
|
||||||
|
RUN pip install poetry
|
||||||
|
RUN mkdir -p /app
|
||||||
|
COPY . /app
|
||||||
|
|
||||||
|
# Фикс
|
||||||
|
|
||||||
|
RUN sed -i '/ocab-core = {/{s/, develop = true//}' /app/src/gnomik/pyproject.toml && \
|
||||||
|
sed -i '/ocab-modules = {/{s/, develop = true//}' /app/src/gnomik/pyproject.toml && \
|
||||||
|
sed -i '/ocab-core = {/{s/, develop = true//}' /app/src/ocab_modules/pyproject.toml
|
||||||
|
|
||||||
|
WORKDIR /app/src/gnomik
|
||||||
|
|
||||||
|
RUN poetry lock && poetry install
|
||||||
|
|
||||||
|
FROM python:3.12-slim as base
|
||||||
|
|
||||||
|
COPY --from=builder /app/src/gnomik /app
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
ENV PATH="/app/.venv/bin:$PATH"
|
||||||
|
CMD ["python", "-m", "gnomik"]
|
14
src/gnomik/Dockerfile.dockerignore
Normal file
14
src/gnomik/Dockerfile.dockerignore
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
**/Dockerfile
|
||||||
|
**/*.dockerignore
|
||||||
|
**/docker-compose.yml
|
||||||
|
|
||||||
|
**/.git
|
||||||
|
**/.gitignore
|
||||||
|
|
||||||
|
**/.venv
|
||||||
|
|
||||||
|
**/.mypy_cache
|
||||||
|
**/__pycache__/
|
||||||
|
|
||||||
|
src/gnomik/config.yaml
|
||||||
|
src/gnomik/database/*
|
12
src/gnomik/docker-compose.yml
Normal file
12
src/gnomik/docker-compose.yml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
version: '3'
|
||||||
|
|
||||||
|
services:
|
||||||
|
app:
|
||||||
|
build:
|
||||||
|
context: ../..
|
||||||
|
dockerfile: src/gnomik/Dockerfile
|
||||||
|
ports:
|
||||||
|
- 9000:9000
|
||||||
|
volumes:
|
||||||
|
- ./config.yaml:/app/config.yaml
|
||||||
|
- ./database:/app/database
|
@ -36,8 +36,19 @@ class ConfigManager:
|
|||||||
def save(self, file_path: str = ""):
|
def save(self, file_path: str = ""):
|
||||||
if not file_path:
|
if not file_path:
|
||||||
file_path = self.config_path
|
file_path = self.config_path
|
||||||
|
|
||||||
|
def nested_dict(flat_dict):
|
||||||
|
result = {}
|
||||||
|
for key, value in flat_dict.items():
|
||||||
|
keys = key.split("::")
|
||||||
|
d = result
|
||||||
|
for k in keys[:-1]:
|
||||||
|
d = d.setdefault(k, {})
|
||||||
|
d[keys[-1]] = value
|
||||||
|
return result
|
||||||
|
|
||||||
with open(file_path, "w", encoding="utf-8") as file:
|
with open(file_path, "w", encoding="utf-8") as file:
|
||||||
yaml.dump(self._config, file, allow_unicode=True)
|
yaml.dump(nested_dict(self._config), file, allow_unicode=True)
|
||||||
|
|
||||||
def _check_rights(self, key, module_id, access_type="get"):
|
def _check_rights(self, key, module_id, access_type="get"):
|
||||||
return
|
return
|
||||||
@ -58,6 +69,16 @@ class ConfigManager:
|
|||||||
module_id = caller_globals.get("__ocab_module_id__")
|
module_id = caller_globals.get("__ocab_module_id__")
|
||||||
return module_id
|
return module_id
|
||||||
|
|
||||||
|
def mass_set(self, updates: Dict[str, Any]):
|
||||||
|
module_id = self._get_module_id()
|
||||||
|
for key, value in updates.items():
|
||||||
|
self._check_rights(key, module_id, "set")
|
||||||
|
if key in self._metadata:
|
||||||
|
# TODO: add checks to validate the type and value based on metadata
|
||||||
|
self._config[key] = value
|
||||||
|
else:
|
||||||
|
raise KeyError(f"Key {key} is not registered.")
|
||||||
|
|
||||||
def register(
|
def register(
|
||||||
self,
|
self,
|
||||||
key: str,
|
key: str,
|
||||||
|
@ -127,7 +127,6 @@ def create_settings_components(tree, level=0):
|
|||||||
|
|
||||||
def get_miniapp_blueprint(config: ConfigManager, prefix: str):
|
def get_miniapp_blueprint(config: ConfigManager, prefix: str):
|
||||||
import datetime
|
import datetime
|
||||||
import locale
|
|
||||||
|
|
||||||
from dash_extensions.enrich import DashBlueprint
|
from dash_extensions.enrich import DashBlueprint
|
||||||
|
|
||||||
@ -181,7 +180,10 @@ def get_miniapp_blueprint(config: ConfigManager, prefix: str):
|
|||||||
key = key.removeprefix(f"{prefix}-")
|
key = key.removeprefix(f"{prefix}-")
|
||||||
updated_settings[key] = value
|
updated_settings[key] = value
|
||||||
|
|
||||||
locale.setlocale(locale.LC_TIME, "ru_RU.UTF-8")
|
config.mass_set(updated_settings)
|
||||||
|
config.save()
|
||||||
|
|
||||||
|
# locale.setlocale(locale.LC_TIME, "ru_RU.UTF-8")
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.now()
|
||||||
date_str = now.strftime("%H:%M:%S")
|
date_str = now.strftime("%H:%M:%S")
|
||||||
|
|
||||||
|
1462
src/ocab_modules/poetry.lock
generated
1462
src/ocab_modules/poetry.lock
generated
File diff suppressed because it is too large
Load Diff
@ -17,6 +17,8 @@ dash = "^2.17.1"
|
|||||||
dash-extensions = "^1.0.18"
|
dash-extensions = "^1.0.18"
|
||||||
dash-bootstrap-components = "^1.6.0"
|
dash-bootstrap-components = "^1.6.0"
|
||||||
|
|
||||||
|
[tool.poetry-monorepo.deps]
|
||||||
|
enabled = true
|
||||||
|
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = ["poetry-core"]
|
requires = ["poetry-core"]
|
||||||
|
Loading…
Reference in New Issue
Block a user