This commit is contained in:
parent
5a4f75537d
commit
52b608da99
|
@ -1,6 +1,5 @@
|
|||
import time
|
||||
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.sql import and_
|
||||
|
||||
from cache.cache import (
|
||||
|
|
|
@ -12,16 +12,14 @@ from cache.cache import (
|
|||
invalidate_shouts_cache,
|
||||
)
|
||||
from orm.author import Author
|
||||
from orm.draft import Draft
|
||||
from orm.shout import Shout, ShoutAuthor, ShoutTopic
|
||||
from orm.topic import Topic
|
||||
from resolvers.draft import create_draft, publish_draft
|
||||
from resolvers.follower import follow, unfollow
|
||||
from resolvers.stat import get_with_stat
|
||||
from services.auth import login_required
|
||||
from services.db import local_session
|
||||
from services.notify import notify_shout
|
||||
from services.schema import mutation, query
|
||||
from services.schema import query
|
||||
from services.search import search_service
|
||||
from utils.logger import root_logger as logger
|
||||
|
||||
|
@ -582,6 +580,9 @@ async def update_shout(_, info, shout_id: int, shout_input=None, publish=False):
|
|||
else []
|
||||
)
|
||||
|
||||
# Add main_topic to the shout dictionary
|
||||
shout_dict["main_topic"] = get_main_topic_slug(shout_with_relations.topics)
|
||||
|
||||
shout_dict["authors"] = (
|
||||
[
|
||||
{"id": author.id, "name": author.name, "slug": author.slug}
|
||||
|
@ -641,3 +642,19 @@ async def delete_shout(_, info, shout_id: int):
|
|||
return {"error": None}
|
||||
else:
|
||||
return {"error": "access denied"}
|
||||
|
||||
|
||||
def get_main_topic_slug(topics):
|
||||
"""Get the slug of the main topic from a list of topics.
|
||||
|
||||
Args:
|
||||
topics: List of ShoutTopic objects
|
||||
|
||||
Returns:
|
||||
str: Slug of the main topic, or None if no main topic found
|
||||
"""
|
||||
if not topics:
|
||||
return None
|
||||
|
||||
main_topic = next((t for t in topics.reverse() if t.main), None)
|
||||
return main_topic.topic.slug if main_topic else { "slug": "notopic", "title": "no topic", "id": 0 }
|
||||
|
|
|
@ -9,7 +9,6 @@ from starlette.testclient import TestClient
|
|||
from main import app
|
||||
from services.db import Base
|
||||
from services.redis import redis
|
||||
from settings import DB_URL
|
||||
|
||||
# Use SQLite for testing
|
||||
TEST_DB_URL = "sqlite:///test.db"
|
||||
|
|
|
@ -3,7 +3,7 @@ from datetime import datetime
|
|||
import pytest
|
||||
|
||||
from orm.author import Author
|
||||
from orm.reaction import Reaction, ReactionKind
|
||||
from orm.reaction import ReactionKind
|
||||
from orm.shout import Shout
|
||||
|
||||
|
||||
|
|
|
@ -6,9 +6,7 @@ from pydantic import ValidationError
|
|||
from auth.validations import (
|
||||
AuthInput,
|
||||
AuthResponse,
|
||||
OAuthInput,
|
||||
TokenPayload,
|
||||
UserLoginInput,
|
||||
UserRegistrationInput,
|
||||
)
|
||||
|
||||
|
|
|
@ -105,7 +105,7 @@ root_logger.setLevel(logging.DEBUG)
|
|||
root_logger.addHandler(stream)
|
||||
root_logger.addFilter(filter)
|
||||
|
||||
ignore_logs = ["_trace", "httpx", "_client", "_trace.atrace", "aiohttp", "_client"]
|
||||
ignore_logs = ["_trace", "httpx", "_client", "atrace", "aiohttp", "_client"]
|
||||
for lgr in ignore_logs:
|
||||
loggr = logging.getLogger(lgr)
|
||||
loggr.setLevel(logging.INFO)
|
||||
|
|
Loading…
Reference in New Issue
Block a user