mirror of
https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git
synced 2025-08-14 00:25:46 +02:00
Проверка 09.02.2025
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
# event/api.py
|
||||
# Copyright (C) 2005-2024 the SQLAlchemy authors and contributors
|
||||
# Copyright (C) 2005-2025 the SQLAlchemy authors and contributors
|
||||
# <see AUTHORS file>
|
||||
#
|
||||
# This module is part of SQLAlchemy and is released under
|
||||
@@ -51,15 +51,14 @@ def listen(
|
||||
from sqlalchemy import event
|
||||
from sqlalchemy.schema import UniqueConstraint
|
||||
|
||||
|
||||
def unique_constraint_name(const, table):
|
||||
const.name = "uq_%s_%s" % (
|
||||
table.name,
|
||||
list(const.columns)[0].name
|
||||
)
|
||||
const.name = "uq_%s_%s" % (table.name, list(const.columns)[0].name)
|
||||
|
||||
|
||||
event.listen(
|
||||
UniqueConstraint,
|
||||
"after_parent_attach",
|
||||
unique_constraint_name)
|
||||
UniqueConstraint, "after_parent_attach", unique_constraint_name
|
||||
)
|
||||
|
||||
:param bool insert: The default behavior for event handlers is to append
|
||||
the decorated user defined function to an internal list of registered
|
||||
@@ -132,19 +131,17 @@ def listens_for(
|
||||
The :func:`.listens_for` decorator is part of the primary interface for the
|
||||
SQLAlchemy event system, documented at :ref:`event_toplevel`.
|
||||
|
||||
This function generally shares the same kwargs as :func:`.listens`.
|
||||
This function generally shares the same kwargs as :func:`.listen`.
|
||||
|
||||
e.g.::
|
||||
|
||||
from sqlalchemy import event
|
||||
from sqlalchemy.schema import UniqueConstraint
|
||||
|
||||
|
||||
@event.listens_for(UniqueConstraint, "after_parent_attach")
|
||||
def unique_constraint_name(const, table):
|
||||
const.name = "uq_%s_%s" % (
|
||||
table.name,
|
||||
list(const.columns)[0].name
|
||||
)
|
||||
const.name = "uq_%s_%s" % (table.name, list(const.columns)[0].name)
|
||||
|
||||
A given function can also be invoked for only the first invocation
|
||||
of the event using the ``once`` argument::
|
||||
@@ -153,7 +150,6 @@ def listens_for(
|
||||
def on_config():
|
||||
do_config()
|
||||
|
||||
|
||||
.. warning:: The ``once`` argument does not imply automatic de-registration
|
||||
of the listener function after it has been invoked a first time; a
|
||||
listener entry will remain associated with the target object.
|
||||
@@ -189,6 +185,7 @@ def remove(target: Any, identifier: str, fn: Callable[..., Any]) -> None:
|
||||
def my_listener_function(*arg):
|
||||
pass
|
||||
|
||||
|
||||
# ... it's removed like this
|
||||
event.remove(SomeMappedClass, "before_insert", my_listener_function)
|
||||
|
||||
|
Reference in New Issue
Block a user