Improve topic sorting: add popular sorting by publications and authors count
This commit is contained in:
@@ -7,7 +7,7 @@ from services.db import local_session
|
||||
from utils.diff import apply_diff, get_diff
|
||||
|
||||
|
||||
def handle_proposing(kind: ReactionKind, reply_to: int, shout_id: int):
|
||||
def handle_proposing(kind: ReactionKind, reply_to: int, shout_id: int) -> None:
|
||||
with local_session() as session:
|
||||
if is_positive(kind):
|
||||
replied_reaction = (
|
||||
@@ -29,20 +29,31 @@ 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})
|
||||
session.add(shout)
|
||||
session.commit()
|
||||
if shout:
|
||||
body = replied_reaction.quote
|
||||
# Use setattr instead of Shout.update for Column assignment
|
||||
shout.body = body
|
||||
session.add(shout)
|
||||
session.commit()
|
||||
|
||||
# реакция содержит цитату -> обновляются все предложения
|
||||
# (proposals) для соответствующего Shout.
|
||||
for proposal in proposals:
|
||||
if proposal.quote:
|
||||
proposal_diff = get_diff(shout.body, proposal.quote)
|
||||
proposal_dict = proposal.dict()
|
||||
proposal_dict["quote"] = apply_diff(replied_reaction.quote, proposal_diff)
|
||||
Reaction.update(proposal, proposal_dict)
|
||||
session.add(proposal)
|
||||
# реакция содержит цитату -> обновляются все предложения
|
||||
# (proposals) для соответствующего Shout.
|
||||
for proposal in proposals:
|
||||
if proposal.quote:
|
||||
# Convert Column to string for get_diff
|
||||
shout_body = str(shout.body) if shout.body else ""
|
||||
proposal_dict = proposal.dict() if hasattr(proposal, "dict") else {"quote": proposal.quote}
|
||||
proposal_diff = get_diff(shout_body, proposal_dict["quote"])
|
||||
replied_reaction_dict = (
|
||||
replied_reaction.dict()
|
||||
if hasattr(replied_reaction, "dict")
|
||||
else {"quote": replied_reaction.quote}
|
||||
)
|
||||
proposal_dict["quote"] = apply_diff(replied_reaction_dict["quote"], proposal_diff)
|
||||
|
||||
# Update proposal quote
|
||||
proposal.quote = proposal_dict["quote"] # type: ignore[assignment]
|
||||
session.add(proposal)
|
||||
|
||||
if is_negative(kind):
|
||||
# TODO: rejection logic
|
||||
|
Reference in New Issue
Block a user