c10e54dd34
Some checks failed
Python package / build (3.10) (push) Has been cancelled
Python package / build (3.11) (push) Has been cancelled
Python package / build (3.9) (push) Has been cancelled
155 lines
4.3 KiB
Python
155 lines
4.3 KiB
Python
class Post:
|
|
def __init__(self, postData, project):
|
|
# we do this here to help autosuggest figure out what project is
|
|
from cohost.models.project import Project # noqa: F401
|
|
self.postData = postData
|
|
self.project = project
|
|
|
|
def __str__(self):
|
|
return "{}".format(self.filename)
|
|
|
|
def edit(self, headline, blocks= [], cws= [],
|
|
tags= [], adult= False, draft=False):
|
|
from cohost.models.project import EditableProject
|
|
if not isinstance(self.project, EditableProject):
|
|
raise AttributeError("Post isn't attached to an EditableProject -\
|
|
do you have Edit permissions for this post?")
|
|
return self.project.editPost(
|
|
self.postId,
|
|
headline=headline,
|
|
blocks=blocks,
|
|
cws=cws,
|
|
tags=tags,
|
|
adult=adult,
|
|
draft=draft
|
|
)
|
|
|
|
def share(self, headline, blocks= [], cws= [],
|
|
tags= [], adult= False, draft=False):
|
|
from cohost.models.project import EditableProject
|
|
if not isinstance(self.project, EditableProject):
|
|
raise AttributeError("Post isn't attached to an EditableProject -\
|
|
do you have Post permissions for this project?")
|
|
return self.project.post(
|
|
headline=headline,
|
|
blocks=blocks,
|
|
cws=cws,
|
|
tags=tags,
|
|
adult=adult,
|
|
draft=draft,
|
|
shareOfPostId=self.postId
|
|
)
|
|
|
|
@property
|
|
def postId(self):
|
|
return self.postData['postId']
|
|
|
|
@property
|
|
def headline(self):
|
|
return self.postData['headline']
|
|
|
|
@property
|
|
def publishedAt(self):
|
|
return self.postData['publishedAt'] # TODO: Use a datetime for this
|
|
|
|
@property
|
|
def filename(self):
|
|
return self.postData['filename']
|
|
|
|
@property
|
|
def transparentShareOfPostId(self):
|
|
return self.postData['transparentShareOfPostId']
|
|
|
|
@property
|
|
def state(self):
|
|
return self.postData['state']
|
|
|
|
@property
|
|
def numComments(self):
|
|
return self.postData['numComments']
|
|
|
|
@property
|
|
def numSharedComments(self):
|
|
return self.postData['numSharedComments']
|
|
|
|
@property
|
|
def contentWarnings(self):
|
|
return self.postData['cws']
|
|
|
|
@property
|
|
def tags(self):
|
|
return self.postData['tags']
|
|
|
|
"""Build
|
|
|
|
Returns:
|
|
list[str]: Return a list of blocks that make up a post
|
|
"""
|
|
@property
|
|
def blocks(self):
|
|
return self.postData['blocks']
|
|
|
|
@property
|
|
def plainTextBody(self):
|
|
return self.postData['plainTextBody']
|
|
|
|
@property
|
|
def ogAuthor(self):
|
|
if self.postData['shareTree']:
|
|
# We use the first one, as i *think* that refers to the OG poster
|
|
newProject = self.postData['shareTree'][0]['postingProject']
|
|
else:
|
|
newProject = self.postData['postingProject']
|
|
return self.project.user.resolveSecondaryProject(newProject)
|
|
|
|
@property
|
|
def shareTree(self):
|
|
return self.postData['shareTree']
|
|
|
|
@property
|
|
def relatedProjects(self):
|
|
projects = []
|
|
for p in self.postData['relatedProjects']:
|
|
projects.append(self.project.user.resolveSecondaryProject(p))
|
|
return projects
|
|
|
|
@property
|
|
def url(self):
|
|
return self.postData['singlePostPageUrl']
|
|
|
|
@property
|
|
def adult(self):
|
|
return self.postData['effectiveAdultContent']
|
|
|
|
@property
|
|
def contributorBlock(self):
|
|
# NOTE: This is still untested as I'm still not sure how blocks work
|
|
return self.postData['contributorBlockIncomingOrOutgoing']
|
|
|
|
@property
|
|
def hasAnyContributorMuted(self):
|
|
return self.postData['hasAnyContributorMuted']
|
|
|
|
@property
|
|
def renderInIframe(self):
|
|
return self.postData['renderInIframe']
|
|
|
|
@property
|
|
def postPreviewIframeUrl(self):
|
|
return self.postData['postPreviewIFrameUrl']
|
|
|
|
@property
|
|
def postEditurl(self):
|
|
return self.postData['postEditUrl']
|
|
|
|
@property
|
|
def liked(self):
|
|
return self.postData['isLiked']
|
|
|
|
@property
|
|
def shareable(self):
|
|
return self.postData['canShare']
|
|
|
|
@property
|
|
def publishable(self):
|
|
return self.postData['canPublish']
|