RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-565450

Kamran Pulatov's questions

Martin Hope
Kamran Pulatov
Asked: 2024-07-21 05:26:41 +0000 UTC

SQLalchemy 2.0 监听事件并处理列更改

  • 8

大家好,我有一个模型表:

class User(Base):
    username: Mapped[str] = mapped_column(String(1_000), unique=True)
    email: Mapped[str] = mapped_column(unique=True, nullable=True)
    password: Mapped[str]
    is_active: Mapped[bool] = mapped_column(default=True)
    is_verified: Mapped[bool] = mapped_column(default=False)

我需要确保当电子邮件字段更改时,is_verified 字段自动更改为 False

python
  • 1 个回答
  • 52 Views
Martin Hope
Kamran Pulatov
Asked: 2024-06-06 22:51:33 +0000 UTC

我无法连接 aiogram_i18n,它给出错误 TypeError: ...expandable_blockquote

  • 5

__main__.py我决定将此中间件添加到应用程序文件夹中的文件中:

...
from aiogram_i18n import I18nMiddleware
from aiogram_i18n.cores import FluentRuntimeCore
...

async def main() -> None:
    await setup_logging()

    bot = Bot(
        token=settings.BOT_TOKEN,
        default=DefaultBotProperties(parse_mode=ParseMode.HTML),
    )
    dp = Dispatcher(storage=RedisStorage(redis=redis_storage()))

    dp.include_routers(user.router, admin.router, group.router, errors.router)
    ...
    dp.update.middleware(UoWMiddleWare(session_factory=session_factory()))

    mw = I18nMiddleware(
        core=FluentRuntimeCore(
            path="locales/{locale}",
        ),
    )

    mw.setup(dispatcher=dp)

    await dp.start_polling(bot, allowed_updates=dp.resolve_used_update_types())


if __name__ == "__main__":
    asyncio.run(main())

在私人聊天的处理程序(我在下面连接的路由器)中,我有这个:

from typing import Any

from aiogram import Router, F
from aiogram.types import Message
from aiogram.filters import Command, CommandStart
from aiogram.methods import TelegramMethod
from aiogram_i18n import I18nContext

from app.repositories import UserRepository
from app.models import Users
from app.filters import AdminFilter, ChatTypeFilter

router = Router()
router.message.filter(ChatTypeFilter(chat_type=["private"]))


@router.message(CommandStart())
async def cmd_start(
    message: Message, user: Users, user_service: UserRepository, i18n: I18nContext,
) -> TelegramMethod[Any]:

    await message.answer(text=i18n.messages.start(name=user.mention))

在流畅的文件中,它是这样写的:messages-start = "Hello { $name }!" 这就是它的位置:

├── app
│   └── __main__.py
|   ...
│
└── locales
    │
    ├── ru
    │   └── messages.ftl
    │
    └── en
        └── messages.ftl

毕竟,我通过命令启动机器人python -m app并出现错误:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/home/.../job/telegram_bot/app/__main__.py", line 13, in <module>
    from aiogram_i18n.cores import FluentRuntimeCore
  File "<frozen importlib._bootstrap>", line 1229, in _handle_fromlist
  File "/home/.../.cache/pypoetry/virtualenvs/telegram-bot-a3iI3O79-py3.11/lib/python3.11/site-packages/aiogram_i18n/cores/__init__.py", line 29, in __getattr__
    return cast(BaseCore[Any], getattr(import_module(__cores__[name], "aiogram_i18n.cores"), name))
                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/.../.cache/pypoetry/virtualenvs/telegram-bot-a3iI3O79-py3.11/lib/python3.11/site-packages/aiogram_i18n/cores/fluent_runtime_core.py", line 5, in <module>
    from aiogram_i18n.utils.text_decorator import td
  File "/home/.../.cache/pypoetry/virtualenvs/telegram-bot-a3iI3O79-py3.11/lib/python3.11/site-packages/aiogram_i18n/utils/text_decorator.py", line 124, in <module>
    td = TextDecoration()
         ^^^^^^^^^^^^^^^^
  File "/home/.../.cache/pypoetry/virtualenvs/telegram-bot-a3iI3O79-py3.11/lib/python3.11/site-packages/aiogram_i18n/utils/text_decorator.py", line 55, in __init__
    None: Null(),
          ^^^^^^
TypeError: Can't instantiate abstract class Null with abstract method expandable_blockquote

我什至尝试只设置默认区域设置和其他东西(我用 get_locale、set_locale 方法编写了另一个中间件,在那里我只是使用数据库,我保存了用户的语言代码),但没有任何改变

有时我觉得版本有问题,我有所有最新版本的依赖项,aiogram,aiogram_i18n,flutter - 它们也都是最新版本:

 1. aiogram-i18n = {extras = ["compiler"], version = "^1.3.4"}
 2. aiogram = "^3.7.0"
 3. fluent-compiler   1.1
 4. fluent-syntax     0.19.0
 5. babel             2.15.0

python
  • 1 个回答
  • 40 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5