diff --git a/config.py b/config.py index 8306818..f6451f5 100644 --- a/config.py +++ b/config.py @@ -28,7 +28,7 @@ REFRESH_TOKEN_EXPIRE_DAYS = 170 TOKEN_TTL_DAYS = 7 ACCESS_COOKIE = "access_token" REFRESH_COOKIE = "refresh_token" -RABBITMQ_HOST = "rabbitmq-0.rabbitmq.kultmost.svc.cluster.local" if PROD else "rabbit.spiritofweb.ru:31023" +RABBITMQ_HOST = "rabbit.spiritofweb.ru:31023" EMAIL_SUBJECT = 'Культмост' PROTECTED_FIELDS_USER = {"_id", "img", 'original_img', "hashed_password", "password", "roles"} VK_CLIENT_ID = os.getenv("VK_CLIENT_ID") diff --git a/email_task.ipynb b/email_task.ipynb index fab8029..2d124ce 100644 --- a/email_task.ipynb +++ b/email_task.ipynb @@ -7,7 +7,7 @@ "metadata": {}, "outputs": [], "source": [ - "# ignore\n", + "#ignore\n", "import os\n", "\n", "def load_env(file_path):\n", diff --git a/email_task.py b/email_task.py index 5318c68..5cfe161 100644 --- a/email_task.py +++ b/email_task.py @@ -1,3 +1,35 @@ +#ignore +import os + +def load_env(file_path): + """Загружает переменные окружения из файла .env с поддержкой булевых значений.""" + with open(file_path) as f: + for line in f: + line = line.strip() + if not line or line.startswith('#'): + continue + + try: + key, value = line.split('=', 1) + key = key.strip() + value = value.strip('"\' ') + # Преобразование строковых значений в булевые + if value.lower() in ['true', '1', 'yes']: + value = True + elif value.lower() in ['false', '0', 'no']: + value = False + + # Проверка, что ключ не пустой + if key: + os.environ[key] = str(value) # Храним как строку + except ValueError: + print(f"Ошибка: неверный формат в строке '{line}'") + +try: + load_env('env') +except: + load_env('env_example') + import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText diff --git a/main.ipynb b/main.ipynb index 8bde025..8a42df2 100644 --- a/main.ipynb +++ b/main.ipynb @@ -2701,8 +2701,9 @@ " user: Dict = Security(get_current_user, scopes=[\"create:super_items\"])\n", "): \n", " competition = await competitions_col.find_one({'_id': ObjectId(competition_id)})\n", + " data = json.dumps(competition, cls=MongoJSONEncoder, ensure_ascii=False)\n", " return templates.TemplateResponse(\n", - " request=request, name=\"form/competition_edit.html\", context={\"competition\": competition, \"user\": user}\n", + " request=request, name=\"form/competition_edit.html\", context={\"competition\": str(data), \"user\": user}\n", " )\n" ] }, @@ -2815,17 +2816,6 @@ "metadata": {}, "outputs": [], "source": [ - "import json\n", - "from datetime import datetime, date\n", - "from bson import ObjectId\n", - "\n", - "class MongoJSONEncoder(json.JSONEncoder):\n", - " def default(self, o):\n", - " if isinstance(o, ObjectId):\n", - " return str(o)\n", - " if isinstance(o, (datetime, date)):\n", - " return o.isoformat()\n", - " return super().default(o)\n", "\n", "\n", "@app.get(\"/form/exhibition/{exhibition_id}\", response_class=HTMLResponse)\n", @@ -2835,8 +2825,7 @@ " user: Dict = Security(get_current_user)\n", "):\n", " exhibition = await exhibition_collection.find_one({'_id': ObjectId(exhibition_id)},{'posts':0,'vk':0,'tg':0,'fb':0,'inst':0,'max':0})\n", - " data= json.dumps(exhibition, cls=MongoJSONEncoder, ensure_ascii=False)\n", - " print(data)\n", + " data = json.dumps(exhibition, cls=MongoJSONEncoder, ensure_ascii=False)\n", " return templates.TemplateResponse(\n", " request=request, name=\"form/exhibition_edit.html\", context={\"id\": 1, \"user\": user, \"exhibition\": str(data)}\n", " )" diff --git a/main.py b/main.py index 155b052..0cde495 100644 --- a/main.py +++ b/main.py @@ -2028,8 +2028,9 @@ async def form_( user: Dict = Security(get_current_user, scopes=["create:super_items"]) ): competition = await competitions_col.find_one({'_id': ObjectId(competition_id)}) + data = json.dumps(competition, cls=MongoJSONEncoder, ensure_ascii=False) return templates.TemplateResponse( - request=request, name="form/competition_edit.html", context={"competition": competition, "user": user} + request=request, name="form/competition_edit.html", context={"competition": str(data), "user": user} ) @@ -2104,17 +2105,6 @@ async def form_exhibition( request=request, name="form/exhibition.html", context={"id": 1, "user": user} ) -import json -from datetime import datetime, date -from bson import ObjectId - -class MongoJSONEncoder(json.JSONEncoder): - def default(self, o): - if isinstance(o, ObjectId): - return str(o) - if isinstance(o, (datetime, date)): - return o.isoformat() - return super().default(o) @app.get("/form/exhibition/{exhibition_id}", response_class=HTMLResponse) @@ -2124,8 +2114,7 @@ async def form_exhibition( user: Dict = Security(get_current_user) ): exhibition = await exhibition_collection.find_one({'_id': ObjectId(exhibition_id)},{'posts':0,'vk':0,'tg':0,'fb':0,'inst':0,'max':0}) - data= json.dumps(exhibition, cls=MongoJSONEncoder, ensure_ascii=False) - print(data) + data = json.dumps(exhibition, cls=MongoJSONEncoder, ensure_ascii=False) return templates.TemplateResponse( request=request, name="form/exhibition_edit.html", context={"id": 1, "user": user, "exhibition": str(data)} ) diff --git a/templates/competition/edit.html b/templates/competition/edit.html index 8a597f6..631c40e 100644 --- a/templates/competition/edit.html +++ b/templates/competition/edit.html @@ -2,24 +2,6 @@ {% import "components/checkbox.html" as checkbox %} {% macro section(user, competition) -%} - -