create-reaction-fkx
All checks were successful
Deploy on push / deploy (push) Successful in 6s

This commit is contained in:
2024-11-02 13:49:22 +03:00
parent 52567557e8
commit b322219173
2 changed files with 28 additions and 27 deletions

View File

@@ -1,6 +1,5 @@
from sqlalchemy import and_
from orm.rating import is_negative, is_positive
from orm.reaction import Reaction, ReactionKind
from orm.shout import Shout
@@ -11,7 +10,9 @@ from utils.diff import apply_diff, get_diff
def handle_proposing(kind: ReactionKind, reply_to: int, shout_id: int):
with local_session() as session:
if is_positive(kind):
replied_reaction = session.query(Reaction).filter(Reaction.id == reply_to, Reaction.shout == shout_id).first()
replied_reaction = (
session.query(Reaction).filter(Reaction.id == reply_to, Reaction.shout == shout_id).first()
)
if replied_reaction and replied_reaction.kind is ReactionKind.PROPOSE.value and replied_reaction.quote:
# patch all the proposals' quotes
@@ -29,11 +30,11 @@ def handle_proposing(kind: ReactionKind, reply_to: int, shout_id: int):
# patch shout's body
shout = session.query(Shout).filter(Shout.id == shout_id).first()
body = replied_reaction.quote
Shout.update(shout, { body })
Shout.update(shout, {body})
session.add(shout)
session.commit()
# реакция содержит цитату -> обновляются все предложения
# реакция содержит цитату -> обновляются все предложения
# (proposals) для соответствующего Shout.
for proposal in proposals:
if proposal.quote: