fix-slug-raise-error
This commit is contained in:
parent
57aa4caa84
commit
ad97aa2227
2
main.py
2
main.py
|
@ -83,6 +83,8 @@ app.mount(
|
||||||
GraphQL(schema, debug=True),
|
GraphQL(schema, debug=True),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
print("[main] app mounted")
|
||||||
|
|
||||||
dev_app = app = Starlette(
|
dev_app = app = Starlette(
|
||||||
debug=True,
|
debug=True,
|
||||||
on_startup=[dev_start_up],
|
on_startup=[dev_start_up],
|
||||||
|
|
|
@ -1,13 +1,23 @@
|
||||||
from datetime import datetime, timedelta, timezone
|
from datetime import datetime, timedelta, timezone
|
||||||
|
from sqlalchemy.engine import ObjectKind
|
||||||
|
|
||||||
from sqlalchemy.orm import joinedload, aliased
|
from sqlalchemy.orm import joinedload, aliased
|
||||||
from sqlalchemy.sql.expression import desc, asc, select, func, case, and_, nulls_last
|
from sqlalchemy.sql.expression import (
|
||||||
|
desc,
|
||||||
|
asc,
|
||||||
|
select,
|
||||||
|
func,
|
||||||
|
case,
|
||||||
|
and_,
|
||||||
|
# text,
|
||||||
|
nulls_last,
|
||||||
|
)
|
||||||
|
|
||||||
from auth.authenticate import login_required
|
from auth.authenticate import login_required
|
||||||
from auth.credentials import AuthCredentials
|
from auth.credentials import AuthCredentials
|
||||||
from services.exceptions import ObjectNotExist
|
from base.exceptions import ObjectNotExist # , OperationNotAllowed
|
||||||
from services.db import local_session
|
from base.orm import local_session
|
||||||
from services.schema import query
|
from base.resolvers import query
|
||||||
from orm import TopicFollower
|
from orm import TopicFollower
|
||||||
from orm.reaction import Reaction, ReactionKind
|
from orm.reaction import Reaction, ReactionKind
|
||||||
from orm.shout import Shout, ShoutAuthor, ShoutTopic
|
from orm.shout import Shout, ShoutAuthor, ShoutTopic
|
||||||
|
@ -96,14 +106,15 @@ async def load_shout(_, info, slug=None, shout_id=None):
|
||||||
|
|
||||||
q = q.filter(Shout.deletedAt.is_(None)).group_by(Shout.id)
|
q = q.filter(Shout.deletedAt.is_(None)).group_by(Shout.id)
|
||||||
|
|
||||||
try:
|
resp = session.execute(q).first()
|
||||||
|
if resp:
|
||||||
[
|
[
|
||||||
shout,
|
shout,
|
||||||
reacted_stat,
|
reacted_stat,
|
||||||
commented_stat,
|
commented_stat,
|
||||||
rating_stat,
|
rating_stat,
|
||||||
last_comment,
|
last_comment,
|
||||||
] = session.execute(q).first()
|
] = resp
|
||||||
|
|
||||||
shout.stat = {
|
shout.stat = {
|
||||||
"viewed": shout.views,
|
"viewed": shout.views,
|
||||||
|
@ -119,8 +130,9 @@ async def load_shout(_, info, slug=None, shout_id=None):
|
||||||
if author.id == author_caption.user:
|
if author.id == author_caption.user:
|
||||||
author.caption = author_caption.caption
|
author.caption = author_caption.caption
|
||||||
return shout
|
return shout
|
||||||
except Exception:
|
else:
|
||||||
raise ObjectNotExist("Slug was not found: %s" % slug)
|
print("Slug was not found: %s" % slug)
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
@query.field("loadShouts")
|
@query.field("loadShouts")
|
||||||
|
|
|
@ -75,8 +75,7 @@ class ViewedStorage:
|
||||||
{"Authorization": "Bearer %s" % str(token)}, schema=schema_str
|
{"Authorization": "Bearer %s" % str(token)}, schema=schema_str
|
||||||
)
|
)
|
||||||
print(
|
print(
|
||||||
"[stat] * authorized permanentely by ackee.discours.io: %s"
|
"[stat] * authorized permanentely by ackee.discours.io: %s" % token
|
||||||
% token
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
print("[stat] * please set ACKEE_TOKEN")
|
print("[stat] * please set ACKEE_TOKEN")
|
||||||
|
@ -171,16 +170,18 @@ class ViewedStorage:
|
||||||
if viewer == "old-discours":
|
if viewer == "old-discours":
|
||||||
# this is needed for old db migration
|
# this is needed for old db migration
|
||||||
if shout.viewsOld == amount:
|
if shout.viewsOld == amount:
|
||||||
print(f"[stat] viewsOld amount: {amount}")
|
print(f"[stat] ⎪ viewsOld amount: {amount}")
|
||||||
else:
|
else:
|
||||||
print(f"[stat] viewsOld amount changed: {shout.viewsOld} --> {amount}")
|
print(
|
||||||
|
f"[stat] ⎪ viewsOld amount changed: {shout.viewsOld} --> {amount}"
|
||||||
|
)
|
||||||
shout.viewsOld = amount
|
shout.viewsOld = amount
|
||||||
else:
|
else:
|
||||||
if shout.viewsAckee == amount:
|
if shout.viewsAckee == amount:
|
||||||
print(f"[stat] viewsAckee amount: {amount}")
|
print(f"[stat] ⎪ viewsAckee amount: {amount}")
|
||||||
else:
|
else:
|
||||||
print(
|
print(
|
||||||
f"[stat] viewsAckee amount changed: {shout.viewsAckee} --> {amount}"
|
f"[stat] ⎪ viewsAckee amount changed: {shout.viewsAckee} --> {amount}"
|
||||||
)
|
)
|
||||||
shout.viewsAckee = amount
|
shout.viewsAckee = amount
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user