Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit 4d4c382

Browse files
authored
Merge pull request #39 from Sakimori/main
Adding share methods to Post and Project objects
2 parents 995d30c + d457b11 commit 4d4c382

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

cohost/models/post.py

+16
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,22 @@ def edit(self, headline: str, blocks: list = [], cws: list = [],
2323
adult=adult,
2424
draft=draft
2525
)
26+
27+
def share(self, headline: str, blocks: list = [], cws: list = [],
28+
tags: list = [], adult: bool = False, draft=False):
29+
from cohost.models.project import EditableProject
30+
if not isinstance(self.project, EditableProject):
31+
raise AttributeError("Post isn't attached to an EditableProject -\
32+
do you have Post permissions for this project?")
33+
return self.project.post(
34+
headline=headline,
35+
blocks=blocks,
36+
cws=cws,
37+
tags=tags,
38+
adult=adult,
39+
draft=draft,
40+
shareOfPostId=self.postId
41+
)
2642

2743
@property
2844
def postId(self):

cohost/models/project.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def projectInfo(self) -> dict[str, Any]:
143143
raise AttributeError("Project not found")
144144

145145
def post(self, headline: str, blocks: list = [], cws: list = [],
146-
tags: list = [], adult: bool = False, draft=False):
146+
tags: list = [], adult: bool = False, draft=False, shareOfPostId: int = None):
147147
# Basic flow: you send a POST to project/{handle}/posts
148148
# This gives us back a post ID, as well as a API link
149149
# For example:
@@ -209,8 +209,12 @@ def post(self, headline: str, blocks: list = [], cws: list = [],
209209
'adultContent': adult,
210210
'blocks': blockL,
211211
'cws': cws,
212-
'tags': tags
212+
'tags': tags,
213213
}
214+
if shareOfPostId is not None:
215+
postData.update({
216+
'shareOfPostId': shareOfPostId
217+
})
214218
req = fetch(
215219
'postJSON',
216220
'/project/{}/posts'.format(self.handle),
@@ -237,6 +241,10 @@ def post(self, headline: str, blocks: list = [], cws: list = [],
237241
'cws': cws,
238242
'tags': tags
239243
}
244+
if shareOfPostId is not None:
245+
postData.update({
246+
'shareOfPostId': shareOfPostId
247+
})
240248
req = fetch(
241249
'put',
242250
'/project/{}/posts/{}'.format(self.handle, req['postId']),
@@ -272,6 +280,7 @@ def editPost(self, postId: int,
272280
'cws': cws,
273281
'tags': tags
274282
}
283+
275284
req = fetch(
276285
'put',
277286
'/project/{}/posts/{}'.format(self.handle, postId),

0 commit comments

Comments
 (0)