我试图在falcon中处理sqlalchemy事件,任务是在模型字段更改时发送消息:
# -*- coding: utf-8 -*-
from sqlalchemy import Column
from sqlalchemy import Boolean, Date, ForeignKey, Numeric
from sqlalchemy import event
from sqlalchemy_utils import UUIDType
from app.model import MyBaseModel
from app.emails import MyEventListener
class EventSend(MyBaseModel):
__tablename__ = 'event_send'
event_to = Column(Numeric(5, 1), nullable=True)
current = Column(Boolean, nullable=False)
start = Column(Date)
end = Column(Date)
status_id = Column(UUIDType, ForeignKey('status.id'))
event.listen(EventSend.status_id, 'set', MyEventListener.handler, named=True)
在MyEventListener中,我想知道进行更改并触发事件的用户。但是,如何在未通过会话的情况下获得经过身份验证的用户?
event
仅向MyEventListener发送以下参数:
kwargs["value"]: new value for triggered field
kwargs["oldvalue"]: current value of the field
kwargs["target"]: object that triggers event e.g. app.model.EventSend object
kwargs["initiator"] sqlalchemy.orm.attributes.Event object
MyEventListener:
class MyEventListener(object):
@classmethod
def handler(cls, *args, **kwargs):
if args:
print(args)
elif kwargs:
print(kwargs)
else:
print("Wrong or unknown event")
请问您,在这种情况下我如何才能得到用户?或者在处理程序中触发事件时,应该采取什么措施来让用户做出更改?