0
0
mirror of https://gitflic.ru/project/maks1ms/ocab.git synced 2024-12-24 00:33:05 +03:00

исправлено сохранение настроек

This commit is contained in:
Maxim Slipenko 2024-07-31 15:20:13 +03:00
parent d5f6f1bb4f
commit 3130e820c3
9 changed files with 1540 additions and 5 deletions

1
.gitignore vendored
View File

@ -7,3 +7,4 @@ venv
__pycache__
OCAB.db
config.yaml
dist

2
poetry.toml Normal file
View File

@ -0,0 +1,2 @@
[virtualenvs]
in-project = true

23
src/gnomik/Dockerfile Normal file
View 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"]

View File

@ -0,0 +1,14 @@
**/Dockerfile
**/*.dockerignore
**/docker-compose.yml
**/.git
**/.gitignore
**/.venv
**/.mypy_cache
**/__pycache__/
src/gnomik/config.yaml
src/gnomik/database/*

View 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

View File

@ -36,8 +36,19 @@ class ConfigManager:
def save(self, file_path: str = ""):
if not file_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:
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"):
return
@ -58,6 +69,16 @@ class ConfigManager:
module_id = caller_globals.get("__ocab_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(
self,
key: str,

View File

@ -127,7 +127,6 @@ def create_settings_components(tree, level=0):
def get_miniapp_blueprint(config: ConfigManager, prefix: str):
import datetime
import locale
from dash_extensions.enrich import DashBlueprint
@ -181,7 +180,10 @@ def get_miniapp_blueprint(config: ConfigManager, prefix: str):
key = key.removeprefix(f"{prefix}-")
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()
date_str = now.strftime("%H:%M:%S")

File diff suppressed because it is too large Load Diff

View File

@ -17,6 +17,8 @@ dash = "^2.17.1"
dash-extensions = "^1.0.18"
dash-bootstrap-components = "^1.6.0"
[tool.poetry-monorepo.deps]
enabled = true
[build-system]
requires = ["poetry-core"]