trcbk-devmode-only

This commit is contained in:
tonyrewin 2022-12-03 10:37:45 +03:00
parent e4bbe11bed
commit 70501d49b0
2 changed files with 22 additions and 15 deletions

View File

@ -5,6 +5,7 @@ from sqlalchemy.sql.expression import desc, asc, select, func
from auth.credentials import AuthCredentials
from base.orm import local_session
from base.resolvers import query
from base.exceptions import ObjectNotExist
from orm import ViewedEntry
from orm.shout import Shout, ShoutAuthor
from orm.reaction import Reaction
@ -58,22 +59,23 @@ async def load_shout(_, info, slug):
).filter(
Shout.deletedAt.is_(None)
).group_by(Shout.id)
try:
[shout, viewed_stat, reacted_stat, commented_stat, rating_stat] = session.execute(q).first()
[shout, viewed_stat, reacted_stat, commented_stat, rating_stat] = session.execute(q).unique().one()
shout.stat = {
"viewed": viewed_stat,
"reacted": reacted_stat,
"commented": commented_stat,
"rating": rating_stat
}
shout.stat = {
"viewed": viewed_stat,
"reacted": reacted_stat,
"commented": commented_stat,
"rating": rating_stat
}
for author_caption in session.query(ShoutAuthor).join(Shout).where(Shout.slug == slug):
for author in shout.authors:
if author.id == author_caption.user:
author.caption = author_caption.caption
return shout
for author_caption in session.query(ShoutAuthor).join(Shout).where(Shout.slug == slug):
for author in shout.authors:
if author.id == author_caption.user:
author.caption = author_caption.caption
return shout
except Exception:
raise ObjectNotExist("Slug was not found: %s" % slug)
@query.field("loadShouts")

View File

@ -4,6 +4,11 @@ import uvicorn
from settings import PORT, DEV_SERVER_STATUS_FILE_NAME
def exception_handler(exception_type, exception, traceback, debug_hook=sys.excepthook):
print("%s: %s" % (exception_type.__name__, exception))
log_settings = {
'version': 1,
'disable_existing_loggers': True,
@ -66,7 +71,6 @@ if __name__ == "__main__":
if x == "dev":
if os.path.exists(DEV_SERVER_STATUS_FILE_NAME):
os.remove(DEV_SERVER_STATUS_FILE_NAME)
want_reload = False
if "reload" in sys.argv:
print("MODE: DEV + RELOAD")
@ -90,6 +94,7 @@ if __name__ == "__main__":
migrate()
else:
sys.excepthook = exception_handler
uvicorn.run(
"main:app",
host="0.0.0.0",