From e3bc1c0c385276d9679af79d8fed5f1e1c807181 Mon Sep 17 00:00:00 2001 From: knst-kotov Date: Fri, 17 Dec 2021 17:14:08 +0100 Subject: [PATCH] fix creating shout --- orm/shout.py | 2 +- resolvers/zine.py | 31 ++++++++++++++++++------------- schema.graphql | 4 ++-- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/orm/shout.py b/orm/shout.py index 638bab24..a13a49fd 100644 --- a/orm/shout.py +++ b/orm/shout.py @@ -318,7 +318,7 @@ class Shout(Base): id = None slug: str = Column(String, primary_key=True) - community: int = Column(Integer, ForeignKey("community.id"), nullable=True, comment="Community") + community: int = Column(Integer, ForeignKey("community.id"), nullable=False, comment="Community") body: str = Column(String, nullable=False, comment="Body") createdAt: str = Column(DateTime, nullable=False, default = datetime.now, comment="Created at") updatedAt: str = Column(DateTime, nullable=True, comment="Updated at") diff --git a/resolvers/zine.py b/resolvers/zine.py index 0baf4954..c7240508 100644 --- a/resolvers/zine.py +++ b/resolvers/zine.py @@ -35,7 +35,12 @@ class GitTask: Path(repo_path).mkdir() - cmd = "cd %s && git init && touch initial && git add initial && git commit -m 'init repo'" % (repo_path) + cmd = "cd %s && git init && " \ + "git config user.name 'discours' && " \ + "git config user.email 'discours@discours.io' && " \ + "touch initial && git add initial && " \ + "git commit -m 'init repo'" \ + % (repo_path) output = subprocess.check_output(cmd, shell=True) print(output) @@ -45,9 +50,9 @@ class GitTask: if not Path(repo_path).exists(): self.init_repo() - cmd = "cd %s && git checkout master" % (repo_path) - output = subprocess.check_output(cmd, shell=True) - print(output) + #cmd = "cd %s && git checkout master" % (repo_path) + #output = subprocess.check_output(cmd, shell=True) + #print(output) shout_filename = "%s.md" % (self.slug) shout_full_filename = "%s/%s" % (repo_path, shout_filename) @@ -208,20 +213,20 @@ async def recent_shouts(_, info, limit): @mutation.field("createShout") @login_required async def create_shout(_, info, input): - auth = info.context["request"].auth - user_id = auth.user_id - - with local_session() as session: - user = session.query(User).filter(User.id == user_id).first() - - topic_slugs = input.get("topic_slugs") - del input["topic_slugs"] + user = info.context["request"].user + + topic_slugs = input.get("topic_slugs", []) + if topic_slugs: + del input["topic_slugs"] new_shout = Shout.create(**input) ShoutAuthor.create( shout = new_shout.slug, - user = user_id) + user = user.id) + if "mainTopic" in input: + topic_slugs.append(input["mainTopic"]) + for slug in topic_slugs: topic = ShoutTopic.create( shout = new_shout.slug, diff --git a/schema.graphql b/schema.graphql index 677984d9..dbfa0fa0 100644 --- a/schema.graphql +++ b/schema.graphql @@ -25,8 +25,8 @@ type MessageResult { input ShoutInput { slug: String! body: String! - # replyTo: String # another shout - # tags: [String] # actual values + community: Int! + mainTopic: String topic_slugs: [String] title: String subtitle: String