fix creating shout

This commit is contained in:
knst-kotov 2021-12-17 17:14:08 +01:00
parent 931fd887d9
commit e3bc1c0c38
3 changed files with 21 additions and 16 deletions

View File

@ -318,7 +318,7 @@ class Shout(Base):
id = None id = None
slug: str = Column(String, primary_key=True) 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") body: str = Column(String, nullable=False, comment="Body")
createdAt: str = Column(DateTime, nullable=False, default = datetime.now, comment="Created at") createdAt: str = Column(DateTime, nullable=False, default = datetime.now, comment="Created at")
updatedAt: str = Column(DateTime, nullable=True, comment="Updated at") updatedAt: str = Column(DateTime, nullable=True, comment="Updated at")

View File

@ -35,7 +35,12 @@ class GitTask:
Path(repo_path).mkdir() 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) output = subprocess.check_output(cmd, shell=True)
print(output) print(output)
@ -45,9 +50,9 @@ class GitTask:
if not Path(repo_path).exists(): if not Path(repo_path).exists():
self.init_repo() self.init_repo()
cmd = "cd %s && git checkout master" % (repo_path) #cmd = "cd %s && git checkout master" % (repo_path)
output = subprocess.check_output(cmd, shell=True) #output = subprocess.check_output(cmd, shell=True)
print(output) #print(output)
shout_filename = "%s.md" % (self.slug) shout_filename = "%s.md" % (self.slug)
shout_full_filename = "%s/%s" % (repo_path, shout_filename) shout_full_filename = "%s/%s" % (repo_path, shout_filename)
@ -208,19 +213,19 @@ async def recent_shouts(_, info, limit):
@mutation.field("createShout") @mutation.field("createShout")
@login_required @login_required
async def create_shout(_, info, input): async def create_shout(_, info, input):
auth = info.context["request"].auth user = info.context["request"].user
user_id = auth.user_id
with local_session() as session: topic_slugs = input.get("topic_slugs", [])
user = session.query(User).filter(User.id == user_id).first() if topic_slugs:
del input["topic_slugs"]
topic_slugs = input.get("topic_slugs")
del input["topic_slugs"]
new_shout = Shout.create(**input) new_shout = Shout.create(**input)
ShoutAuthor.create( ShoutAuthor.create(
shout = new_shout.slug, shout = new_shout.slug,
user = user_id) user = user.id)
if "mainTopic" in input:
topic_slugs.append(input["mainTopic"])
for slug in topic_slugs: for slug in topic_slugs:
topic = ShoutTopic.create( topic = ShoutTopic.create(

View File

@ -25,8 +25,8 @@ type MessageResult {
input ShoutInput { input ShoutInput {
slug: String! slug: String!
body: String! body: String!
# replyTo: String # another shout community: Int!
# tags: [String] # actual values mainTopic: String
topic_slugs: [String] topic_slugs: [String]
title: String title: String
subtitle: String subtitle: String