trcbk-devmode-only
This commit is contained in:
parent
e4bbe11bed
commit
70501d49b0
|
@ -5,6 +5,7 @@ from sqlalchemy.sql.expression import desc, asc, select, func
|
||||||
from auth.credentials import AuthCredentials
|
from auth.credentials import AuthCredentials
|
||||||
from base.orm import local_session
|
from base.orm import local_session
|
||||||
from base.resolvers import query
|
from base.resolvers import query
|
||||||
|
from base.exceptions import ObjectNotExist
|
||||||
from orm import ViewedEntry
|
from orm import ViewedEntry
|
||||||
from orm.shout import Shout, ShoutAuthor
|
from orm.shout import Shout, ShoutAuthor
|
||||||
from orm.reaction import Reaction
|
from orm.reaction import Reaction
|
||||||
|
@ -58,22 +59,23 @@ async def load_shout(_, info, slug):
|
||||||
).filter(
|
).filter(
|
||||||
Shout.deletedAt.is_(None)
|
Shout.deletedAt.is_(None)
|
||||||
).group_by(Shout.id)
|
).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 = {
|
for author_caption in session.query(ShoutAuthor).join(Shout).where(Shout.slug == slug):
|
||||||
"viewed": viewed_stat,
|
for author in shout.authors:
|
||||||
"reacted": reacted_stat,
|
if author.id == author_caption.user:
|
||||||
"commented": commented_stat,
|
author.caption = author_caption.caption
|
||||||
"rating": rating_stat
|
return shout
|
||||||
}
|
except Exception:
|
||||||
|
raise ObjectNotExist("Slug was not found: %s" % slug)
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
@query.field("loadShouts")
|
@query.field("loadShouts")
|
||||||
|
|
|
@ -4,6 +4,11 @@ import uvicorn
|
||||||
|
|
||||||
from settings import PORT, DEV_SERVER_STATUS_FILE_NAME
|
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 = {
|
log_settings = {
|
||||||
'version': 1,
|
'version': 1,
|
||||||
'disable_existing_loggers': True,
|
'disable_existing_loggers': True,
|
||||||
|
@ -66,7 +71,6 @@ if __name__ == "__main__":
|
||||||
if x == "dev":
|
if x == "dev":
|
||||||
if os.path.exists(DEV_SERVER_STATUS_FILE_NAME):
|
if os.path.exists(DEV_SERVER_STATUS_FILE_NAME):
|
||||||
os.remove(DEV_SERVER_STATUS_FILE_NAME)
|
os.remove(DEV_SERVER_STATUS_FILE_NAME)
|
||||||
|
|
||||||
want_reload = False
|
want_reload = False
|
||||||
if "reload" in sys.argv:
|
if "reload" in sys.argv:
|
||||||
print("MODE: DEV + RELOAD")
|
print("MODE: DEV + RELOAD")
|
||||||
|
@ -90,6 +94,7 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
migrate()
|
migrate()
|
||||||
else:
|
else:
|
||||||
|
sys.excepthook = exception_handler
|
||||||
uvicorn.run(
|
uvicorn.run(
|
||||||
"main:app",
|
"main:app",
|
||||||
host="0.0.0.0",
|
host="0.0.0.0",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user